]> git.pld-linux.org Git - projects/geninitrd.git/commitdiff
- nfs modularized
authorElan Ruusamäe <glen@pld-linux.org>
Thu, 2 Apr 2009 23:13:00 +0000 (23:13 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Thu, 2 Apr 2009 23:13:00 +0000 (23:13 +0000)
svn-id: @10294

Makefile
geninitrd
mod-nfs.sh [new file with mode: 0644]

index 3d8b2786ba538703c8525f5eaaf389b68280fd90..11809b1f370f8eef18c13b50c632f4ac75756c08 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 # when making release, make sure you do it as RELEASE document describes
 VERSION                := 10000.3
-MODS           := ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb
+MODS           := ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs
 FILES_MODS  := $(MODS:%=mod-%.sh)
 FILES          := Makefile geninitrd.sysconfig geninitrd functions $(FILES_MODS) geninitrd.8 geninitrd.8.xml ChangeLog
 prefix         := /usr
index b810f0f2edf63708143372374fa51a629ca05f2d..77022dfdb07e5160664f1eac2159fb6b0d9f43c3 100755 (executable)
--- a/geninitrd
+++ b/geninitrd
@@ -45,9 +45,6 @@ tmp_mounted=no
 # are /dev nodes already created from /proc/devices info?
 proc_partitions=no
 
-# if we should init NFS at boot
-have_nfs=no
-
 usage() {
        uname_r=$(uname -r)
        echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
@@ -480,26 +477,8 @@ find_modules_for_devpath() {
                return
        fi
 
-       if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
-               if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
-                       die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
-               fi
-               if [ ! -f /proc/bus/pci/devices ]; then
-                       warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
-                       warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
-               else
-                       local m
-                       [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
-                       warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
-                       for m in $NFS_ETH_MODULES; do
-                               find_module "$m"
-                       done
-               fi
-               find_module "-ipv4"
-               find_module "nfs"
-               have_nfs=yes
-               warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
-               warn "or you will have problems like init(xx) being child process of swapper(1)."
+       if is_nfs "$devpath"; then
+               find_modules_nfs "$devpath"
                return
        fi
 
@@ -709,55 +688,6 @@ initrd_gen_devices() {
        EOF
 }
 
-initrd_gen_nfs() {
-       # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
-       # have problems like init(XX) being child process of swapper(1).
-       debug "Adding rootfs on NFS support to initrd (dhcp)"
-       mknod "$DESTDIR/dev/urandom" c 1 9
-       mkdir "$DESTDIR/newroot"
-       add_linuxrc <<-'EOF'
-               ifconfig lo 127.0.0.1 up
-               route add -net 127.0.0.0 mask 255.0.0.0 lo
-               ifconfig eth0 up
-               udhcpc -i eth0 -f -q -s /bin/setdhcp
-
-               cd /newroot
-               pivot_root . initrd
-               [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
-               exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
-       EOF
-
-       cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
-               #!/bin/sh
-               [ "$1" != "bound" ] && exit
-               [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
-               [ -n "$subnet" ] && NETMASK="netmask $subnet"
-               ifconfig $interface $ip $BROADCAST $NETMASK up
-               if [ -n "$router" ]; then
-                       for r in $router; do
-                               route add default gw $r dev $interface
-                       done
-               fi
-
-               for o in $CMDLINE; do
-                       case $o in
-                       nfsroot=*)
-                               rootpath=${o#nfsroot=}
-                               ;;
-                       esac
-               done
-
-               if [ -n "$rootpath" ]; then
-                       mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
-               else
-                       echo "Missing rootpath in what DHCP server sent to us. Failing..."
-                       echo "All seen variables are listed below:"
-                       set
-               fi
-       EOF
-
-       chmod 755 "$DESTDIR/bin/setdhcp"
-}
 
 initrd_gen_setrootdev() {
        debug "Adding rootfs finding based on kernel cmdline root= option support."
@@ -860,7 +790,7 @@ if [ -r /etc/sysconfig/geninitrd ]; then
        . /etc/sysconfig/geninitrd
 fi
 
-geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb
+geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs
 
 while [ $# -gt 0 ]; do
        case $1 in
diff --git a/mod-nfs.sh b/mod-nfs.sh
new file mode 100644 (file)
index 0000000..73804c6
--- /dev/null
@@ -0,0 +1,99 @@
+#!/bin/sh
+#
+# geninitrd mod: nfs
+
+# if we should init NFS at boot
+have_nfs=no
+
+# return true if node is nfs
+# @param       string $node device node to be examined
+# @access      public
+is_nfs() {
+       local node="$1"
+
+       if is_yes "`echo "$node" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
+               return 1
+       fi
+
+       return 0
+}
+
+# find modules for for nfs
+# @access      public
+find_modules_nfs() {
+       local devpath="$1"
+
+       if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
+               die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
+       fi
+
+       if [ ! -f /proc/bus/pci/devices ]; then
+               warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
+               warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
+       else
+               local m
+               [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
+               warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
+               for m in $NFS_ETH_MODULES; do
+                       find_module "$m"
+               done
+       fi
+       find_module "-ipv4"
+       find_module "nfs"
+
+       have_nfs=yes
+       warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
+       warn "or you will have problems like init(xx) being child process of swapper(1)."
+}
+
+# generate initrd fragment
+# @access      public
+initrd_gen_nfs() {
+       # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
+       # have problems like init(XX) being child process of swapper(1).
+       debug "Adding rootfs on NFS support to initrd (dhcp)"
+       mknod "$DESTDIR/dev/urandom" c 1 9
+       mkdir "$DESTDIR/newroot"
+       add_linuxrc <<-'EOF'
+               ifconfig lo 127.0.0.1 up
+               route add -net 127.0.0.0 mask 255.0.0.0 lo
+               ifconfig eth0 up
+               udhcpc -i eth0 -f -q -s /bin/setdhcp
+
+               cd /newroot
+               pivot_root . initrd
+               [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
+               exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
+       EOF
+
+       cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
+               #!/bin/sh
+               [ "$1" != "bound" ] && exit
+               [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
+               [ -n "$subnet" ] && NETMASK="netmask $subnet"
+               ifconfig $interface $ip $BROADCAST $NETMASK up
+               if [ -n "$router" ]; then
+                       for r in $router; do
+                               route add default gw $r dev $interface
+                       done
+               fi
+
+               for o in $CMDLINE; do
+                       case $o in
+                       nfsroot=*)
+                               rootpath=${o#nfsroot=}
+                               ;;
+                       esac
+               done
+
+               if [ -n "$rootpath" ]; then
+                       mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
+               else
+                       echo "Missing rootpath in what DHCP server sent to us. Failing..."
+                       echo "All seen variables are listed below:"
+                       set
+               fi
+       EOF
+
+       chmod 755 "$DESTDIR/bin/setdhcp"
+}
This page took 0.166957 seconds and 4 git commands to generate.