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

init: mount 'SliTaz persistent /home' partition
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 10 14:11:26 2022 +0000 (2022-01-10)
parents a53219934611
children
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\"*|*\"exfat\"*)
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
144 fs=/home/boot/rootfs.gz
145 [ -s $fs ] && ( zcat $fs || unlzma < $fs || cat $fs ) | ( cd / ; cpio -idmu )
146 else
147 echo "Unable to find $DEVICE... "
148 fi
150 # Move all user dir if needed.
151 if [ ! -d "/home/$USER" ] ; then
152 mv /tmp/$USER-files /home/$USER
153 chown -R $USER.users /home/$USER
154 else
155 rm -rf /tmp/$USER-files
156 fi
158 # Install all packages in /home/boot/packages. In live CD and
159 # USB mode the option home= mounts the device on /home, so we
160 # already have a boot directory with the Kernel and rootfs.
161 if [ -d '/home/boot/packages' ]; then
162 for pkg in /home/boot/packages/*.tazpkg; do
163 tazpkg install $pkg
164 done
165 fi
167 # We can have custom files in /home/boot/rootfs to overwrite
168 # the one packed into the Live system.
169 if [ -d '/home/boot/rootfs' ]; then
170 cp -a /home/boot/rootfs/* /
171 fi ;;
172 laptop)
173 # Enable Kernel Laptop mode.
174 echo '5' > /proc/sys/vm/laptop_mode ;;
175 mount)
176 # Mount all ext3 partitions found (opt: mount).
178 # Get the list of partitions.
179 DEVICES_LIST=$(fdisk -l | sed '/83 Linux/!d;s/ .*//')
181 # Mount filesystems rw.
182 for device in $DEVICES_LIST; do
183 name=${device#/dev/}
184 # Device can be already used by home=usb.
185 if ! mount | grep ^$device >/dev/null; then
186 echo "Mounting partition: $name on /mnt/$name"
187 mkdir -p /mnt/$name
188 mount $device /mnt/$name
189 fi
190 done ;;
191 mount-packages)
192 # Mount and install packages-XXX.iso (useful without Internet
193 # connection).
194 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
195 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
196 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
197 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
198 if [ -n "$PKGDEV" ]; then
199 action 'Mounting packages archive from %s...' "$PKGDEV"
200 mkdir -p /packages; mount -t iso9660 -o ro $PKGDEV /packages
201 status
202 /packages/install.sh
203 fi ;;
204 wm=*)
205 # Check for a Window Manager (for a flavor, default WM can be changed
206 # with boot options or via /etc/slitaz/applications.conf).
207 WM=${opt#wm=}
208 case $WM in
209 ob|openbox|openbox-session)
210 WM=openbox-session ;;
211 e17|enlightenment|enlightenment_start)
212 WM=enlightenment ;;
213 razorqt|razor-session)
214 WM=razor-session ;;
215 esac
216 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
217 /etc/slitaz/applications.conf ;;
218 *)
219 continue ;;
220 esac
221 done
222 if [ ! -s /etc/keymap.conf ]; then
223 [ -z "$KEYMAP" ] && tazkeymap
224 [ -z "$LANG" ] && tazlocale
225 fi > /dev/tty1