]> Zhao Yanbai Git Server - minix.git/commitdiff
setup(8): only call df(1) on mounted file systems
authorDavid van Moolenbroek <david@minix3.org>
Tue, 16 Oct 2012 17:04:40 +0000 (19:04 +0200)
committerDavid van Moolenbroek <david@minix3.org>
Wed, 17 Oct 2012 20:54:27 +0000 (22:54 +0200)
commands/setup/setup.sh

index da8b2c54dfd08da73aa0c83e2291639fdd560136..ed276bd62ff7d0c425aa4c4218f63a33a9b0c8f6 100644 (file)
@@ -428,6 +428,14 @@ then
 
        chroot /mnt update_bootcfg
 
+       sync
+
+       # Get sizes and space availability while the file systems are still
+       # mounted. Otherwise we have to mount them again just for this.
+       required_root_space=`df -k /dev/$root | awk '{print $4}' | tail -n 1`
+       free_root_space=`df -k /dev/$root | awk '{print $3}' | tail -n 1`
+       free_usr_space=`df -k /dev/$usr | awk '{print $3}' | tail -n 1`
+
        umount /mnt/usr && umount /mnt || exit
 
        # Check if enough space for new boot
@@ -438,9 +446,8 @@ then
                echo "Root partition size will be reduced by up to 16Kb to fit new bootloader."
                echo "This is not a problem."
 
-               free_space=`df /dev/$root | awk '{print $3}' | tail -n 1`
                # round 16 => 20
-               if [ "$free_space" -le 20 ]
+               if [ "$free_root_space" -le 20 ]
                then
                        echo ""
                        echo "Not enough space on /dev/$root, you need at least 20Kb to use new bootloader!"
@@ -449,14 +456,11 @@ then
 
                ROOTSECTS=`expr \`devsize /dev/$root\` - $BOOTXXSECTS + $bootspace`
 
-               free_space=`df /dev/$usr | awk '{print $3}' | tail -n 1`
-               required_space=`df /dev/$root | awk '{print $4}' | tail -n 1`
-
-               if [ "$required_space" -gt "$free_space" ]
+               if [ "$required_root_space" -gt "$free_usr_space" ]
                then
                        echo ""
                        echo "You don't have enough free space on /dev/$usr to backup /dev/$root!"
-                       echo "${free_space}Kb available, ${required_space} required."
+                       echo "${free_usr_space}Kb available, ${required_root_space} required."
                        exit 1
                fi