From ca9c1938ca136ebd5f341f9fb01b822905f41906 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Fri, 28 Oct 2016 15:31:31 +0200 Subject: mkinitfs: add nbd support this also introduces default behaviour for networking calling configure_ip without setting ip defaults to dhcp --- Makefile | 4 +++- features.d/nbd.files | 1 + features.d/nbd.modules | 1 + features.d/network.modules | 2 ++ initramfs-init.in | 38 +++++++++++++++++++++++++++++--------- 5 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 features.d/nbd.files create mode 100644 features.d/nbd.modules diff --git a/Makefile b/Makefile index b599b01..124cf0a 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,9 @@ CONF_FILES := mkinitfs.conf \ features.d/ubifs.modules \ features.d/usb.modules \ features.d/virtio.modules \ - features.d/xfs.modules + features.d/xfs.modules \ + features.d/nbd.files \ + features.d/nbd.modules SCRIPTS := mkinitfs bootchartd initramfs-init IN_FILES := $(addsuffix .in,$(SCRIPTS)) diff --git a/features.d/nbd.files b/features.d/nbd.files new file mode 100644 index 0000000..3796750 --- /dev/null +++ b/features.d/nbd.files @@ -0,0 +1 @@ +/usr/sbin/nbd-client diff --git a/features.d/nbd.modules b/features.d/nbd.modules new file mode 100644 index 0000000..0b0ca75 --- /dev/null +++ b/features.d/nbd.modules @@ -0,0 +1 @@ +kernel/drivers/block/nbd.ko diff --git a/features.d/network.modules b/features.d/network.modules index 8397498..311df0b 100644 --- a/features.d/network.modules +++ b/features.d/network.modules @@ -1,2 +1,4 @@ kernel/drivers/net/ethernet kernel/net/packet/af_packet.ko +kernel/drivers/net/hyperv +kernel/drivers/net/vmxnet3 diff --git a/initramfs-init.in b/initramfs-init.in index 1a1adab..78bcbe4 100755 --- a/initramfs-init.in +++ b/initramfs-init.in @@ -167,14 +167,15 @@ ip_set() { # ip=client-ip:server-ip:gw-ip:netmask:hostname:device:autoconf # ip=dhcp # "server-ip" and "hostname" are not supported here. +# Default (when configure_ip is called without setting ip=): +# ip=dhcp # configure_ip() { - [ -z "$KOPT_ip" -o "$MAC_ADDRESS" ] && return - OIFS=$IFS - IFS=':' - eval set -- $KOPT_ip - IFS=$OIFS - + [ -n "$MAC_ADDRESS" ] && return + local ops=${KOPT_ip:-dhcp} + local IFS=':' + set -- $ops + unset IFS local client_ip="$1" local gw_ip="$3" local netmask="$4" @@ -190,13 +191,12 @@ configure_ip() { echo "ERROR: IP requested but no network device was found" return 1 fi - if [ "$autoconf" = "dhcp" ]; then + # automatic configuration if [ ! -e /usr/share/udhcpc/default.script ]; then echo "ERROR: DHCP requested but not present in initrd" return 1 fi - # automatic configuration ebegin "Obtaining IP via DHCP ($device)..." ifconfig $device 0.0.0.0 udhcpc -i $device -f -q @@ -241,6 +241,21 @@ find_boot_repositories() { fi } +setup_nbd() { + modprobe -q nbd max_part=8 || return 1 + local IFS=, n=0 + set -- $KOPT_nbd + unset IFS + for ops; do + local server="${ops%:*}" + local port="${ops#*:}" + local device="/dev/nbd${n}" + [ -b "$device" ] || continue + nbd-client "$server" "$port" "$device" && n=$((n+1)) + done + [ "$n" != 0 ] || return 1 +} + # read the kernel options. we need surve things like: # acpi_osi="!Windows 2006" xen-pciback.hide=(01:00.0) set -- $(cat /proc/cmdline) @@ -248,7 +263,7 @@ set -- $(cat /proc/cmdline) myopts="alpine_dev autodetect autoraid chart cryptroot cryptdm debug_init dma init_args keep_apk_new modules ovl_dev pkgs quiet root_size root usbdelay ip alpine_repo apkovl alpine_start splash blacklist - overlaytmpfs rootfstype rootflags" + overlaytmpfs rootfstype rootflags nbd" for opt; do case "$opt" in @@ -343,6 +358,11 @@ if [ -n "$KOPT_cryptroot" ]; then fi fi +if [ -n "$KOPT_nbd" ]; then + configure_ip + setup_nbd || echo "Failed to setup nbd device." +fi + # check if root=... was set if [ -n "$KOPT_root" ]; then if [ "$SINGLEMODE" = "yes" ]; then -- cgit v1.2.3