]>
Commit | Line | Data |
---|---|---|
89a12446 DM |
1 | #!/bin/bash |
2 | ||
3 | trap "err_reboot" ERR | |
4 | ||
0acbbbf5 TL |
5 | # NOTE: we nowadays get exec'd by the initrd's PID 1, so we're the new PID 1 |
6 | ||
89a12446 | 7 | parse_cmdline() { |
89a12446 | 8 | proxdebug=0 |
7a11b298 | 9 | proxtui=0 |
e2cbcc4e | 10 | serial=0 |
9e5787e5 | 11 | # shellcheck disable=SC2013 # per word splitting is wanted here |
dbe9a0c9 | 12 | for par in $(cat /proc/cmdline); do |
9e5787e5 TL |
13 | case $par in |
14 | proxdebug) | |
7a11b298 TL |
15 | proxdebug=1 |
16 | ;; | |
17 | proxtui) | |
18 | proxtui=1 | |
9e5787e5 | 19 | ;; |
a31259b1 SI |
20 | console=ttyS*) |
21 | serial=1 | |
22 | ;; | |
9e5787e5 | 23 | esac |
89a12446 DM |
24 | done; |
25 | } | |
26 | ||
27 | debugsh() { | |
16ff00ec | 28 | /bin/bash |
89a12446 DM |
29 | } |
30 | ||
0acbbbf5 TL |
31 | eject_and_reboot() { |
32 | iso_dev=$(awk '/ iso9660 / {print $1}' /proc/mounts) | |
33 | ||
34 | for try in 5 4 3 2 1; do | |
298bdcaf TL |
35 | echo "unmounting ISO" |
36 | if umount -v -a --types iso9660; then | |
0acbbbf5 TL |
37 | break |
38 | fi | |
39 | if test -n $try; then | |
e13e3510 | 40 | echo "unmount failed - trying again in 5 seconds" |
0acbbbf5 TL |
41 | sleep 5 |
42 | fi | |
43 | done | |
44 | ||
45 | if [ -n "$iso_dev" ]; then | |
6ce4f3d7 | 46 | eject "$iso_dev" || true # cannot really work currently, don't care |
0acbbbf5 TL |
47 | fi |
48 | ||
cd801ab8 TL |
49 | umount -l -n /dev |
50 | ||
0acbbbf5 TL |
51 | echo "rebooting - please remove the ISO boot media" |
52 | sleep 3 | |
024449f1 | 53 | reboot -nf |
6ce4f3d7 TL |
54 | sleep 5 |
55 | echo "trigger reset system request" | |
56 | # we do not expect the reboot above to fail, so rather to avoid kpanic when pid 1 exits | |
0acbbbf5 TL |
57 | echo b > /proc/sysrq-trigger |
58 | sleep 100 | |
59 | } | |
60 | ||
89a12446 | 61 | real_reboot() { |
dbe9a0c9 | 62 | trap - ERR |
89a12446 | 63 | |
e13e3510 TL |
64 | if [[ -x /etc/init.d/networking ]]; then |
65 | /etc/init.d/networking stop | |
66 | fi | |
89a12446 DM |
67 | |
68 | # stop udev (release file handles) | |
69 | /etc/init.d/udev stop | |
70 | ||
20d20ee3 | 71 | swap=$(awk '/^\/dev\// { print $1 }' /proc/swaps); |
89a12446 | 72 | if [ -n "$swap" ]; then |
6856f73c TL |
73 | echo -n "Deactivating swap..." |
74 | swapoff "$swap" | |
75 | echo "done." | |
89a12446 | 76 | fi |
89a12446 | 77 | |
6ce4f3d7 TL |
78 | # just to be sure |
79 | sync | |
80 | ||
89a12446 | 81 | umount -l -n /target >/dev/null 2>&1 |
57a8f6e5 TL |
82 | umount -l -n /dev/pts |
83 | umount -l -n /dev/shm | |
8d7ddbde | 84 | umount -l -n /run |
dea730ea | 85 | [ -d /sys/firmware/efi/efivars ] && umount -l -n /sys/firmware/efi/efivars |
89a12446 | 86 | |
0acbbbf5 TL |
87 | # do not unmount proc and sys for now, at least /proc is still required to trigger the actual |
88 | # reboot, and both are virtual FS only anyway | |
89 | ||
8a13026d TL |
90 | echo "Terminate all remaining processes" |
91 | kill -s TERM -1 # TERMinate all but current init (our self) PID 1 | |
92 | sleep 2 | |
93 | echo "Kill any remaining processes" | |
94 | kill -s KILL -1 # KILL all but current init (our self) PID 1 | |
95 | sleep 0.5 | |
0acbbbf5 TL |
96 | |
97 | eject_and_reboot | |
98 | ||
99 | exit 0 # shouldn't be reached, kernel will panic in that case | |
89a12446 DM |
100 | } |
101 | ||
102 | err_reboot() { | |
4fb3a9c6 | 103 | printf "\nInstallation aborted - unable to continue (type exit or CTRL-D to reboot)\n" |
2e3fe722 | 104 | debugsh || true |
89a12446 DM |
105 | real_reboot |
106 | } | |
107 | ||
478b111c TL |
108 | # NOTE: dbus must be launched before this, else iwd cannot work |
109 | # FIXME: very crude, still needs to actually copy over any iwd config to target | |
110 | handle_wireless() { | |
111 | wireless_found= | |
112 | for iface in /sys/class/net/*; do | |
113 | if [ -d "$iface/wireless" ]; then | |
114 | wireless_found=1 | |
115 | fi | |
116 | done | |
117 | if [ -z $wireless_found ]; then | |
118 | return; | |
119 | fi | |
120 | ||
121 | if [ -x /usr/libexec/iwd ]; then | |
122 | echo "wireless device(s) found, starting iwd; use 'iwctl' to manage connections (experimental)" | |
123 | /usr/libexec/iwd & | |
124 | else | |
125 | echo "wireless device found but iwd not available, ignoring" | |
126 | fi | |
127 | } | |
128 | ||
89a12446 DM |
129 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin |
130 | ||
fff4bc47 TL |
131 | echo "Starting Proxmox installation" |
132 | ||
0acbbbf5 | 133 | # ensure udev doesn't ignores our request; FIXME: not required anymore, as we use switch_root now |
194d737a TL |
134 | export SYSTEMD_IGNORE_CHROOT=1 |
135 | ||
89a12446 | 136 | mount -n -t proc proc /proc |
89a12446 | 137 | mount -n -t sysfs sysfs /sys |
f238dd03 TL |
138 | if [ -d /sys/firmware/efi ]; then |
139 | echo "EFI boot mode detected, mounting efivars filesystem" | |
dea730ea | 140 | mount -n -t efivarfs efivarfs /sys/firmware/efi/efivars |
f238dd03 | 141 | fi |
8d7ddbde | 142 | mount -n -t tmpfs tmpfs /run |
de629a23 | 143 | mkdir -p /run/proxmox-installer |
89a12446 DM |
144 | |
145 | parse_cmdline | |
146 | ||
147 | # always load most common input drivers | |
000f289d TL |
148 | modprobe -q psmouse || true |
149 | modprobe -q sermouse || true | |
150 | modprobe -q usbhid || true | |
89a12446 DM |
151 | |
152 | # load device mapper - used by lilo | |
000f289d | 153 | modprobe -q dm_mod || true |
89a12446 DM |
154 | |
155 | echo "Installing additional hardware drivers" | |
dbe9a0c9 | 156 | export RUNLEVEL=S |
89a12446 DM |
157 | export PREVLEVEL=N |
158 | /etc/init.d/udev start | |
159 | ||
3119bdeb TL |
160 | mkdir -p /dev/shm |
161 | mount -t tmpfs tmpfs /dev/shm | |
162 | ||
4569e022 TL |
163 | # allow pseudo terminals for debuggin in X |
164 | mkdir -p /dev/pts | |
165 | mount -vt devpts devpts /dev/pts -o gid=5,mode=620 | |
166 | ||
cbddb92d TL |
167 | # shellcheck disable=SC2207 |
168 | console_dim=($(IFS=' ' stty size)) # [height, width] | |
169 | DPI=96 | |
170 | if (("${console_dim[0]}" > 100)) && (("${console_dim[1]}" > 400)); then | |
171 | # heuristic only, high resolution can still mean normal/low DPI if it's a really big screen | |
172 | # FIXME: use `edid-decode` as it can contain physical dimensions to calculate actual dpi? | |
173 | echo "detected huge console, setting bigger font/dpi" | |
174 | DPI=192 | |
175 | export GDK_SCALE=2 | |
176 | setfont /usr/share/consolefonts/Uni2-Terminus32x16.psf.gz | |
177 | fi | |
178 | ||
d5268f68 TL |
179 | # set the hostname |
180 | hostname proxmox | |
181 | ||
478b111c TL |
182 | if command -v dbus-daemon; then |
183 | echo "starting D-Bus daemon" | |
184 | mkdir /run/dbus | |
185 | dbus-daemon --system --syslog-only | |
186 | ||
187 | if [ $proxdebug -ne 0 ]; then # FIXME: better intergration, e.g., use iwgtk? | |
188 | handle_wireless # no-op if not wireless dev is found | |
189 | fi | |
190 | fi | |
191 | ||
291ac3b6 TL |
192 | # we use a trimmed down debootstrap so make busybox tools available to compensate that |
193 | busybox --install -s || true | |
194 | ||
521662f8 TL |
195 | setupcon || echo "setupcon failed, TUI rendering might be garbled - $?" |
196 | ||
11a42156 | 197 | if [ $proxdebug -ne 0 ]; then |
aa0fe276 | 198 | /sbin/agetty -o '-p -- \\u' --noclear tty9 & |
fff4bc47 | 199 | printf "\nDropping in debug shell before starting installation\n" |
521662f8 | 200 | echo "type 'exit' or press CTRL + D to continue and start the installation wizard" |
2e3fe722 | 201 | debugsh || true |
11a42156 TL |
202 | fi |
203 | ||
89a12446 | 204 | # try to get ip config with dhcp |
01e402f0 FG |
205 | echo -n "Attempting to get DHCP leases... " |
206 | dhclient -v | |
89a12446 DM |
207 | echo "done" |
208 | ||
203059a9 | 209 | echo "Starting chrony for opportunistic time-sync... " |
d5268f68 | 210 | chronyd || echo "starting chrony failed ($?)" |
150291b3 | 211 | |
909936b5 SI |
212 | echo "Starting a root shell on tty3." |
213 | setsid /sbin/agetty -a root --noclear tty3 & | |
214 | ||
de629a23 TL |
215 | /usr/bin/proxmox-low-level-installer dump-env |
216 | ||
7a11b298 | 217 | if [ $proxtui -ne 0 ]; then |
a31259b1 SI |
218 | if [ "$serial" -ne 0 ]; then |
219 | echo "Setting terminal size to 80x24 for serial install" | |
220 | stty columns 80 rows 25 | |
221 | fi | |
222 | ||
7a11b298 | 223 | echo "Starting the TUI installer" |
65694938 | 224 | /usr/bin/proxmox-tui-installer 2>/dev/tty2 |
7a11b298 TL |
225 | else |
226 | echo "Starting the installer GUI - see tty2 (CTRL+ALT+F2) for any errors..." | |
0d97286c | 227 | xinit -- -dpi "$DPI" -s 0 >/dev/tty2 2>&1 |
7a11b298 | 228 | fi |
89a12446 | 229 | |
b0c4afcc DM |
230 | # just to be sure everything is on disk |
231 | sync | |
232 | ||
89a12446 | 233 | if [ $proxdebug -ne 0 ]; then |
fff4bc47 | 234 | printf "\nDebug shell after installation exited (type exit or CTRL-D to reboot)\n" |
2e3fe722 | 235 | debugsh || true |
89a12446 DM |
236 | fi |
237 | ||
238 | echo "Installation done, rebooting... " | |
d13c1966 TL |
239 | |
240 | killall5 -15 | |
241 | ||
89a12446 DM |
242 | real_reboot |
243 | ||
244 | # never reached | |
245 | exit 0 |