]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/system/partresize
7605b9e2b15a618f949741687e97d8fe0ff16e20
[people/pmueller/ipfire-2.x.git] / src / initscripts / system / partresize
1 #!/bin/sh
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 . /etc/sysconfig/rc
23 . ${rc_functions}
24
25 case "${1}" in
26 start)
27 if [ -e "/.partresize" ]; then
28
29 boot_mesg "Mounting root file system in read/write mode ..."
30 mount -o remount,rw / > /dev/null
31 evaluate_retval
32
33 boot_mesg "Create /etc/mtab..."
34 > /etc/mtab
35 mount -f / || failed=1
36 (exit ${failed})
37 evaluate_retval
38
39 # check if serial console enabled
40 scon="off";
41 if [ ! "$(grep "console=ttyS0" /proc/cmdline)" == "" ]; then
42 scon="on";
43 fi
44 if [ -e /sys/class/dmi/id/product_name ]; then
45 IFS= read -r DMI_PRODUCT_NAME < /sys/class/dmi/id/product_name;
46 case ${DMI_PRODUCT_NAME} in
47 APU|apu[1-4]|PC\ Engines\ apu[1-4] )
48 scon="on";
49 ;;
50 esac
51 fi
52
53 # Enable the serial console on all systems on AWS EC2, Oracle Cloud,
54 # Azure and Google Compute Platform
55 if running_on_ec2 || running_on_oci || running_on_azure || running_on_gcp; then
56 scon="on"
57 fi
58
59 mount /boot > /dev/null
60 case "$(< /proc/device-tree/model )" in
61 FriendlyElec\ NanoPi?R1* )
62 # Install AP6112 wlan config on NanoPi R1
63 cp -f /lib/firmware/brcm/brcmfmac43430-sdio.AP6212.txt \
64 /lib/firmware/brcm/brcmfmac43430-sdio.txt
65 cp -f /lib/firmware/brcm/brcmfmac43430a0-sdio.ONDA-V80_PLUS.txt \
66 /lib/firmware/brcm/brcmfmac43430a0-sdio.txt
67 ;;
68 FriendlyElec\ NanoPi?R2* )
69 # Generate MAC address at first boot
70 SWMAC=`printf "%1x2:%02x:%02x:%02x:%02x" $[RANDOM%16] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]`
71 echo ethaddr=$SWMAC:00 >> /boot/uEnv.txt
72 echo eth1addr=$SWMAC:01 >> /boot/uEnv.txt
73 ;;
74 FriendlyElec\ NanoPi?R4* )
75 # Generate MAC address at first boot
76 SWMAC=`printf "%1x2:%02x:%02x:%02x:%02x" $[RANDOM%16] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]`
77 echo ethaddr=$SWMAC:00 >> /boot/uEnv.txt
78 echo eth1addr=$SWMAC:01 >> /boot/uEnv.txt
79 ;;
80 esac 2>/dev/null
81
82 if [ -e /boot/grub/grub.cfg ]; then
83 # swtich permanent to serial console if it was selected on first boot
84 if [ "${scon}" = "on" ]; then
85 # Enable also serial console on GRUB
86 echo "GRUB_TERMINAL=\"serial console\"" >> /etc/default/grub
87 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> /etc/default/grub
88 sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" /etc/default/grub
89 fi
90
91 # Re-generate GRUB configuration
92 /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
93 fi
94 umount /boot > /dev/null
95
96 # Detect device
97 mount | while read -r dev tmp1 mountpoint tmp2; do
98 [ "${dev}" = "rootfs" ] && continue
99
100 if [ "${mountpoint}" = "/" ]; then
101 # Find root partition number
102 part_num="${dev: -1}"
103
104 # Find path to the root device
105 root_dev="${dev::-1}"
106 if [ ! -b "${dev::-1}" -a "${root_dev: -1}" = "p" ]; then
107 root_dev="${dev::-2}"
108 fi
109
110 boot_mesg "Growing root partition to maximum size..."
111 echo -e ',+' | sfdisk --no-reread -f -N${part_num} "${root_dev}" 2>/dev/null
112
113 # Update c,h,s values of the boot partition...
114 if [ ${part_num} -ne 1 -a -b "${root_dev}1" ]; then
115 echo -e ',' | sfdisk --no-reread -f -N1 ${DRV} &> /dev/null
116 fi
117
118 # The filesystem should be resized after
119 # this operation
120 touch /.resizefs
121
122 # Remove marker
123 rm -f /.partresize
124
125 # Reboot
126 boot_mesg "Rebooting system..."
127 mount -o remount,ro / &>/dev/null
128 sleep 15
129 reboot -f
130 fi
131 done
132 fi
133 ;;
134 *)
135 echo "Usage: ${0} {start}"
136 exit 1
137 ;;
138 esac