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
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
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
--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
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
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
;;
*)
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}"