]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
Update auto-resize code to work with any partition number
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 24 Aug 2014 11:29:18 +0000 (13:29 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 24 Aug 2014 11:29:18 +0000 (13:29 +0200)
config/rootfiles/common/armv5tel/initscripts
config/rootfiles/common/i586/initscripts
lfs/flash-images
lfs/initscripts
src/initscripts/init.d/fsresize
src/initscripts/init.d/partresize

index 5e40079a9fa317dfac347f542c2a703f2364a13b..7a4e41b7da613d8477bbb9a02939a832ac08b80e 100644 (file)
@@ -213,8 +213,10 @@ etc/rc.d/rcsysinit.d/S05modules
 etc/rc.d/rcsysinit.d/S10udev
 etc/rc.d/rcsysinit.d/S19waitdrives
 etc/rc.d/rcsysinit.d/S20swap
+etc/rc.d/rcsysinit.d/S25partresize
 etc/rc.d/rcsysinit.d/S30checkfs
 etc/rc.d/rcsysinit.d/S40mountfs
+etc/rc.d/rcsysinit.d/S42fsresize
 etc/rc.d/rcsysinit.d/S45udev_retry
 etc/rc.d/rcsysinit.d/S50cleanfs
 etc/rc.d/rcsysinit.d/S60setclock
index 6704251d5a316b6078208c9260134c829626dd02..529bcc9c0a354476e1df37139861a38a9e41ad0a 100644 (file)
@@ -220,8 +220,10 @@ etc/rc.d/rcsysinit.d/S10udev
 etc/rc.d/rcsysinit.d/S19checkfstab
 etc/rc.d/rcsysinit.d/S19waitdrives
 etc/rc.d/rcsysinit.d/S20swap
+etc/rc.d/rcsysinit.d/S25partresize
 etc/rc.d/rcsysinit.d/S30checkfs
 etc/rc.d/rcsysinit.d/S40mountfs
+etc/rc.d/rcsysinit.d/S42fsresize
 etc/rc.d/rcsysinit.d/S45udev_retry
 etc/rc.d/rcsysinit.d/S50cleanfs
 etc/rc.d/rcsysinit.d/S60setclock
index 69b6b44ebd35999f058fb062e5233c6d201293ea..7baec7c2eec6db70299e38d0c50deb372aa9a276 100644 (file)
@@ -162,11 +162,6 @@ endif
        printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \
                "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab
 
-       # Setup symlink for partresize at first boot...
-       ln -sf ../init.d/partresize $(MNThdd)/etc/rc.d/rcsysinit.d/S25partresize
-       # Setup symlink for fsresize at second boot...
-       ln -sf ../init.d/fsresize $(MNThdd)/etc/rc.d/rcsysinit.d/S42fsresize
-
 ifeq "$(BOOTLOADER)" "grub"
 ifeq "$(SCON)" "1"
        # Enable serial console on GRUB
@@ -189,6 +184,9 @@ endif
                --root-directory=$(MNThdd) $(DEVICE)
 endif
 
+       # Automatically resize the root partition to its maximum size at first boot
+       touch $(MNThdd)/.partresize
+
        # Unmount
        umount $(MNThdd)/proc
        umount $(MNThdd)/sys
index 4acf65e13eb965ae8673e0a40e72786a30d3a5c9..c5fe54f8245ad9adeebe488b08ecfe86496c7e69 100644 (file)
@@ -162,8 +162,10 @@ $(TARGET) :
        ln -sf ../init.d/udev        /etc/rc.d/rcsysinit.d/S10udev
        ln -sf ../init.d/waitdrives  /etc/rc.d/rcsysinit.d/S19waitdrives
        ln -sf ../init.d/swap        /etc/rc.d/rcsysinit.d/S20swap
+       ln -sf ../init.d/partresize  /etc/rc.d/rcsysinit.d/S25partresize
        ln -sf ../init.d/checkfs     /etc/rc.d/rcsysinit.d/S30checkfs
        ln -sf ../init.d/mountfs     /etc/rc.d/rcsysinit.d/S40mountfs
+       ln -sf ../init.d/fsresize    /etc/rc.d/rcsysinit.d/S42fsresize
        ln -sf ../init.d/udev_retry  /etc/rc.d/rcsysinit.d/S45udev_retry
        ln -sf ../init.d/cleanfs     /etc/rc.d/rcsysinit.d/S50cleanfs
        ln -sf ../init.d/setclock    /etc/rc.d/rcsysinit.d/S60setclock
index 3dbd1addd50230fed436e5d919ccc1b7f9ac779b..325c731af849ab8e78f9ae348f7cf0070f6f69b6 100644 (file)
 
 case "${1}" in
        start)
