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

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