From 11b7290a75eefa9da5c08a25e3c17723be6a4e90 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 3 Jan 2012 11:01:46 -0800 Subject: install: use sfdisk to get disk size sfdisk is simpler, and safer for getting disk size. It doesn't require as much screen scraping and doesn't need disk label. --- scripts/install/install-functions | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/scripts/install/install-functions b/scripts/install/install-functions index 0cca8944..042ef5bb 100755 --- a/scripts/install/install-functions +++ b/scripts/install/install-functions @@ -139,40 +139,14 @@ turnoffswap () { # Return the size of the drive in MB get_drive_size () { - ldrive=$1 + local ldrive=$1 - # Make sure you can print disk info using parted - parted --script /dev/$ldrive p >/dev/null 2>&1 + # Get size of disk in 1k blocks + local blocks=$(sfdisk -s /dev/$ldrive) - # If unable to read disk, it's likely it needs a disklabel - if [ "$?" != "0" ]; then - lecho "Creating a new disklabel on $ldrive" - lecho "parted /dev/$ldrive mklabel msdos" - output=$(parted -s /dev/$ldrive mklabel msdos) - - # Get the drive size from parted - lsize=$(parted -s /dev/$ldrive p | grep "^Disk" | awk '{ print $3 }') - - if [ $(echo $lsize | grep error) ]; then - echo "Unable to read disk label. Exiting." - exit 1 - fi - fi - - # Get the drive size from parted - lsize=$(parted -s /dev/$ldrive p | grep "^Disk" | awk '{ print $3 }') - # Get the reported units (mB, GB, kB) - lmodifier=$(echo $lsize | sed 's/[0-9\.]//g') - # remove the modifier - lsize=$(echo $lsize | sed 's/[a-z,A-Z]//g') - # Remove any fractions - lsize=$(echo $lsize | cut -f1 -d'.') - # Translate our size into mB if not there already - if [ $lmodifier = "GB" ]; then - lsize=$(($lsize * 1000)) - elif [ $lmodifier = "kB" ]; then - lsize=$(($lsize / 1000)) - fi + # Translate to Megabytes (SI units) + local bytes=$(($blocks * 1024)) + local lsize=$(($bytes / 1000000)) echo $lsize } -- cgit v1.2.3