wok rev 15527

busybox-root: fix root=device|UUID|LABEL cmdline
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Nov 21 11:34:23 2013 +0000 (2013-11-21)
parents d36394ef35a1
children 8ae289524b6b
files busybox-boot/receipt
line diff
     1.1 --- a/busybox-boot/receipt	Wed Nov 20 16:06:44 2013 +0000
     1.2 +++ b/busybox-boot/receipt	Thu Nov 21 11:34:23 2013 +0000
     1.3 @@ -25,6 +25,9 @@
     1.4  	done
     1.5  	cp -a $src/busybox-$CHOICE $fs/usr/share/boot/bin/busybox
     1.6  	chmod 4755 $fs/usr/share/boot/bin/busybox
     1.7 +	for i in sed mount mknod mkdir sh cp ln ; do
     1.8 +		ln $fs/usr/share/boot/bin/busybox $fs/usr/share/boot/bin/$i
     1.9 +	done
    1.10  	mknod -m 660 $fs/usr/share/boot/dev/console c 5 1
    1.11  	mknod -m 771 $fs/usr/share/boot/dev/null c 1 3
    1.12  	mknod -m 660 $fs/usr/share/boot/dev/tty c 5 0
    1.13 @@ -34,15 +37,24 @@
    1.14  		mknod -m 660 $fs/usr/share/boot/dev/ttyS0 c 4 64
    1.15  	fi
    1.16  	cat > $fs/usr/share/boot/init <<EOT
    1.17 -#!/bin/busybox sh
    1.18 -
    1.19 -for i in \$(busybox --list) ; do busybox ln /bin/busybox /bin/\$i; done
    1.20 +#!/bin/sh
    1.21  
    1.22  export PATH=/bin
    1.23  export HOME=/
    1.24  export TERM=vt100
    1.25  
    1.26 -mkdir /tmp /mnt /proc
    1.27 +if [ -n "\$1" ]; then
    1.28 +	[ -n "\$broadcast" ] && BROADCAST="broadcast \$broadcast"
    1.29 +	[ -n "\$subnet" ] && NETMASK="netmask \$subnet"
    1.30 +	ifconfig \$interface \${ip:-0.0.0.0} \$BROADCAST \$NETMASK
    1.31 +	while route del default gw 0.0.0.0 dev \$interface ; do : ; done
    1.32 +	for i in \$router ; do route add default gw \$i dev \$interface; done
    1.33 +	[ -n "\$domain" ] && echo search \$domain > /etc/resolv.conf
    1.34 +	for i in \$dns ; do echo nameserver \$i; done >> /etc/resolv.conf
    1.35 +	exit 0
    1.36 +fi
    1.37 +
    1.38 +mkdir /tmp /mnt /proc /etc
    1.39  mount -t proc none /proc
    1.40  while read name major minor ; do
    1.41  	for i in '' 1 2 3 4 5 6 7 8 9 ; do
    1.42 @@ -58,14 +70,20 @@
    1.43  
    1.44  arg()
    1.45  {
    1.46 -grep -q \$1= /proc/cmdline && root="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" </proc/cmdline)"
    1.47 +root="\$(sed "s/^/ /;s/\$/ /;/ \$1=/!d;s/.* \$1=\\([^ ]*\\).*/\\1/" </proc/cmdline)"
    1.48 +busybox [ -n "\$root" ]
    1.49  }
    1.50  
    1.51 -arg mount && mount \$root /mnt
    1.52 -arg loopfs && losetup /dev/loop /mnt/\$root && mount /dev/loop /mnt
    1.53 +arg init
    1.54 +init=\${root:-/sbin/init}
    1.55 +arg root && root="\$(echo \$root | sed 's|/|\\\\/|g')" &&
    1.56 +	mount \$(busybox blkid | sed "s/\"//g;/\$root/!d;s/:.*//;q") /mnt
    1.57 +arg loopfs && busybox losetup /dev/loop /mnt/\$root && mount /dev/loop /mnt
    1.58  arg subroot && cp /bin/busybox /mnt/\$root/dev/shm &&
    1.59 -exec switch_root mnt \$root/dev/shm/busybox chroot \$root /sbin/init
    1.60 -arg loopfs && exec switch_root mnt /sbin/init
    1.61 +	chroot="\$root/dev/shm/busybox chroot \$root"
    1.62 +busybox [ -x /mnt/\$root\$init ] && exec busybox switch_root mnt \$chroot \$init
    1.63 +
    1.64 +for i in \$(busybox --list) ; do busybox ln /bin/busybox /bin/\$i; done
    1.65  
    1.66  [ -d /proc/bus/usb ] && mount -t usbfs usbfs /proc/bus/usb
    1.67  while read type dir ; do
    1.68 @@ -82,6 +100,7 @@
    1.69  	$jslinux && echo 'stty -F $TTY rows 30 2>/dev/null' >> $fs/usr/share/boot/init
    1.70  	cat >> $fs/usr/share/boot/init <<EOT
    1.71  
    1.72 +[ -x /bin/udhcpc ] && udhcpc -b -s /init
    1.73  while true; do
    1.74  	busybox | sed '/Current/,\$!d'
    1.75  	if [ -x /bin/setsid ]; then