]> git.pld-linux.org Git - projects/geninitrd.git/blob - mod-nfs.sh
Report RCSID for loaded modules, too.
[projects/geninitrd.git] / mod-nfs.sh
1 #!/bin/sh
2 RCSID='$Revision: 12159 $ $Date: 2011-02-17 23:16:30 +0100 (czw) $'
3
4 # geninitrd mod: nfs
5
6 # if we should init NFS at boot
7 have_nfs=no
8
9 # return true if node is nfs
10 # @param        string $node device node to be examined
11 # @access       public
12 is_nfs() {
13         local node="$1"
14
15         if is_yes "$(awk -vnode="$node" 'BEGIN { if (node ~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/) print "yes" }')"; then
16                 return 0
17         fi
18
19         return 1
20 }
21
22 # find modules for for nfs
23 # @access       public
24 find_modules_nfs() {
25         local devpath="$1"
26
27         if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
28                 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
29         fi
30
31         if [ ! -f /proc/bus/pci/devices ]; then
32                 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
33                 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
34         else
35                 local m
36                 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
37                 msg "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
38                 for m in $NFS_ETH_MODULES; do
39                         find_module "$m"
40                 done
41         fi
42         find_module "-ipv4"
43         find_module "nfs"
44
45         have_nfs=yes
46         warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
47         warn "or you will have problems like init(xx) being child process of swapper(1)."
48 }
49
50 # generate initrd fragment
51 # @access       public
52 initrd_gen_nfs() {
53         if ! is_yes "$have_nfs"; then
54                 return
55         fi
56
57         # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
58         # have problems like init(XX) being child process of swapper(1).
59         debug "Adding rootfs on NFS support to initrd (dhcp)"
60         mknod "$DESTDIR/dev/urandom" c 1 9
61         mkdir "$DESTDIR/newroot"
62         add_linuxrc <<-'EOF'
63                 ifconfig lo 127.0.0.1 up
64                 route add -net 127.0.0.0 mask 255.0.0.0 lo
65                 ifconfig eth0 up
66                 udhcpc -i eth0 -f -q -s /bin/setdhcp
67
68                 cd /newroot
69                 pivot_root . initrd
70                 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
71         EOF
72
73         cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
74                 #!/bin/sh
75                 [ "$1" != "bound" ] && exit
76                 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
77                 [ -n "$subnet" ] && NETMASK="netmask $subnet"
78                 ifconfig $interface $ip $BROADCAST $NETMASK up
79                 if [ -n "$router" ]; then
80                         for r in $router; do
81                                 route add default gw $r dev $interface
82                         done
83                 fi
84
85                 if [ -n "$hostname" ]; then
86                         hostname $hostname
87                 fi
88
89                 for o in $CMDLINE; do
90                         case $o in
91                         nfsroot=*)
92                                 rootpath=${o#nfsroot=}
93                                 ;;
94                         esac
95                 done
96
97                 if [ -n "$rootpath" ]; then
98                         mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
99                 else
100                         echo "Missing rootpath in what DHCP server sent to us. Failing..."
101                         echo "All seen variables are listed below:"
102                         set
103                 fi
104         EOF
105
106         chmod 755 "$DESTDIR/bin/setdhcp"
107 }
This page took 0.042897 seconds and 4 git commands to generate.