X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=meta-netboot%2Frecipes-core%2Finitramfs-netboot%2Ffiles%2Finit.sh;h=87a1acb80834b7af75ede872ba90053e9be02cd5;hb=c05762b781b5fb7b4f6139ea1a6d5a9b9d72de7a;hp=81c2c79a488d8fbc8145af51df5e2a58a0fb5111;hpb=d96d6bdc5399ab257e482248682c6d90dac7d9ae;p=AGL%2Fmeta-agl.git diff --git a/meta-netboot/recipes-core/initramfs-netboot/files/init.sh b/meta-netboot/recipes-core/initramfs-netboot/files/init.sh index 81c2c79a4..87a1acb80 100644 --- a/meta-netboot/recipes-core/initramfs-netboot/files/init.sh +++ b/meta-netboot/recipes-core/initramfs-netboot/files/init.sh @@ -21,10 +21,10 @@ EOF # global variables -SMACK=n NBD_SERVER= NBD_PORT=10809 NBD_DEV=/dev/nbd0 +NBD_NAMEV3= DEBUG=n # ------------------------------------------- @@ -56,6 +56,29 @@ check_debug() { esac } +find_active_interface() { + [[ ! -d /sys/class/net ]] && { log_error "find_active_interface: /sys/class/net doesn't exist"; return 2; } + local iface + for x in $(ls -d /sys/class/net/* 2>/dev/null); do + iface=$(basename $x) + # find interfaces with: + # - type == 1 (ethernet) + # - not wireless + # - with state up + + [[ $(cat $x/type) != 1 ]] && continue + [[ -d $x/wireless ]] && continue + [[ $(cat $x/operstate) != "up" ]] && continue + + log_info "find_active_interface: first active interface is $iface" + echo $iface + return 0 + done + + log_error "Unable to find any active network interface." + return 1 +} + # ------------------------------------------- export PATH=/sbin:/usr/sbin:/bin:/usr/bin @@ -76,6 +99,7 @@ for x in $(cat /proc/cmdline); do nbd.server=*) NBD_SERVER=${x/*=/};; nbd.port=*) NBD_PORT=${x/*=/};; nbd.dev=*) NBD_DEV=/dev/${x/*=/};; + nbd.namev3=*) NBD_NAMEV3=${x/*=/};; nbd.debug=*) DEBUG=${x/*=/};; esac done @@ -84,23 +108,17 @@ check_debug "Debug point 1. Exit to continue initrd script (mount NBD device)." log_info "NBD parameters: device $NBD_DEV, server $NBD_SERVER:$NBD_PORT" -# check if smack is active (and if so, mount smackfs) -grep -q smackfs /proc/filesystems && { - SMACK=y - - do_mount_fs smackfs /sys/fs/smackfs - - # adjust current label and network label - echo System >/proc/self/attr/current - echo System >/sys/fs/smackfs/ambient -} - # start nbd client try=5 while :;do log_info "Starting NBD client" - nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV && { log_info "NBD client successfully started"; break; } - log_info "NBD client failed" + if [ -z "${NBD_NAMEV3}" ]; then + nbd-client -persist $NBD_SERVER $NBD_PORT $NBD_DEV && { log_info "NBD client successfully started"; break; } + log_info "NBD client failed" + else + nbd3-client $NBD_SERVER $NBD_DEV --name $NBD_NAMEV3 && { log_info "NBD3 client successfully started"; break; } + log_info "NBDv3 client failed" + fi [[ $try -gt 0 ]] && { log_info "Retrying ($try trie(s) left)..."; sleep 3; try=$(( try - 1 )); continue; } bail_out "Unable to mount NBD device $NBD_DEV using server $NBD_SERVER:$NBD_PORT" @@ -119,16 +137,44 @@ done # switch to new rootfs log_info "Switching to new rootfs" -mkdir -p run/initramfs -pivot_root . run/initramfs || bail_out "pivot_root failed." +mkdir -p boot/initramfs +pivot_root . boot/initramfs || bail_out "pivot_root failed." -# workaround for connman (avoid bringing down the network interface used for booting) +# workaround for connman (avoid bringing down the network interface used for booting, disable DNS proxy) if [[ -f /lib/systemd/system/connman.service ]]; then - log_info "Adjusting Connman configuration" - iface=$(ip -o link show up | tr ':' ' ' | awk '{print $2}' | grep -v -e "^lo$" | head -1) - sed -i "s|connmand -n\$|connmand -n -I $iface|g" /lib/systemd/system/connman.service + newopts="-r -n" + iface=$(find_active_interface) + [[ -n "$iface" ]] && newopts="$newopts -I $iface" + + log_info "Adjusting Connman command line. Will be: 'connmand $newopts'" + sed -i "s|connmand -n\$|connmand $newopts|g" /lib/systemd/system/connman.service fi +# also use /proc/net/pnp to generate /etc/resolv.conf +rm -f /etc/resolv.conf +grep -v bootserver /proc/net/pnp | sed 's/^domain/search/g' >/etc/resolv.conf + +# Do SELinux relabeling if required, to avoid a reboot that would complicate CI +if [ -f /.autorelabel ]; then + # Nothing SELinux related works w/o the fs mounted + do_mount_fs selinuxfs /sys/fs/selinux + + # Labeling requires the policy to be loaded + log_info "Loading SELinux policy" + /usr/sbin/load_policy + + /usr/bin/selinux-autorelabel.sh + + # Will get remounted by systemd startup, unmount to keep that behavior + # more like the non-netboot case. + umount /sys/fs/selinux +fi + +# unmount tmp and run to let systemd remount them +log_info "Unmounting /tmp and /run" +umount /tmp +umount /run + # finally, run systemd check_debug "Debug point 2. Exit to continue initrd script (run systemd)."