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

bootopts.sh: look for usb key device
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Mar 23 10:48:07 2012 +0100 (2012-03-23)
parents 244e4aba431e
children 4e3f09beb648
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 -q 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 grep -qs batt /etc/lxpanel/default/panels/panel ||
152 sed -i 's/= cpu/= batt\n}\n\nPlugin {\n type = cpu/' \
153 /etc/lxpanel/default/panels/panel 2> /dev/null
154 # Enable Kernel Laptop mode.
155 echo "5" > /proc/sys/vm/laptop_mode ;;
156 mount)
157 # Mount all ext3 partitions found (opt: mount).
158 # Get the list of partitions.
159 DEVICES_LIST=`fdisk -l | sed '/83 Linux/!d;s/ .*//'`
160 # Mount filesystems rw.
161 for device in $DEVICES_LIST
162 do
163 name=${device#/dev/}
164 # Device can be already used by home=usb.
165 if ! mount | grep ^$device >/dev/null; then
166 echo "Mounting partition: $name on /mnt/$name"
167 mkdir /mnt/$name
168 mount $device /mnt/$name
169 fi
170 done ;;
171 mount-packages)
172 # Mount and install packages-XXX.iso (useful without Internet
173 # connection).
174 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
175 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
176 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
177 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
178 if [ -n "$PKGDEV" ]; then
179 echo -n "Mounting packages archive from $PKGDEV..."
180 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
181 status
182 /packages/install.sh
183 fi ;;
184 wm=*)
185 # Check for a Window Manager (for a flavor, default WM can be changed
186 # with boot options or with an addfile in /etc/X11/wm.default.
187 WM=${opt#wm=}
188 mkdir -p /etc/X11
189 case $WM in
190 jwm)
191 echo "jwm" > /etc/X11/wm.default ;;
192 ob|openbox|openbox-session)
193 echo "openbox" > /etc/X11/wm.default ;;
194 e17|enlightenment|enlightenment_start)
195 echo "enlightenment" > /etc/X11/wm.default ;;
196 esac ;;
197 *)
198 continue ;;
199 esac
200 done
202 # If no default WM fallback to Openbox (we never know).
203 if [ ! -f /etc/X11/wm.default ]; then
204 echo "openbox" > /etc/X11/wm.default
205 fi
207 # Activate an eventual swap file or partition.
208 if [ "`fdisk -l | grep swap`" ]; then
209 for SWAP_DEV in `fdisk -l | sed '/swap/!d;s/ .*//'`; do
210 echo "Swap memory detected on: $SWAP_DEV"
211 add_swap_in_fstab $SWAP_DEV
212 done
213 fi
214 if grep -q swap /etc/fstab; then
215 echo "Activating swap memory..."
216 swapon -a
217 fi