diff --git a/Dockerfile b/Dockerfile index 373f0dd..3c7f887 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,8 @@ RUN pacman -Sy --noconfirm \ ntp \ openssh \ vim \ - wget + wget \ + networkmanager # Locales @@ -38,6 +39,7 @@ RUN systemctl enable sshd.service \ # Patch rootfs RUN wget -qO - http://j.mp/ocs-scripts | bash ADD ./patches/etc/ /etc/ +ADD ./patches/usr/ /usr/ # packages upgrade diff --git a/patches/usr/lib/systemd/system/systemd-reboot.service b/patches/usr/lib/systemd/system/systemd-reboot.service new file mode 100644 index 0000000..5240993 --- /dev/null +++ b/patches/usr/lib/systemd/system/systemd-reboot.service @@ -0,0 +1,10 @@ +[Unit] +Description=Reboot +Documentation=man:systemd-halt.service(8) +DefaultDependencies=no +Requires=shutdown.target umount.target final.target +After=shutdown.target umount.target final.target + +[Service] +Type=oneshot +ExecStart=/usr/sbin/oc-nbd-disconnect-root diff --git a/patches/usr/sbin/oc-add-extra-volumes b/patches/usr/sbin/oc-add-extra-volumes new file mode 100755 index 0000000..81055dd --- /dev/null +++ b/patches/usr/sbin/oc-add-extra-volumes @@ -0,0 +1,36 @@ +#!/bin/bash + +METADATA_CACHE=`mktemp -u` + +get_metadata() { + if [ ! -f $METADATA_CACHE ]; then + /usr/local/bin/oc-metadata > $METADATA_CACHE + fi +} + +get_value() { + # Get value from metadata + key="$1" + grep "^$key=" "$METADATA_CACHE" | cut -d= -f2 | sed "s/^['\"]//;s/['\"]$//" +} + +add_volumes() { + keys=$(get_value VOLUMES) + for key in $keys + do + test $key -eq 0 && continue + host=$(get_value VOLUMES_${key}_EXPORT_URI | sed 's|nbd://\(.*\):.*|\1|') + port=$(get_value VOLUMES_${key}_EXPORT_URI | sed 's|nbd://.*:\(.*\)|\1|') + device=/dev/nbd$key + xnbd-client -c $device && continue + for i in {1..3} + do + xnbd-client --connect $device $host $port --blocksize 4096 && break + sleep 5 + done + done +} + +get_metadata +add_volumes +rm $METADATA_CACHE diff --git a/patches/usr/sbin/oc-nbd-disconnect-root b/patches/usr/sbin/oc-nbd-disconnect-root new file mode 100755 index 0000000..579ea69 --- /dev/null +++ b/patches/usr/sbin/oc-nbd-disconnect-root @@ -0,0 +1,15 @@ +#!/bin/sh +# Thanks to the LTSP project +# If the root /dev/nbd0 device is unmounted on reboot then nbd read +# errors occur, and if it isn't, then # the nbd-server process on the server +# doesn't terminate. +# Called by init scripts on reboot. + +NBD_CLIENT=/usr/local/sbin/xnbd-client + +disconnect() { + $NBD_CLIENT -d "/dev/nbd0" + echo b > /proc/sysrq-trigger +} + +disconnect diff --git a/patches/usr/sbin/oc-remove-extra-volumes b/patches/usr/sbin/oc-remove-extra-volumes new file mode 100755 index 0000000..84d5edc --- /dev/null +++ b/patches/usr/sbin/oc-remove-extra-volumes @@ -0,0 +1,45 @@ +#!/bin/bash + +ROOT_DEVICE="/dev/nbd0" + +umount_nbd_devices() { + for device in $(mount | cut -d " " -f 1 | grep /dev/nbd) + do + test $device = $ROOT_DEVICE && continue + umount $device 2>/dev/null + if [ $? -eq 1 ] + then + echo -n "umount of $device failed! Data loss may occur! will continue in 10 seconds..." + sleep 1 + for i in 9 8 7 6 5 4 3 2 1 + do + echo -n $i" " + sleep 1 + done + echo "ok, going on..." + fi + done +} + +swapoff_nbd_devices() { + for device in $(grep '^/dev/nb' /proc/swaps | cut -d ' ' -f1) + do + swapoff $device 2> /dev/null + done + +} + +disconnect_devices() { + for device in $(ls /dev/nbd*) + do + test $device = $ROOT_DEVICE && continue + if xnbd-client -c $device 2> /dev/null + then + xnbd-client -d $device + fi + done +} + +umount_nbd_devices +swapoff_nbd_devices +disconnect_devices \ No newline at end of file