]>
Commit | Line | Data |
---|---|---|
a6d0d790 AF |
1 | #!/bin/sh |
2 | ######################################################################## | |
3 | # Begin $rc_base/init.d/partresize | |
4 | # | |
3e011c27 | 5 | # Description : Resize the root partition to the drivesize |
fa5e921c AF |
6 | # and setup some platform or hardware options in |
7 | # flashimage | |
a6d0d790 AF |
8 | # |
9 | # Authors : Arne Fitzenreiter - arne_f@ipfire.org | |
10 | # | |
b8101c50 | 11 | # Version : 1.04 |
a6d0d790 AF |
12 | # |
13 | # Notes : | |
14 | # | |
15 | ######################################################################## | |
16 | ||
17 | . /etc/sysconfig/rc | |
18 | . ${rc_functions} | |
19 | ||
20 | case "${1}" in | |
21 | start) | |
a2454679 | 22 | if [ -e "/.partresize" ]; then |
6b566244 | 23 | |
a2454679 MT |
24 | boot_mesg "Mounting root file system in read/write mode ..." |
25 | mount -o remount,rw / > /dev/null | |
26 | evaluate_retval | |
a6d0d790 | 27 | |
c0504c5c AF |
28 | boot_mesg "Create /etc/mtab..." |
29 | > /etc/mtab | |
30 | mount -f / || failed=1 | |
31 | (exit ${failed}) | |
32 | evaluate_retval | |
33 | ||
8f49959d AF |
34 | # check if serial console enabled |
35 | scon="off"; | |
36 | if [ ! "$(grep "console=ttyS0" /proc/cmdline)" == "" ]; then | |
37 | scon="on"; | |
38 | fi | |
99f2c695 AF |
39 | if [ -e /sys/class/dmi/id/product_name ]; then |
40 | IFS= read -r DMI_PRODUCT_NAME < /sys/class/dmi/id/product_name; | |
41 | case ${DMI_PRODUCT_NAME} in | |
42 | APU|apu[1-4]|PC\ Engines\ apu[1-4] ) | |
43 | scon="on"; | |
44 | ;; | |
45 | esac | |
46 | fi | |
8f49959d | 47 | |
a09578f4 MT |
48 | # Enable the serial console on all systems on AWS EC2, Oracle Cloud, |
49 | # Azure and Google Compute Platform | |
50 | if running_on_ec2 || running_on_oci || running_on_azure || running_on_gcp; then | |
bc503715 MT |
51 | scon="on" |
52 | fi | |
53 | ||
75c9d8c2 | 54 | mount /boot > /dev/null |
fa5e921c | 55 | case "$(< /proc/device-tree/model )" in |
2f3af8c0 | 56 | FriendlyElec\ NanoPi?R1* ) |
75c9d8c2 | 57 | # Install AP6112 wlan config on NanoPi R1 |
fa5e921c AF |
58 | cp -f /lib/firmware/brcm/brcmfmac43430-sdio.AP6212.txt \ |
59 | /lib/firmware/brcm/brcmfmac43430-sdio.txt | |
97f4b514 AF |
60 | cp -f /lib/firmware/brcm/brcmfmac43430a0-sdio.ONDA-V80_PLUS.txt \ |
61 | /lib/firmware/brcm/brcmfmac43430a0-sdio.txt | |
fa5e921c | 62 | ;; |
2f3af8c0 | 63 | FriendlyElec\ NanoPi?R2* ) |
75c9d8c2 AF |
64 | # Generate MAC address at first boot |
65 | SWMAC=`printf "%1x2:%02x:%02x:%02x:%02x" $[RANDOM%16] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]` | |
66 | echo ethaddr=$SWMAC:00 >> /boot/uEnv.txt | |
67 | echo eth1addr=$SWMAC:01 >> /boot/uEnv.txt | |
68 | ;; | |
2f3af8c0 | 69 | FriendlyElec\ NanoPi?R4* ) |
75c9d8c2 AF |
70 | # Generate MAC address at first boot |
71 | SWMAC=`printf "%1x2:%02x:%02x:%02x:%02x" $[RANDOM%16] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]` | |
72 | echo ethaddr=$SWMAC:00 >> /boot/uEnv.txt | |
73 | echo eth1addr=$SWMAC:01 >> /boot/uEnv.txt | |
74 | ;; | |
fa5e921c AF |
75 | esac 2>/dev/null |
76 | ||
6b566244 AF |
77 | if [ -e /boot/grub/grub.cfg ]; then |
78 | # swtich permanent to serial console if it was selected on first boot | |
8f49959d | 79 | if [ "${scon}" = "on" ]; then |
6b566244 AF |
80 | # Enable also serial console on GRUB |
81 | echo "GRUB_TERMINAL=\"serial console\"" >> /etc/default/grub | |
82 | echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> /etc/default/grub | |
83 | sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" /etc/default/grub | |
84 | fi | |
43829df3 MT |
85 | |
86 | # Re-generate GRUB configuration | |
87 | /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg | |
6b566244 AF |
88 | fi |
89 | umount /boot > /dev/null | |
90 | ||
a2454679 | 91 | # Detect device |
c0504c5c | 92 | mount | while read -r dev tmp1 mountpoint tmp2; do |
a2454679 MT |
93 | [ "${dev}" = "rootfs" ] && continue |
94 | ||
95 | if [ "${mountpoint}" = "/" ]; then | |
96 | # Find root partition number | |
97 | part_num="${dev: -1}" | |
a6d0d790 | 98 | |
a2454679 MT |
99 | # Find path to the root device |
100 | root_dev="${dev::-1}" | |
101 | if [ ! -b "${dev::-1}" -a "${root_dev: -1}" = "p" ]; then | |
102 | root_dev="${dev::-2}" | |
103 | fi | |
6450609d | 104 | |
a2454679 MT |
105 | boot_mesg "Growing root partition to maximum size..." |
106 | echo -e ',+' | sfdisk --no-reread -f -N${part_num} "${root_dev}" 2>/dev/null | |
a6d0d790 | 107 | |
a2454679 MT |
108 | # Update c,h,s values of the boot partition... |
109 | if [ ${part_num} -ne 1 -a -b "${root_dev}1" ]; then | |
110 | echo -e ',' | sfdisk --no-reread -f -N1 ${DRV} &> /dev/null | |
111 | fi | |
a6d0d790 | 112 | |
a2454679 MT |
113 | # The filesystem should be resized after |
114 | # this operation | |
115 | touch /.resizefs | |
a6d0d790 | 116 | |
a2454679 MT |
117 | # Remove marker |
118 | rm -f /.partresize | |
119 | ||
120 | # Reboot | |
121 | boot_mesg "Rebooting system..." | |
122 | mount -o remount,ro / &>/dev/null | |
123 | sleep 15 | |
124 | reboot -f | |
125 | fi | |
c0504c5c | 126 | done |
a2454679 | 127 | fi |
a6d0d790 AF |
128 | ;; |
129 | *) | |
130 | echo "Usage: ${0} {start}" | |
131 | exit 1 | |
132 | ;; | |
133 | esac | |
134 | ||
135 | # End $rc_base/init.d/partresize |