From 5cd2ae147e30b97da2278dbeda6be7831054cbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Burgue=C3=B1o?= Date: Sat, 28 Jan 2017 12:33:16 +1300 Subject: [PATCH] Support for GPT on disks > 2TB - Use parted by default if available, fallback to sfdisk - Use GPT only when disk is larger than 2TB - Limit partition size to 2TB if parted is not available and sfdisk does not support GPT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eric BurgueƱo --- docker-storage-setup.sh | 44 +++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/docker-storage-setup.sh b/docker-storage-setup.sh index 3bbaccc..7997003 100755 --- a/docker-storage-setup.sh +++ b/docker-storage-setup.sh @@ -707,32 +707,60 @@ scan_disks() { } create_partition_sfdisk(){ - local dev="$1" size + local dev="$1" size label="$2" type # Use a single partition of a whole device # TODO: - # * Consider gpt, or unpartitioned volumes + # * Consider unpartitioned volumes # * Error handling when partition(s) already exist # * Deal with loop/nbd device names. See growpart code + size=$(( $( awk "\$4 ~ /"$( basename $dev )"/ { print \$3 }" /proc/partitions ) * 2 - 2048 )) + # if parted is not present, and this version of sfdisk + # does not support GPT then we are limited to 2TB + if [ $label = "gpt" ]; then + if $(sfdisk --help|grep gpt >/dev/null) ; then + label="label: gpt" + type="" + size=$(( $size - 34 )) #34 is the first usable sector for GPT labels + else + Info "Your version of sfdisk does not support GPT labels. Will use MBR instead but partition size will be limited to 2TB" + label="" + type=", Id=8e" + # 2TB in sectors - 2048 + if [ $size -gt 4294965248 ]; then size=4294965248; fi + fi + elif [ $label = "msdos" ]; then + label="" + fi + cat <