Browse Source

mkinitcpio-nfs-utils: add new package

tags/milky-way/v0.3
André Silva 1 year ago
parent
commit
8626118e2d
5 changed files with 314 additions and 0 deletions
  1. +48
    -0
      mkinitcpio-nfs-utils/PKGBUILD
  2. +90
    -0
      mkinitcpio-nfs-utils/initcpio-hook-net
  3. +108
    -0
      mkinitcpio-nfs-utils/initcpio-install-net
  4. +54
    -0
      mkinitcpio-nfs-utils/make-mkinitcpio-nfs-utils-fhs-compliant.patch
  5. +14
    -0
      mkinitcpio-nfs-utils/nfsmount-fix-wrong-umount-path.patch

+ 48
- 0
mkinitcpio-nfs-utils/PKGBUILD View File

@@ -0,0 +1,48 @@
# Maintainer: Thomas Bächler <thomas@archlinux.org>
# Maintainer: André Silva <emulatorman@hyperbola.info>

pkgname=mkinitcpio-nfs-utils
pkgver=0.3
pkgrel=5.hyperbola1
pkgdesc="ipconfig and nfsmount tools for NFS root support in mkinitcpio"
arch=('i686' 'x86_64')
url="https://www.archlinux.org/"
license=('GPL-2')
depends=('glibc')
source=("https://sources.archlinux.org/other/mkinitcpio/$pkgname-$pkgver.tar.xz"
'nfsmount-fix-wrong-umount-path.patch'
'initcpio-install-net'
'initcpio-hook-net'
'make-mkinitcpio-nfs-utils-fhs-compliant.patch')
sha512sums=('f867c1ee7dc193c666fe2147c4a168bd1bed4d2547cd00f32e4a119e18656f0bc20fe76798cbe4a4270e8292820d45528113f8bba392a42df25c26909c353b43'
'f6d3e6b2eebe4b1ff8ba45343cc1e9c63ab315512da0bfd254679b0713c45716fb0dcecfbbe8a5f73b9f0f95e6e1ab8dcf59d91ddcd5d8bc9b5dbe610b174a04'
'3015a27d5bbedab08d20dfbe012cd7091f4cc492109f4f1acae97bd3af0724440c225668c5bf1906e7277465c05cd795e9fd8303ef461c6c640eb990562a2a3c'
'ab776d79f7955e2a6d177f8e2cce870536c0d90ab500d1476c22571fdd8705012208a5e002f7db8ff74b6f9c13fe80c73e3dd83e260e38592670d8a33bae5114'
'2b91560c84b33058be90e179444042f94d0fc38ba6fbf88adfca97f30d49af735a4324980990d4cfa93e7ea7610f72786babb9029be6f1d71b47a7c6c2037885')

prepare() {
cd "$pkgname-$pkgver"

# upstream commit 029622dfbfe25203275a385a5bf33d44c2409b00
patch -Np1 < "$srcdir/nfsmount-fix-wrong-umount-path.patch"

# make mkinitcpio-nfs-utils FHS compliant
patch -p1 -i "$srcdir/make-mkinitcpio-nfs-utils-fhs-compliant.patch"
}

build() {
cd "$pkgname-$pkgver"

make
}

