[arch-releng] [PATCH 2/2] [archiso] Add PXE NFS support

Gerardo Exequiel Pozzi vmlinuz386 at yahoo.com.ar
Tue Nov 22 00:47:35 EST 2011


It add support for using *.sfs images via NFS.

It must be located after archiso_pxe_nbd in mkinitcpio.conf, in that way
NBD is the default.

New boot parameters:

    archiso_nfs_srv=IP:/path
         Set the NFS IP and path. Accepts ${pxeserver} as IP.

    archiso_nfs_opt= Sets NFS mount opts (comma separated)
                    Defaults to:
                      port            = as given by server portmap daemon
                      rsize           = 1024
                      wsize           = 1024
                      timeo           = 7
                      retrans         = 3
                      acregmin        = 3
                      acregmax        = 60
                      acdirmin        = 30
                      acdirmax        = 60
                      flags           = hard, nointr, noposix, cto, ac

:: Running Hook [archiso_pxe_common]
IP-Config: eth0 hardware address 52:54:00:12:34:57 mtu 1500
IP-Config: eth0 guessed broadcast address 192.168.0.255
IP-Config: eth0 guessed nameserver address 192.168.0.218
IP-Config: eth0 complete (from 192.168.0.218):
 address: 192.168.0.90     broadcast: 192.168.0.255    netmask: 255.255.255.0
 gateway: 192.168.0.218    dns0     : 192.168.0.218    dns1   : 0.0.0.0
 rootserver: 192.168.0.218 rootpath:
 filename  :
:: Running Hook [archiso_pxe_nbd]
:: Running Hook [archiso_pxe_curl]
:: Running Hook [archiso_pxe_nfs]
:: Mounting '192.168.0.77:/mnt/iso'

...
192.168.0.77:/mnt/iso/ on /run/archiso/bootmnt type nfs (rw,relatime,vers=3,rsize=524288,wsize=524288,namlen=255,hard,nolock,proto=tcp,port=65535,timeo=7,retrans=3,sec=sys,local_lock=all,addr=192.168.0.77)
...

My /etc/exports
/mnt/iso 192.168.0.90(ro,no_subtree_check,no_root_squash)
---
 README                          |   22 ++++++++++++++++++++++
 archiso/Makefile                |    4 ++++
 archiso/hooks/archiso_pxe_nfs   |   26 ++++++++++++++++++++++++++
 archiso/install/archiso_pxe_nfs |   14 ++++++++++++++
 configs/releng/build.sh         |    2 +-
 configs/releng/mkinitcpio.conf  |    2 +-
 6 files changed, 68 insertions(+), 2 deletions(-)
 create mode 100644 archiso/hooks/archiso_pxe_nfs
 create mode 100644 archiso/install/archiso_pxe_nfs

diff --git a/README b/README
index 70aaf9e..dbaf0cd 100644
--- a/README
+++ b/README
@@ -90,6 +90,26 @@ INDEX
                     Default: (unset)
 
 
+** hooks/archiso_pxe_nfs
+
+* archiso_nfs_srv=  Set the NFS-IP:/path of the server
+                    In the IP part if ${pxeserver} is used, PXE IP will be used.
+                    Default: (unset)
+* archiso_nfs_opt=  Set NFS mount options separated by comma.
+                    Default: (unset, see below)
+                    These are the implicit options:
+                      port            = as given by server portmap daemon
+                      rsize           = 1024
+                      wsize           = 1024
+                      timeo           = 7
+                      retrans         = 3
+                      acregmin        = 3
+                      acregmax        = 60
+                      acdirmin        = 30
+                      acdirmax        = 60
+                      flags           = hard, nointr, noposix, cto, ac
+
+
 ** hooks/archiso_loop_mnt
 
 * img_label=        Set the filesystem label where archiso-image.iso.
@@ -137,6 +157,8 @@ if nothing is specified on command line.
  + nbd                     for nbd-client
 * archiso_pxe_curl
  + curl                    for curl
+* archiso_pxe_nfs
+ + mkinitcpio-nfs-utils    for nfsmount
 * archiso_shutdown
  + (none)
 
diff --git a/archiso/Makefile b/archiso/Makefile
index 0dbbbf8..11aff53 100644
--- a/archiso/Makefile
+++ b/archiso/Makefile
@@ -22,6 +22,8 @@ install-hooks:
 	install -D -m 644 install/archiso_pxe_nbd $(DESTDIR)/lib/initcpio/install/archiso_pxe_nbd
 	install -D -m 644 hooks/archiso_pxe_curl $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_curl
 	install -D -m 644 install/archiso_pxe_curl $(DESTDIR)/lib/initcpio/install/archiso_pxe_curl
