]> git.proxmox.com Git - pve-installer.git/blame - unconfigured.sh
unconfigured: reboot: explicitly unnmount /dev/pts /dev/shm too
[pve-installer.git] / unconfigured.sh
CommitLineData
89a12446
DM
1#!/bin/bash
2
3trap "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 7parse_cmdline() {
89a12446 8 proxdebug=0
9e5787e5 9 # shellcheck disable=SC2013 # per word splitting is wanted here
dbe9a0c9 10 for par in $(cat /proc/cmdline); do
9e5787e5
TL
11 case $par in
12 proxdebug)
13 proxdebug=1
14 ;;
15 esac
89a12446
DM
16 done;
17}
18
19debugsh() {
16ff00ec 20 /bin/bash
89a12446
DM
21}
22
0acbbbf5
TL
23eject_and_reboot() {
24 iso_dev=$(awk '/ iso9660 / {print $1}' /proc/mounts)
25
26 for try in 5 4 3 2 1; do
27 echo "unmounting all"
28 if umount -a; then
29 break
30 fi
31 if test -n $try; then
32 echo "unmount failed -trying again in 5 seconds"
33 sleep 5
34 fi
35 done
36
37 if [ -n "$iso_dev" ]; then
38 eject "$iso_dev"
39 fi
40
41 echo "rebooting - please remove the ISO boot media"
42 sleep 3
43 echo b > /proc/sysrq-trigger
44 sleep 100
45}
46
89a12446 47real_reboot() {
dbe9a0c9 48 trap - ERR
89a12446 49
dbe9a0c9 50 /etc/init.d/networking stop
89a12446
DM
51
52 # stop udev (release file handles)
53 /etc/init.d/udev stop
54
55 echo -n "Deactivating swap..."
20d20ee3 56 swap=$(awk '/^\/dev\// { print $1 }' /proc/swaps);
89a12446 57 if [ -n "$swap" ]; then
20d20ee3 58 swapoff "$swap"
89a12446
DM
59 fi
60 echo "done."
61
89a12446 62 umount -l -n /target >/dev/null 2>&1
57a8f6e5
TL
63 umount -l -n /dev/pts
64 umount -l -n /dev/shm
37a88382 65 umount -l -n /dev
8d7ddbde 66 umount -l -n /run
dea730ea 67 [ -d /sys/firmware/efi/efivars ] && umount -l -n /sys/firmware/efi/efivars
89a12446 68
0acbbbf5
TL
69 # do not unmount proc and sys for now, at least /proc is still required to trigger the actual
70 # reboot, and both are virtual FS only anyway
71
72 kill -s KILL -1 # kill all but current init (our self) PID 1
73 sleep 1
74
75 eject_and_reboot
76
77 exit 0 # shouldn't be reached, kernel will panic in that case
89a12446
DM
78}
79
80err_reboot() {
4fb3a9c6 81 printf "\nInstallation aborted - unable to continue (type exit or CTRL-D to reboot)\n"
2e3fe722 82 debugsh || true
89a12446
DM
83 real_reboot
84}
85
86echo "Starting Proxmox installation"
87
88PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
89
0acbbbf5 90# ensure udev doesn't ignores our request; FIXME: not required anymore, as we use switch_root now
194d737a
TL
91export SYSTEMD_IGNORE_CHROOT=1
92
89a12446 93mount -n -t proc proc /proc
89a12446 94mount -n -t sysfs sysfs /sys
f238dd03
TL
95if [ -d /sys/firmware/efi ]; then
96 echo "EFI boot mode detected, mounting efivars filesystem"
dea730ea 97 mount -n -t efivarfs efivarfs /sys/firmware/efi/efivars
f238dd03 98fi
8d7ddbde 99mount -n -t tmpfs tmpfs /run
89a12446
DM
100
101parse_cmdline
102
103# always load most common input drivers
000f289d
TL
104modprobe -q psmouse || true
105modprobe -q sermouse || true
106modprobe -q usbhid || true
89a12446
DM
107
108# load device mapper - used by lilo
000f289d 109modprobe -q dm_mod || true
89a12446
DM
110
111echo "Installing additional hardware drivers"
dbe9a0c9 112export RUNLEVEL=S
89a12446
DM
113export PREVLEVEL=N
114/etc/init.d/udev start
115
3119bdeb
TL
116mkdir -p /dev/shm
117mount -t tmpfs tmpfs /dev/shm
118
4569e022
TL
119# allow pseudo terminals for debuggin in X
120mkdir -p /dev/pts
121mount -vt devpts devpts /dev/pts -o gid=5,mode=620
122
11a42156 123if [ $proxdebug -ne 0 ]; then
aa0fe276 124 /sbin/agetty -o '-p -- \\u' --noclear tty9 &
4fb3a9c6
TL
125 echo "Dropping in debug shell before starting installation"
126 echo "type exit or CTRL-D to continue and start the installation wizard"
2e3fe722 127 debugsh || true
11a42156
TL
128fi
129
dbe9a0c9 130# set the hostname
89a12446
DM
131hostname proxmox
132
89a12446 133# try to get ip config with dhcp
01e402f0
FG
134echo -n "Attempting to get DHCP leases... "
135dhclient -v
89a12446
DM
136echo "done"
137
150291b3
TL
138echo -n "Starting chrony for opportunistic time-sync... "
139chronyd || echo "starting chrony failed"
140
909936b5
SI
141echo "Starting a root shell on tty3."
142setsid /sbin/agetty -a root --noclear tty3 &
143
89a12446
DM
144xinit -- -dpi 96 >/dev/tty2 2>&1
145
b0c4afcc
DM
146# just to be sure everything is on disk
147sync
148
89a12446 149if [ $proxdebug -ne 0 ]; then
000f289d 150 echo "Debug shell after installation exited (type exit or CTRL-D to reboot)"
2e3fe722 151 debugsh || true
89a12446
DM
152fi
153
154echo "Installation done, rebooting... "
d13c1966
TL
155
156killall5 -15
157
89a12446
DM
158real_reboot
159
160# never reached
161exit 0