diff --git a/srcpkgs/mkinitcpio-nfs-utils/files/initcpio-hook-net b/srcpkgs/mkinitcpio-nfs-utils/files/initcpio-hook-net new file mode 100644 index 00000000000..4d1ebb95605 --- /dev/null +++ b/srcpkgs/mkinitcpio-nfs-utils/files/initcpio-hook-net @@ -0,0 +1,90 @@ +# vim: set ft=sh: +run_hook() { + local line i net_mac bootif_mac bootif_dev defaultrootpath defaultserver + # These variables will be parsed from /tmp/net-*.conf generated by ipconfig + local DEVICE + local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1 + local HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH + local filename + # /tmp/net-*.conf + + if [ -z "${ip}" -a -n "${nfsaddrs}" ]; then + ip="${nfsaddrs}" + fi + + if [ -n "${ip}" ]; then + if [ -n "${BOOTIF}" ]; then + bootif_mac=${BOOTIF#01-} + bootif_mac=${bootif_mac//-/:} + for i in /sys/class/net/*/address; do + read net_mac < ${i} + if [ "${bootif_mac}" == "${net_mac}" ]; then + bootif_dev=${i#/sys/class/net/} + bootif_dev=${bootif_dev%/address} + break + fi + done + ip="${ip}::${bootif_dev}" + fi + + # setup network and save some values + ipconfig "ip=${ip}" + + for conf in /tmp/net-*.conf; do + [ -f "$conf" ] && . "$conf" + done + + # calculate nfs_server, nfs_path and nfs_option for later nfs mount + if [ "${root}" = "/dev/nfs" -o "${nfsroot}" != "" ]; then + # parse ROOTPATH if defined by dhcp server + if [ -n "${ROOTPATH}" ]; then + line="${ROOTPATH}" + nfs_server="${line%%:*}" + [ "${nfs_server}" = "${line}" ] && nfs_server="${ROOTSERVER}" + defaultserver="${nfs_server}" + line="${line#*:}" + nfs_path="${line}" + defaultrootpath="${nfs_path}" + else + # define a default ROOTPATH + if [ "${ROOTPATH}" = "" ]; then + defaultrootpath="/tftpboot/${IPV4ADDR}" + fi + fi + + # parse nfsroot if present (overrides ROOTPATH) + if [ -n "${nfsroot}" ]; then + line="${nfsroot}" + nfs_server="${line%%:*}" + [ -z "${nfs_server}" ] && nfs_server="${defaultserver}" + line="${line#*:}" + nfs_path="${line%%,*}" + line="${line#"${nfs_path}"}" + [ -z "${nfs_path}" ] && nfs_path="${defaultrootpath}" + nfs_option="${line#","}" + fi + + # ensure root and filesystem type are set proper for nfs boot + root="/dev/nfs" + rootfstype="nfs" + + echo "NFS-Mount: ${nfs_server}:${nfs_path}" + + # set mount handler for NFS + mount_handler="nfs_mount_handler" + fi + fi +} + +nfs_mount_handler() { + if [ -z "$nfs_server" -o -z "$nfs_path" ]; then + err "Unable to mount root filesystem over NFS: wrong parameters." + echo "You are being dropped to a recovery shell" + echo " Type 'exit' to try and continue booting" + launch_interactive_shell + msg "Trying to continue (this will most likely fail) ..." + fi + nfsmount ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" "$1" +} + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/srcpkgs/mkinitcpio-nfs-utils/files/initcpio-install-net b/srcpkgs/mkinitcpio-nfs-utils/files/initcpio-install-net new file mode 100644 index 00000000000..79b678949c9 --- /dev/null +++ b/srcpkgs/mkinitcpio-nfs-utils/files/initcpio-install-net @@ -0,0 +1,108 @@ +#!/bin/bash + +build() { + add_checked_modules '/drivers/net/' + add_module nfsv3? + + add_binary "/usr/lib/initcpio/ipconfig" "/bin/ipconfig" + add_binary "/usr/lib/initcpio/nfsmount" "/bin/nfsmount" + + add_runscript +} + +help() { + cat <:::::: +nfsaddrs= is an alias to ip= and can be used too. + + IP address of the client. If empty, the address will + either be determined by RARP/BOOTP/DHCP. What protocol + is used de- pends on the parameter. If this + parameter is not empty, autoconf will be used. + + IP address of the NFS server. If RARP is used to + determine the client address and this parameter is NOT + empty only replies from the specified server are + accepted. To use different RARP and NFS server, + specify your RARP server here (or leave it blank), and + specify your NFS server in the 'nfsroot' parameter + (see above). If this entry is blank the address of the + server is used which answered the RARP/BOOTP/DHCP + request. + + IP address of a gateway if the server is on a different + subnet. If this entry is empty no gateway is used and the + server is assumed to be on the local network, unless a + value has been received by BOOTP/DHCP. + + Netmask for local network interface. If this is empty, + the netmask is derived from the client IP address assuming + classful addressing, unless overridden in BOOTP/DHCP reply. + + Name of the client. If empty, the client IP address is + used in ASCII notation, or the value received by + BOOTP/DHCP. + + Name of network device to use. If this is empty, all + devices are used for RARP/BOOTP/DHCP requests, and the + first one we receive a reply on is configured. If you + have only one device, you can safely leave this blank. + + Method to use for autoconfiguration. If this is either + 'rarp', 'bootp', or 'dhcp' the specified protocol is + used. If the value is 'both', 'all' or empty, all + protocols are used. 'off', 'static' or 'none' means + no autoconfiguration. +Examples: +ip=127.0.0.1:::::lo:none --> Enable the loopback interface. +ip=192.168.1.1:::::eth2:none --> Enable static eth2 interface. +ip=:::::eth0:dhcp --> Enable dhcp protcol for eth0 configuration. + +nfsroot=[:][,] + +If the 'nfsroot' parameter is NOT given on the command line, the default +"/tftpboot/%s" will be used. + + Specifies the IP address of the NFS server. If this field + is not given, the default address as determined by the + 'ip' variable (see below) is used. One use of this + parameter is for example to allow using different servers + for RARP and NFS. Usually you can leave this blank. + + Name of the directory on the server to mount as root. If + there is a "%s" token in the string, the token will be + replaced by the ASCII-representation of the client's IP + address. + + Standard NFS options. All options are separated by commas. + If the options field is not given, the following defaults + will be used: + 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 + +root=/dev/nfs + +If you don't use nfsroot= parameter you need to set root=/dev/nfs +to boot from a nfs root by autoconfiguration. +HELPEOF +} + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/srcpkgs/mkinitcpio-nfs-utils/patches/musl.patch b/srcpkgs/mkinitcpio-nfs-utils/patches/musl.patch new file mode 100644 index 00000000000..fa822cb0523 --- /dev/null +++ b/srcpkgs/mkinitcpio-nfs-utils/patches/musl.patch @@ -0,0 +1,83 @@ +From 9e6dd28c7b2d9649cc3fc3ea9effadcb29d233c5 Mon Sep 17 00:00:00 2001 +From: Andrea Brancaleoni +Date: Thu, 25 Jun 2015 18:01:23 +0200 +Subject: [PATCH] musl + +--- + ipconfig/packet.c | 27 +++++++++++++-------------- + 1 file changed, 13 insertions(+), 14 deletions(-) + +diff --git a/ipconfig/packet.c b/ipconfig/packet.c +index 446073a..afedf9d 100644 +--- a/ipconfig/packet.c ++++ b/ipconfig/packet.c +@@ -7,10 +7,9 @@ + #include + #include + #include +-#include ++#include + #include + #include +-#include + #include + #include + #include +@@ -92,10 +91,10 @@ static struct header ipudp_hdrs = { + .daddr = INADDR_BROADCAST, + }, + .udp = { +- .source = __constant_htons(LOCAL_PORT), +- .dest = __constant_htons(REMOTE_PORT), +- .len = 0, +- .check = 0, ++ .uh_sport = __constant_htons(LOCAL_PORT), ++ .uh_dport = __constant_htons(REMOTE_PORT), ++ .uh_ulen = 0, ++ .uh_sum = 0, + }, + }; + +@@ -127,8 +126,8 @@ int packet_send(struct netdev *dev, struct iovec *iov, int iov_len) + msg.msg_flags = 0; + + if (cfg_local_port != LOCAL_PORT) { +- ipudp_hdrs.udp.source = htons(cfg_local_port); +- ipudp_hdrs.udp.dest = htons(cfg_remote_port); ++ ipudp_hdrs.udp.uh_sport = htons(cfg_local_port); ++ ipudp_hdrs.udp.uh_dport = htons(cfg_remote_port); + } + + dprintf("\n udp src %d dst %d", ntohs(ipudp_hdrs.udp.source), +@@ -159,7 +158,7 @@ int packet_send(struct netdev *dev, struct iovec *iov, int iov_len) + ipudp_hdrs.ip.check = ip_checksum((uint16_t *) &ipudp_hdrs.ip, + ipudp_hdrs.ip.ihl); + +- ipudp_hdrs.udp.len = htons(len - sizeof(struct iphdr)); ++ ipudp_hdrs.udp.uh_ulen = htons(len - sizeof(struct iphdr)); + + dprintf("\n bytes %d\n", len); + +@@ -243,14 +242,14 @@ int packet_recv(struct netdev *dev, struct iovec *iov, int iov_len) + + ret -= 4 * ip->ihl; + +- dprintf("\n udp src %d dst %d ", ntohs(udp->source), +- ntohs(udp->dest)); ++ dprintf("\n udp src %d dst %d ", ntohs(udp->uh_sport), ++ ntohs(udp->uh_dport)); + +- if (udp->source != htons(cfg_remote_port) || +- udp->dest != htons(cfg_local_port)) ++ if (udp->uh_sport != htons(cfg_remote_port) || ++ udp->uh_dport != htons(cfg_local_port)) + goto free_pkt; + +- if (ntohs(udp->len) > ret) ++ if (ntohs(udp->uh_ulen) > ret) + goto free_pkt; + + ret -= sizeof(struct udphdr); +-- +2.4.4 + diff --git a/srcpkgs/mkinitcpio-nfs-utils/patches/nfsmount-fix-wrong-umount-path.patch b/srcpkgs/mkinitcpio-nfs-utils/patches/nfsmount-fix-wrong-umount-path.patch new file mode 100644 index 00000000000..0f62fea823c --- /dev/null +++ b/srcpkgs/mkinitcpio-nfs-utils/patches/nfsmount-fix-wrong-umount-path.patch @@ -0,0 +1,14 @@ +--- a/nfsmount/mount.c 2012-11-10 20:16:31.894540497 -0500 ++++ b/nfsmount/mount.c 2012-11-10 20:16:39.957369011 -0500 +@@ -358,9 +358,9 @@ + bail: + if (mounted) { + if (data->flags & NFS_MOUNT_VER3) { +- umount_v3(path, clnt); ++ umount_v3(rem_path, clnt); + } else { +- umount_v2(path, clnt); ++ umount_v2(rem_path, clnt); + } + } + diff --git a/srcpkgs/mkinitcpio-nfs-utils/template b/srcpkgs/mkinitcpio-nfs-utils/template new file mode 100644 index 00000000000..68c55ff2273 --- /dev/null +++ b/srcpkgs/mkinitcpio-nfs-utils/template @@ -0,0 +1,35 @@ +# Template file for 'mkinitcpio-nfs-utils' +pkgname=mkinitcpio-nfs-utils +version=0.3 +revision=1 +build_style=gnu-makefile +short_desc="Ipconfig and nfsmount tools for NFS root support in mkinitcpio" +maintainer="Andrea Brancaleoni " +license="GPL-2" +homepage="http://www.archlinux.org/" +depends="mkinitcpio" +distfiles="https://sources.archlinux.org/other/mkinitcpio/$pkgname-$version.tar.xz" +checksum=d290d489844fae100ca7b848b8eef40078124ff373203086bacc07329d1e8939 + +case "$XBPS_TARGET_MACHINE" in +*-musl) + CFLAGS="-DSYS_NMLN=65" + # http://osxr.org/glibc/source/sysdeps/unix/sysv/linux/bits/utsname.h?v=glibc-2.15; fixes musl not having set this variable + ;; +esac + +patch_args="-Np1" + +pre_configure() { + case "$XBPS_TARGET_MACHINE" in + *-musl) + sed -i 's|PROGRAMS = ipconfig nfsmount|PROGRAMS = ipconfig|g' Makefile + # No RPC in musl for now + ;; + esac +} + +post_install() { + vinstall ${FILESDIR}/initcpio-install-net 644 usr/lib/initcpio/install net + vinstall ${FILESDIR}/initcpio-hook-net 644 usr/lib/initcpio/hooks net +}