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