Update auto-resize code to work with any partition number

This commit is contained in:
Michael Tremer
2014-08-24 13:29:18 +02:00
parent c42cbc86b3
commit a24546794d
6 changed files with 62 additions and 48 deletions

View File

@@ -17,22 +17,24 @@
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
;;
*)

View File

@@ -17,40 +17,48 @@
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
# Detect device
while read -r dev mountpoint fs options; do
[ "${dev}" = "rootfs" ] && continue
boot_mesg "Create /etc/mtab..."
> /etc/mtab
mount -f / || failed=1
(exit ${failed})
evaluate_retval
if [ "${mountpoint}" = "/" ]; then
# Find root partition number
part_num="${dev: -1}"
# 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}
# 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 "Growing root partition to maximum size..."
echo -e ',+' | sfdisk --no-reread -f -N${part_num} "${root_dev}" 2>/dev/null
# 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
# 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
boot_mesg "Change Partition ${DRV}3 to all free space ..."
echo -e ',+' | sfdisk --no-reread -f -N3 ${DRV} 2>/dev/null
boot_mesg "Update c,h,s values of ${DRV}1 ..."
echo -e ',' | sfdisk --no-reread -f -N1 ${DRV} &> /dev/null
# Erase symlink, it should run only once
rm -f /etc/rc.d/rcsysinit.d/S25partresize
boot_mesg "Rebooting ..."
sync
mount -o remount,ro / &> /dev/null
sleep 15
reboot -f
;;
*)
echo "Usage: ${0} {start}"