@@ -712,32 +712,60 @@ scan_disks() {
712
712
}
713
713
714
714
create_partition_sfdisk (){
715
- local dev=" $1 " size
715
+ local dev=" $1 " size label= " $2 " type
716
716
# Use a single partition of a whole device
717
717
# TODO:
718
- # * Consider gpt, or unpartitioned volumes
718
+ # * Consider unpartitioned volumes
719
719
# * Error handling when partition(s) already exist
720
720
# * Deal with loop/nbd device names. See growpart code
721
+
721
722
size=$(( $( awk "\$4 ~ / "$( basename $dev )"/ { print \$3 }" / proc/ partitions ) * 2 - 2048 ))
722
- cat << EOF | sfdisk $dev
723
+ # if parted is not present, and this version of sfdisk
724
+ # does not support GPT then we are limited to 2TB
725
+ if [ $label = " gpt" ]; then
726
+ if $( sfdisk --help| grep gpt > /dev/null) ; then
727
+ label=" label: gpt"
728
+ type=" "
729
+ size=$(( $size - 34 )) # 34 is the first usable sector for GPT labels
730
+ else
731
+ Info " Your version of sfdisk does not support GPT labels. Will use MBR instead but partition size will be limited to 2TB"
732
+ label=" "
733
+ type=" , Id=8e"
734
+ # 2TB in sectors - 2048
735
+ if [ $size -gt 4294965248 ]; then size=4294965248; fi
736
+ fi
737
+ elif [ $label = " msdos" ]; then
738
+ label=" "
739
+ fi
740
+
741
+ cat << EOF | sfdisk $dev
723
742
unit: sectors
743
+ $label
724
744
725
- ${dev} 1 : start= 2048, size= ${size} , Id=8e
745
+ ${dev} 1 : start= 2048, size= ${size}${type}
726
746
EOF
727
747
}
728
748
729
749
create_partition_parted (){
730
- local dev=" $1 "
731
- parted $dev --script mklabel msdos mkpart primary 0% 100% set 1 lvm on
750
+ local dev=" $1 " label= " $2 "
751
+ parted $dev --script mklabel $label mkpart primary 0% 100% set 1 lvm on
732
752
}
733
753
734
754
create_partition () {
735
- local dev=" $1 "
755
+ local dev=" $1 " size label
756
+
757
+ # Determine partition size. If larger than 2TB use GPT instead
758
+ size=$( awk " \$ 4 ~ /" $( basename $dev ) " / { print \$ 3 }" /proc/partitions )
759
+ if [ $size -gt 2147483648 ]; then
760
+ label=" gpt"
761
+ else
762
+ label=" msdos"
763
+ fi
736
764
737
765
if [ -x " /usr/sbin/parted" ]; then
738
- create_partition_parted $dev
766
+ create_partition_parted $dev $label
739
767
else
740
- create_partition_sfdisk $dev
768
+ create_partition_sfdisk $dev $label
741
769
fi
742
770
743
771
# Sometimes on slow storage it takes a while for partition device to
0 commit comments