]> git.pld-linux.org Git - projects/geninitrd.git/blame - mod-nfs.sh
- swsusp support from mis@pld-linux
[projects/geninitrd.git] / mod-nfs.sh
CommitLineData
74d45ce1 1#!/bin/sh
74d45ce1
ER
2# geninitrd mod: nfs
3
4# if we should init NFS at boot
5have_nfs=no
6
7# return true if node is nfs
8# @param string $node device node to be examined
9# @access public
10is_nfs() {
11 local node="$1"
12
864391c7
ER
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
74d45ce1
ER
15 fi
16
864391c7 17 return 1
74d45ce1
ER
18}
19
20# find modules for for nfs
21# @access public
22find_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)
864391c7 35 msg "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
74d45ce1
ER
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
50initrd_gen_nfs() {
1b481849
ER
51 if ! is_yes "$have_nfs"; then
52 return
53 fi
54
74d45ce1
ER
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).
02ba8ab7 57 verbose "Adding rootfs on NFS support to initrd (dhcp)"
6b45dd6c 58 mknod -m 644 "$DESTDIR/dev/urandom" c 1 9
74d45ce1
ER
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
74d45ce1
ER
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
736620da 83 if [ -n "$hostname" ]; then
d14a228d 84 hostname $hostname
85 fi
86
74d45ce1
ER
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.654366 seconds and 4 git commands to generate.