]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/system/partresize
f3e3c0f0d1ab3aaa657ff6c52b473f5cecac8068
[ipfire-2.x.git] / src / initscripts / system / partresize
1 #!/bin/sh
2 ########################################################################
3 # Begin $rc_base/init.d/partresize
4 #
5 # Description : Resize the root partition to the drivesize
6 #
7 # Authors : Arne Fitzenreiter - arne_f@ipfire.org
8 #
9 # Version : 1.04
10 #
11 # Notes :
12 #
13 ########################################################################
14
15 . /etc/sysconfig/rc
16 . ${rc_functions}
17
18 case "${1}" in
19 start)
20 if [ -e "/.partresize" ]; then
21
22 boot_mesg "Mounting root file system in read/write mode ..."
23 mount -o remount,rw / > /dev/null
24 evaluate_retval
25
26 boot_mesg "Create /etc/mtab..."
27 > /etc/mtab
28 mount -f / || failed=1
29 (exit ${failed})
30 evaluate_retval
31
32 # check if serial console enabled
33 scon="off";
34 if [ ! "$(grep "console=ttyS0" /proc/cmdline)" == "" ]; then
35 scon="on";
36 fi
37 IFS= read -r DMI_PRODUCT_NAME < /sys/class/dmi/id/product_name;
38 case ${DMI_PRODUCT_NAME} in
39 APU|apu[2-4]|PC\ Engines\ apu[1-4] )
40 scon="on";
41 ;;
42 esac
43
44 mount /boot > /dev/null
45 if [ -e /boot/grub/grub.cfg ]; then
46 # swtich permanent to serial console if it was selected on first boot
47 if [ "${scon}" = "on" ]; then
48 # Enable also serial console on GRUB
49 echo "GRUB_TERMINAL=\"serial console\"" >> /etc/default/grub
50 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> /etc/default/grub
51 sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" /etc/default/grub
52 fi
53
54 # Re-generate GRUB configuration
55 /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
56 fi
57 umount /boot > /dev/null
58
59 # Detect device
60 mount | while read -r dev tmp1 mountpoint tmp2; do
61 [ "${dev}" = "rootfs" ] && continue
62
63 if [ "${mountpoint}" = "/" ]; then
64 # Find root partition number
65 part_num="${dev: -1}"
66
67 # Find path to the root device
68 root_dev="${dev::-1}"
69 if [ ! -b "${dev::-1}" -a "${root_dev: -1}" = "p" ]; then
70 root_dev="${dev::-2}"
71 fi
72
73 boot_mesg "Growing root partition to maximum size..."
74 echo -e ',+' | sfdisk --no-reread -f -N${part_num} "${root_dev}" 2>/dev/null
75
76 # Update c,h,s values of the boot partition...
77 if [ ${part_num} -ne 1 -a -b "${root_dev}1" ]; then
78 echo -e ',' | sfdisk --no-reread -f -N1 ${DRV} &> /dev/null
79 fi
80
81 # The filesystem should be resized after
82 # this operation
83 touch /.resizefs
84
85 # Remove marker
86 rm -f /.partresize
87
88 # Reboot
89 boot_mesg "Rebooting system..."
90 mount -o remount,ro / &>/dev/null
91 sleep 15
92 reboot -f
93 fi
94 done
95 fi
96 ;;
97 *)
98 echo "Usage: ${0} {start}"
99 exit 1
100 ;;
101 esac
102
103 # End $rc_base/init.d/partresize