-               boot_mesg "Background Autoresize root partition to use the whole drive"
-               # Detect device
-               ROOT=`mount | grep -m1 " / " | cut -d" " -f1`;
-               DRV=${ROOT::`expr length $ROOT`-1}
+               if [ -e "/.resizefs" ]; then
+                       boot_mesg "Re-sizing root partition..."
 
-               boot_mesg "resize ${DRV}3 ..."
-               nice -n 19 $0 background ${DRV}3 > /dev/null &
-               ;;
-       background)
-               resize2fs -p $2
+                       # Find root device
+                       while read -r dev mountpoint fs options; do
+                               # Skip generic entries
+                               [ "${dev}" = "rootfs" ] && continue
 
-               # Erase symlink, it should run only once
-               rm -f /etc/rc.d/rcsysinit.d/S42fsresize
-               sync
-               exit 0;
+                               if [ "${mountpoint}" = "/" ]; then
+                                       # Resize filesystem
+                                       resize2fs -p "${dev}"
 
+                                       # Remove marker
+                                       rm -f /.resizefs
+                                       break
+                               fi
+                       done < /proc/mounts
+               fi
                ;;
 
        *)
index f9b1aa92f09f6a2aa38aecefd9f6c01cfe2c7823..38c5683166e034c93c7f7abd8d6768ecac3dd6fc 100644 (file)
 
 case "${1}" in
        start)
+               if [ -e "/.partresize" ]; then
+                       boot_mesg "Mounting root file system in read/write mode ..."
+                       mount -o remount,rw / > /dev/null
+                       evaluate_retval
 
-               boot_mesg "Mounting root file system in read/write mode ..."
-               mount -o remount,rw / > /dev/null
-               evaluate_retval
-
-               boot_mesg "Create /etc/mtab..."
-               > /etc/mtab
-               mount -f / || failed=1
-               (exit ${failed})
-               evaluate_retval
-
-               # Detect device
-               ROOT=`mount | grep -m1 " / " | cut -d" " -f1`;
-               if [ "${ROOT:`expr length $ROOT`-2:1}" == "p" ]; then
-                       DRV=${ROOT::`expr length $ROOT`-2}
-               else
-                       DRV=${ROOT::`expr length $ROOT`-1}
-               fi
+                       # Detect device
+                       while read -r dev mountpoint fs options; do
+                               [ "${dev}" = "rootfs" ] && continue
+
+                               if [ "${mountpoint}" = "/" ]; then
+                                       # Find root partition number
+                                       part_num="${dev: -1}"
 
-               boot_mesg "Change Partition ${DRV}3 to all free space ..."
-               echo -e ',+' | sfdisk --no-reread -f -N3 ${DRV} 2>/dev/null
+                                       # Find path to the root device
+                                       root_dev="${dev::-1}"
+                                       if [ ! -b "${dev::-1}" -a "${root_dev: -1}" = "p" ]; then
+                                               root_dev="${dev::-2}"
+                                       fi
 
-               boot_mesg "Update c,h,s values of ${DRV}1 ..."
-               echo -e ',' | sfdisk --no-reread -f -N1 ${DRV} &> /dev/null
+                                       boot_mesg "Growing root partition to maximum size..."
+                                       echo -e ',+' | sfdisk --no-reread -f -N${part_num} "${root_dev}" 2>/dev/null
 
-               # Erase symlink, it should run only once
-               rm -f /etc/rc.d/rcsysinit.d/S25partresize
+                                       # Update c,h,s values of the boot partition...
+                                       if [ ${part_num} -ne 1 -a -b "${root_dev}1" ]; then
+                                               echo -e ',' | sfdisk --no-reread -f -N1 ${DRV} &> /dev/null
+                                       fi
 
-               boot_mesg "Rebooting ..."
-               sync
-               mount -o remount,ro / &> /dev/null
-               sleep 15
-               reboot -f
+                                       # The filesystem should be resized after
+                                       # this operation
+                                       touch /.resizefs
 
+                                       # Remove marker
+                                       rm -f /.partresize
+
+                                       # Reboot
+                                       boot_mesg "Rebooting system..."
+                                       mount -o remount,ro / &>/dev/null
+                                       sleep 15
+                                       reboot -f
+                               fi
+                       done < /proc/mounts
+               fi
                ;;
        *)
                echo "Usage: ${0} {start}"