From: Michael Tremer Date: Tue, 17 Feb 2009 22:54:35 +0000 (+0100) Subject: Added some nice things on mkinitramfs. X-Git-Tag: v3.0-alpha1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16d10a88e03ed63198632eeddedff7604bcae983;p=ipfire-3.x.git Added some nice things on mkinitramfs. --- diff --git a/src/mkinitramfs/functions b/src/mkinitramfs/functions index ec8705ede..21e60f826 100644 --- a/src/mkinitramfs/functions +++ b/src/mkinitramfs/functions @@ -490,9 +490,10 @@ mkdir -p bin sbin dev sys proc sysroot \ etc/udev/rules.d lib/udev/rules.d # Install some essential binaries -install bash chmod cat cut dd dmesg env grep kbd_mode kill killall5 ln ls lsmod mkdir \ - mknod modprobe mount mountpoint openvt pidof ps rm sed setfont sh sleep switchroot \ - udevadm udevd umount /lib/udev/console_init /lib/udev/vol_id +install bash chmod cat cut dd dmesg env grep head ip kbd_mode kill killall5 less ln \ + ls lsmod mkdir mknod modprobe mount mountpoint openvt pidof ps rm sed \ + setfont sh sleep switchroot udevadm udevd umount \ + /lib/udev/console_init /lib/udev/vol_id # Copy modprobe.conf and friends over [ -e /etc/modprobe.conf ] && install /etc/modprobe.conf diff --git a/src/mkinitramfs/mkinitramfs b/src/mkinitramfs/mkinitramfs index f71d32de1..abc5cd3e0 100644 --- a/src/mkinitramfs/mkinitramfs +++ b/src/mkinitramfs/mkinitramfs @@ -30,7 +30,7 @@ rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/fstab) rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/fstab) [ -z "$rootopts" ] && rootopts="defaults" -MODULES="$MODULES $rootfs" # Add rootfs module +installmodule --load $rootfs if [[ "$rootdev" =~ "^(UUID=|LABEL=)" ]]; then rootdev=$(resolve_device_name "$rootdev") @@ -53,6 +53,13 @@ fi findstoragedriver ${rootdev##/dev/} +cat >> sbin/real-init <> sbin/real-init <<'EOF' # Users can override rootfs target on the kernel commandline @@ -77,7 +84,9 @@ vecho "Creating devices..." udevadm trigger vecho "Mounting root filesystem $rootdev..." -mount $rootdev /sysroot $rootfs $rootopts +[ -n "$rootopts" ] && rootopts="-o $rootopts" +[ -n "$rootfstype" ] && rootopts="-t $rootfstype $rootopts" +mount $rootdev /sysroot $rootopts kill $(pidof udevd) diff --git a/src/mkinitramfs/mkliveramfs b/src/mkinitramfs/mkliveramfs index f0863fcbe..3fe887381 100644 --- a/src/mkinitramfs/mkliveramfs +++ b/src/mkinitramfs/mkliveramfs @@ -35,12 +35,15 @@ for module in /lib/modules/$KERNEL/kernel/drivers/{ata,message/fusion,pcmcia,scs MODULES="$MODULES $(basename ${module/.ko})" done -install dhclient +install arping dhclient dhclient-script ping # Creating folders mkdir -p mnt/{source,tmpfs,overlayfs,squashfs} cat >> sbin/real-init <<'EOF' + +netdevice=eth0 + # Users can override rootfs target on the kernel commandline for o in $(cat /proc/cmdline); do case $o in @@ -53,6 +56,18 @@ for o in $(cat /proc/cmdline); do rootfstype=*) rootfstype=${o#rootfstype=} ;; + net=*) + net=${o#net=} + ;; + netdevice=*) + netdevice=${o#netdevice=} + ;; + gateway=*) + gateway=${o#gateway=} + ;; + dns=*) + dns="$dns ${o#dns=}" + ;; esac done @@ -109,6 +124,13 @@ else fi thingtomount=/dev/root ;; + NFS=*) + NFS=${root#NFS=} + vecho "Going on to mount $NFS" + #mount -t nfs $NFS /mnt/source + #rootfstype=loop + #thingtomount=$(ls -1 /mnt/source/*.iso | head -n 1) + ;; /dev/*) ln -s $root /dev/root thingtomount=$root @@ -140,18 +162,53 @@ udevd --daemon vecho "Creating devices..." udevadm trigger +if [ -n "$net" ]; then + # Wait 30 seconds for network to appear. + COUNTDOWN=30 + while [ "x$COUNTDOWN" != "x0" ] ; do + is_verbose && echo -n "." + + if ip link show $netdevice &>/dev/null; then + COUNTDOWN=0 + continue + fi + + COUNTDOWN=$(($COUNTDOWN - 1)) + sleep 1 + done + vecho # Blank line + + ip link set $netdevice up + if [ "$net" = "dhcp" ]; then + vecho "Getting an IP address by DHCP..." + dhclient $(get_verbose) $netdevice + else + vecho "Setting IP address $net..." + ip addr add $net dev $netdevice + fi + if [ -n "$gateway" ]; then + vecho "Setting default gateway $gateway..." + ip route add default via $gateway + fi + if ! ping -c3 -w10 ping.ipfire.org 2>/dev/null; then + echo "This box does not seem to have an internet connection." + echo "You may fix this now and continue then:" + bash + fi +fi + if [ "$SHELL" == "1" ] ; then echo "Shell requested on kernel commandline. Exit to continue booting." echo bash fi -# Wait 60 seconds for /dev/root to appear. +# Wait 90 seconds for $thingtomount to appear. COUNTDOWN=90 while [ "x$COUNTDOWN" != "x0" ] ; do is_verbose && echo -n "." - if [ -e /dev/root ]; then + if [ -e $thingtomount ]; then COUNTDOWN=0 continue fi @@ -167,21 +224,21 @@ while [ "x$COUNTDOWN" != "x0" ] ; do done vecho # Blank line -if [ ! -b /dev/root ] ; then +if [ ! -e $thingtomount ] ; then echo echo "--------------------------------------" echo "WARNING: Cannot find root file system!" echo "--------------------------------------" echo - echo "Create symlink /dev/root and then exit this shell to continue" + echo "Create symlink $thingtomount and then exit this shell to continue" echo "the boot sequence." echo bash fi if is_verbose; then - vecho "Mounting /dev/root..." - ls -l /dev/root + vecho "Mounting $thingtomount..." + ls -l $thingtomount fi if [ "x$READONLY" == "x1" ] ; then