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