Skip to content

Commit 1130219

Browse files
committed
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 Signed-off-by: Eric Burgueño <[email protected]>
1 parent 5e1f47b commit 1130219

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

docker-storage-setup.sh

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,32 +707,56 @@ scan_disks() {
707707
}
708708

709709
create_partition_sfdisk(){
710-
local dev="$1" size
710+
local dev="$1" size label="$2" type
711711
# Use a single partition of a whole device
712712
# TODO:
713-
# * Consider gpt, or unpartitioned volumes
713+
# * Consider unpartitioned volumes
714714
# * Error handling when partition(s) already exist
715715
# * Deal with loop/nbd device names. See growpart code
716+
716717
size=$(( $( awk "\$4 ~ /"$( basename $dev )"/ { print \$3 }" /proc/partitions ) * 2 - 2048 ))
718+
# if parted is not present, and this version of sfdisk
719+
# does not support GPT then we are limited to 2TB
720+
if [ $label = "gpt" ]; then
721+
if $(sfdisk --help|grep gpt >/dev/null) ; then
722+
label='label: gpt'
723+
type=''
724+
size=$(( $size - 34 ))
725+
else
726+
Info "Your version of sfdisk does not support GPT labels. Will use MBR instead but partition size will be limited to 2TB"
727+
label=''
728+
type=', Id=8e'
729+
# 2TB in sectors - 2048
730+
if [ $size -gt 4294965248 ]; then size=4294965248; fi
731+
fi
732+
elif [ $label = "msdos" ]; then
733+
label=''
734+
fi
735+
717736
cat <<EOF | sfdisk $dev
718737
unit: sectors
738+
$label
719739
720-
${dev}1 : start= 2048, size= ${size}, Id=8e
740+
${dev}1 : start= 2048, size= ${size}${type}
721741
EOF
722742
}
723743

724744
create_partition_parted(){
725-
local dev="$1"
726-
parted $dev --script mklabel msdos mkpart primary 0% 100% set 1 lvm on
745+
local dev="$1" label="$2"
746+
parted $dev --script mklabel $label mkpart primary 0% 100% set 1 lvm on
727747
}
728748

729749
create_partition() {
730-
local dev="$1"
750+
local dev="$1" size label
731751

752+
#Determine partition size. If larger than 2TB use GPT instead
753+
size=$( awk "\$4 ~ /"$( basename $dev )"/ { print \$3 }" /proc/partitions )
754+
if [ $size -gt 2147483648 ]; then label='gpt'; else label='msdos'; fi
755+
732756
if [ -x "/usr/sbin/parted" ]; then
733-
create_partition_parted $dev
757+
create_partition_parted $dev $label
734758
else
735-
create_partition_sfdisk $dev
759+
create_partition_sfdisk $dev $label
736760
fi
737761

738762
# Sometimes on slow storage it takes a while for partition device to

0 commit comments

Comments
 (0)