From c7d2f0e7c6d2a5c5c662c648bfa048b44174add0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Burgue=C3=B1o?= Date: Sat, 25 Feb 2017 10:58:11 +1300 Subject: [PATCH] Use GPT label when parted is available or sfdisk supports it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Signed-off-by: Eric BurgueƱo --- container-storage-setup.sh | 46 ++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/container-storage-setup.sh b/container-storage-setup.sh index 1b2b91a..74ef232 100755 --- a/container-storage-setup.sh +++ b/container-storage-setup.sh @@ -712,32 +712,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 )) - cat </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 <