+	install -D -m 644 hooks/archiso_pxe_nfs $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_nfs
+	install -D -m 644 install/archiso_pxe_nfs $(DESTDIR)/lib/initcpio/install/archiso_pxe_nfs
 	install -D -m 644 hooks/archiso_loop_mnt $(DESTDIR)/lib/initcpio/hooks/archiso_loop_mnt
 	install -D -m 644 install/archiso_loop_mnt $(DESTDIR)/lib/initcpio/install/archiso_loop_mnt
 
@@ -49,6 +51,8 @@ uninstall:
 	rm -f $(DESTDIR)/lib/initcpio/install/archiso_pxe_nbd
 	rm -f $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_curl
 	rm -f $(DESTDIR)/lib/initcpio/install/archiso_pxe_curl
+	rm -f $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_nfs
+	rm -f $(DESTDIR)/lib/initcpio/install/archiso_pxe_nfs
 	rm -f $(DESTDIR)/lib/initcpio/hooks/archiso_loop_mnt
 	rm -f $(DESTDIR)/lib/initcpio/install/archiso_loop_mnt
 	rm -rf $(DESTDIR)/usr/share/archiso/
diff --git a/archiso/hooks/archiso_pxe_nfs b/archiso/hooks/archiso_pxe_nfs
new file mode 100644
index 0000000..a053672
--- /dev/null
+++ b/archiso/hooks/archiso_pxe_nfs
@@ -0,0 +1,26 @@
+# vim: set ft=sh:
+
+run_hook() {
+    if [[ -n "${ip}" && -n "${archiso_nfs_srv}" ]]; then
+
+        archiso_nfs_srv=$(eval echo ${archiso_nfs_srv})
+        [[ -n "${archiso_nfs_opt}" ]] && archiso_nfs_opt="-o ${archiso_nfs_opt}"
+
+        mount_handler="archiso_nfs_mount_handler"
+    fi
+}
+
+archiso_nfs_mount_handler() {
+    newroot="${1}"
+    mkdir -p "/run/archiso/bootmnt"
+    msg ":: Mounting '${archiso_nfs_srv}'"
+    # Do not put "${archiso_nfs_opt}" nfsmount fails!
+    if ! nfsmount ${archiso_nfs_opt} "${archiso_nfs_srv}" "/run/archiso/bootmnt"; then
+        echo "ERROR: Mounting '${archiso_nfs_srv}'"
+        echo "   Falling back to interactive prompt"
+        echo "   You can try to fix the problem manually, log out when you are finished"
+        launch_interactive_shell
+    fi
+
+    archiso_mount_handler ${newroot}
+}
diff --git a/archiso/install/archiso_pxe_nfs b/archiso/install/archiso_pxe_nfs
new file mode 100644
index 0000000..52be9f3
--- /dev/null
+++ b/archiso/install/archiso_pxe_nfs
@@ -0,0 +1,14 @@
+# vim: set ft=sh:
+
+build() {
+    MODULES="nfs"
+    SCRIPT="archiso_pxe_nfs"
+
+    add_binary "/lib/initcpio/nfsmount" "/bin/nfsmount"
+}
+
+help() {
+    cat <<HELPEOF
+  This hook loads the necessary modules for boot via PXE and NFS.
+HELPEOF
+}
diff --git a/configs/releng/build.sh b/configs/releng/build.sh
index 101a56f..8240740 100755
--- a/configs/releng/build.sh
+++ b/configs/releng/build.sh
@@ -43,7 +43,7 @@ make_customize_root_image() {
 make_setup_mkinitcpio() {
    if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
         local _hook
-        for _hook in archiso archiso_shutdown archiso_pxe_common archiso_pxe_nbd archiso_pxe_curl archiso_loop_mnt; do
+        for _hook in archiso archiso_shutdown archiso_pxe_common archiso_pxe_nbd archiso_pxe_curl archiso_pxe_nfs archiso_loop_mnt; do
             cp /lib/initcpio/hooks/${_hook} ${work_dir}/root-image/lib/initcpio/hooks
             cp /lib/initcpio/install/${_hook} ${work_dir}/root-image/lib/initcpio/install
         done
diff --git a/configs/releng/mkinitcpio.conf b/configs/releng/mkinitcpio.conf
index 6387982..8d77dee 100644
--- a/configs/releng/mkinitcpio.conf
+++ b/configs/releng/mkinitcpio.conf
@@ -1,2 +1,2 @@
-HOOKS="base udev memdisk archiso_shutdown archiso archiso_loop_mnt archiso_pxe_common archiso_pxe_nbd archiso_pxe_curl pata scsi sata virtio usb fw pcmcia filesystems usbinput"
+HOOKS="base udev memdisk archiso_shutdown archiso archiso_loop_mnt archiso_pxe_common archiso_pxe_nbd archiso_pxe_curl archiso_pxe_nfs pata scsi sata virtio usb fw pcmcia filesystems usbinput"
 COMPRESSION="xz"
-- 
1.7.7.3



More information about the arch-releng mailing list