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

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