package() {
make -C "$pkgname-$pkgver" DESTDIR="$pkgdir" install

# override hooks, they need updates
install -m644 "$srcdir/initcpio-install-net" "$pkgdir/lib/initcpio/install/net"
install -m644 "$srcdir/initcpio-hook-net" "$pkgdir/lib/initcpio/hooks/net"

# install license file
install -Dm644 "$pkgname-$pkgver/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

+ 90
- 0
mkinitcpio-nfs-utils/initcpio-hook-net View File

@@ -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:

+ 108
- 0
mkinitcpio-nfs-utils/initcpio-install-net View File

@@ -0,0 +1,108 @@
#!/bin/bash

build() {
add_checked_modules '/drivers/net/'
add_module nfsv3?

add_binary "/lib/initcpio/ipconfig" "/bin/ipconfig"
add_binary "/lib/initcpio/nfsmount" "/bin/nfsmount"

add_runscript
}

help() {
cat <<HELPEOF
This hook loads the necessary modules for a network device.
Detection will take place at runtime. To minimize the modules
in the image, add the autodetect hook too.
For pcmcia net devices please use pcmcia hook too.

Kernel Parameters:
An interface spec can be either short form, which is just the name of
an interface (eth0 or whatever), or long form. The long form consists
of up to seven elements, separated by colons:

ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>
nfsaddrs= is an alias to ip= and can be used too.

<client-ip> 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 <autoconf> parameter. If this
parameter is not empty, autoconf will be used.

<server-ip> 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.

<gw-ip> 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> 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.

<hostname> Name of the client. If empty, the client IP address is
used in ASCII notation, or the value received by
BOOTP/DHCP.

<device> 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.

<autoconf> 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=[<server-ip>:]<root-dir>[,<nfs-options>]

If the 'nfsroot' parameter is NOT given on the command line, the default
"/tftpboot/%s" will be used.

<server-ip> 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.

<root-dir> 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.

<nfs-options> 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:

+ 54
- 0
mkinitcpio-nfs-utils/make-mkinitcpio-nfs-utils-fhs-compliant.patch View File

@@ -0,0 +1,54 @@
diff --git a/Makefile b/Makefile
index 359a3dd..df6f0a5 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ CLEAN_PROGRAMS = $(addsuffix -clean, $(PROGRAMS))
INSTALL_PROGRAMS = $(addsuffix -install, $(PROGRAMS))
DESTDIR ?=
-prefix ?= /usr/lib/initcpio
+prefix ?= /lib/initcpio
bindir ?= $(prefix)
.PHONY: all
diff --git a/ipconfig/Makefile b/ipconfig/Makefile
index b199f8d..171346a 100644
--- a/ipconfig/Makefile
+++ b/ipconfig/Makefile
@@ -4,7 +4,7 @@ SOURCES = bootp_proto.c dhcp_proto.c main.c netdev.c packet.c
OBJECTS = $(subst .c,.o,$(SOURCES))
DESTDIR ?=
-prefix ?= /usr/lib/initcpio
+prefix ?= /lib/initcpio
bindir ?= $(prefix)
CFLAGS = -D_GNU_SOURCE -Wall -Os -fno-strict-aliasing
diff --git a/net_install b/net_install
index 277d003..88d0c97 100644
--- a/net_install
+++ b/net_install
@@ -4,8 +4,8 @@ build() {
MODULES="nfs $(checked_modules "/drivers/net/") "
SCRIPT="net"
- add_binary "/usr/lib/initcpio/ipconfig" "/bin/ipconfig"
- add_binary "/usr/lib/initcpio/nfsmount" "/bin/nfsmount"
+ add_binary "/lib/initcpio/ipconfig" "/bin/ipconfig"
+ add_binary "/lib/initcpio/nfsmount" "/bin/nfsmount"
}
help() {
diff --git a/nfsmount/Makefile b/nfsmount/Makefile
index f5d44e7..808d5d2 100644
--- a/nfsmount/Makefile
+++ b/nfsmount/Makefile
@@ -4,7 +4,7 @@ SOURCES = dummypmap.c main.c mount.c portmap.c sunrpc.c
OBJECTS = $(subst .c,.o,$(SOURCES))
DESTDIR ?=
-prefix ?= /usr/lib/initcpio
+prefix ?= /lib/initcpio
bindir ?= $(prefix)
CFLAGS = -D_GNU_SOURCE -Wall -Os

+ 14
- 0
mkinitcpio-nfs-utils/nfsmount-fix-wrong-umount-path.patch View File

@@ -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);
}
}

Loading…
Cancel
Save