slitaz-boot-scripts view etc/init.d/bootopts.sh @ rev 466

bootopts.sh: ensure keyboard is defined (for uefi case)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Sep 15 15:00:15 2020 +0000 (2020-09-15)
parents da1ed39c4f67
children 0dfcc5bf7b5a
line source
1 #!/bin/sh
2 #
3 # /etc/init.d/bootopts.sh : SliTaz boot options from the cmdline
4 #
5 # Earlier boot options are in rcS, ex: config= and modprobe=
6 #
7 . /etc/init.d/rc.functions
9 # Get first usb disk
10 usb_device() {
11 cd /sys/block
12 for i in sd* sda ; do
13 grep -qs 1 $i/removable && break
14 done
15 echo $i
16 }
18 # Parse /proc/cmdline for boot options.
19 echo 'Checking for SliTaz cmdline options...'
21 # Default user account without password (uid=1000). In live mode the option
22 # user=name can be used, but user must be added before home= to have home dir.
23 # This option is not handled by a loop and case like others and has no
24 # effect on an installed system.
25 if fgrep -q 'user=' /proc/cmdline; then
26 USER=$(sed 's/.*user=\([^ ]*\).*/\1/' /proc/cmdline)
27 # Avoid usage of an existing system user or root.
28 if grep -q ^$USER /etc/passwd; then
29 USER=tux
30 fi
31 else
32 USER=tux
33 fi
35 if ! grep -q '100[0-9]:100' /etc/passwd; then
36 # Make sure we have users applications.conf
37 if [ ! -f '/etc/skel/.config/slitaz/applications.conf' -a \
38 -f '/etc/slitaz/applications.conf' ]; then
39 mkdir -p /etc/skel/.config/slitaz
40 cp /etc/slitaz/applications.conf /etc/skel/.config/slitaz
41 fi
43 action 'Configuring user and group: %s...' "$USER"
44 adduser -D -s /bin/sh -g 'SliTaz User' -G users -h /home/$USER $USER
45 passwd -d $USER >/dev/null
46 for group in audio cdrom video tty plugdev disk; do
47 addgroup $USER $group
48 done
49 status
51 # Slim default user
52 if [ -f /etc/slim.conf ]; then
53 sed -i "s|default_user .*|default_user $USER|" /etc/slim.conf
54 fi
55 fi
57 # Make sure selected user has home
58 if [ ! -d /home/$USER ]; then
59 cp -a /etc/skel /home/$USER
60 chown -R $USER:users /home/$USER
61 fi
63 for opt in $(cat /proc/cmdline); do
64 case $opt in
65 eject)
66 # Eject cdrom.
67 eject /dev/cdrom ;;
68 autologin)
69 # Autologin option to skip first graphic login prompt.
70 if [ -f /etc/slim.conf ]; then
71 sed -i '/auto_login .*/d' /etc/slim.conf
72 echo 'auto_login yes' >> /etc/slim.conf
73 fi ;;
74 lang=*)
75 # Check for a specified locale (lang=*).
76 LANG=${opt#lang=}
77 /sbin/tazlocale ${LANG%.UTF-8} ;;
78 kmap=*)
79 # Check for a specified keymap (kmap=*).
80 KEYMAP=${opt#kmap=}
81 action 'Setting system keymap to: %s...' "$KEYMAP"
82 echo "$KEYMAP" > /etc/keymap.conf
83 status ;;
84 tz=*)
85 # Check for a specified timezone (tz=*).
86 TZ=${opt#tz=}
87 action 'Setting timezone to: %s...' "$TZ"
88 echo "$TZ" > /etc/TZ
89 status ;;
90 font=*)
91 # Check for a specified console font (font=*).
92 FONT=${opt#font=}
93 action 'Setting console font to: %s...' "$FONT"
94 for con in 1 2 3 4 5 6; do
95 setfont $FONT -C /dev/tty$con
96 done
97 status ;;
98 home=*)
99 # Check for a specified home partition (home=*) and check for
100 # user home dir. Note: home=usb is a shorter and easier way to
101 # have home=/dev/sda1.
102 DEVICE=${opt#home=}
103 [ "$DEVICE" = "usb" ] && DEVICE="$(usb_device)1"
104 echo "Home has been specified to $DEVICE..."
106 DEVID=$(/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q')
107 if [ -z "$DEVID" ]; then
108 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
109 USBDELAY=$((2+$USBDELAY))
110 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
111 sleep $USBDELAY
112 fi
114 USER=$(sed '/:1000:/!d;s/:.*//;q' /etc/passwd)
115 DEVID=$DEVICE
116 if [ -x /sbin/blkid ]; then
117 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
118 DEVID=$(/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q')
119 fi
120 DEVID=${DEVID##*/}
122 if [ -n "$DEVID" ] && fgrep -q "$DEVID" /proc/partitions ; then
123 echo "Mounting /home on /dev/$DEVID... "
124 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
125 mount /dev/$DEVID /home &&
126 case "$(/sbin/blkid | grep /dev/$DEVID:)" in
127 *\"ntfs\"*|*\"vfat\"*)
128 mount.posixovl -F /home -- -oallow_other -odefault_permissions -osuid ;;
129 esac
130 mount /home -o remount,uid=1000,gid=100 2>/dev/null
132 # Check if swap file must be generated in /home: swap=size (Mb).
133 # This option is only used within home=device.
134 if grep -q 'swap=[1-9]*' /proc/cmdline; then
135 SWAP_SIZE=$(sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline)
136 # DD to gen a virtual disk.
137 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
138 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
139 # Make the Linux swap filesystem.
140 mkswap /home/swap
141 add_swap_in_fstab /home/swap
142 fi
143 else
144 echo "Unable to find $DEVICE... "
145 fi
147 # Move all user dir if needed.
148 if [ ! -d "/home/$USER" ] ; then
149 mv /tmp/$USER-files /home/$USER
150 chown -R $USER.users /home/$USER
151 else
152 rm -rf /tmp/$USER-files
153 fi
155 # Install all packages in /home/boot/packages. In live CD and
156 # USB mode the option home= mounts the device on /home, so we
157 # already have a boot directory with the Kernel and rootfs.
158 if [ -d '/home/boot/packages' ]; then
159 for pkg in /home/boot/packages/*.tazpkg; do
160 tazpkg install $pkg
161 done
162 fi
164 # We can have custom files in /home/boot/rootfs to overwrite
165 # the one packed into the Live system.
166 if [ -d '/home/boot/rootfs' ]; then
167 cp -a /home/boot/rootfs/* /
168 fi ;;
169 laptop)
170 # Enable Kernel Laptop mode.
171 echo '5' > /proc/sys/vm/laptop_mode ;;
172 mount)
173 # Mount all ext3 partitions found (opt: mount).
175 # Get the list of partitions.
176 DEVICES_LIST=$(fdisk -l | sed '/83 Linux/!d;s/ .*//')
178 # Mount filesystems rw.
179 for device in $DEVICES_LIST; do
180 name=${device#/dev/}
181 # Device can be already used by home=usb.
182 if ! mount | grep ^$device >/dev/null; then
183 echo "Mounting partition: $name on /mnt/$name"
184 mkdir -p /mnt/$name
185 mount $device /mnt/$name
186 fi
187 done ;;
188 mount-packages)
189 # Mount and install packages-XXX.iso (useful without Internet
190 # connection).
191 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
192 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
193 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
194 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
195 if [ -n "$PKGDEV" ]; then
196 action 'Mounting packages archive from %s...' "$PKGDEV"
197 mkdir -p /packages; mount -t iso9660 -o ro $PKGDEV /packages
198 status
199 /packages/install.sh
200 fi ;;
201 wm=*)
202 # Check for a Window Manager (for a flavor, default WM can be changed
203 # with boot options or via /etc/slitaz/applications.conf).
204 WM=${opt#wm=}
205 case $WM in
206 ob|openbox|openbox-session)
207 WM=openbox-session ;;
208 e17|enlightenment|enlightenment_start)
209 WM=enlightenment ;;
210 razorqt|razor-session)
211 WM=razor-session ;;
212 esac
213 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
214 /etc/slitaz/applications.conf ;;
215 *)
216 continue ;;
217 esac
218 done
219 if [ ! -s /etc/keymap.conf ]; then
220 [ -z "$KEYMAP" ] && tazkeymap
221 [ -z "$LANG" ] && tazlocale
222 fi > /dev/tty1