slitaz-boot-scripts annotate etc/init.d/bootopts.sh @ rev 375

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