From 14dde32029e320b8d36ca4cd1ec2d9b114183a2e Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 28 May 2015 13:56:27 +0200 Subject: restructured 'builder' builds the initramfs with our dracut module 'packager' builds/packs the stage4 rootfs --- blacklists/README | 15 - blacklists/essential/fontcache | 3 - blacklists/essential/linux-base | 80 ---- blacklists/essential/linux-extended | 5 - blacklists/essential/other-files | 3 - blacklists/essential/policykit | 2 - blacklists/essential/temp-files | 5 - blacklists/essential/tm-scripts | 1 - blacklists/package-managers/apt | 2 - blacklists/package-managers/rpm | 5 - blacklists/package-managers/yast | 5 - blacklists/package-managers/yum | 1 - blacklists/package-managers/zypper | 2 - builder/INSTALL | 19 + builder/dnbd3-qcow2-rootfs/TODO | 5 + builder/dnbd3-qcow2-rootfs/binaries/busybox | Bin 0 -> 504912 bytes builder/dnbd3-qcow2-rootfs/binaries/dnbd3-client | Bin 0 -> 31150 bytes .../binaries/systemd-preserve-process-marker | Bin 0 -> 7728 bytes builder/dnbd3-qcow2-rootfs/debugging_tools/busybox | Bin 0 -> 931664 bytes builder/dnbd3-qcow2-rootfs/debugging_tools/endless | Bin 0 -> 6752 bytes .../dnbd3-qcow2-rootfs/debugging_tools/endless.c | 10 + .../dnbd3-qcow2-rootfs/debugging_tools/nbd-client | Bin 0 -> 59639 bytes .../debugging_tools/nbd-debugging.ko | Bin 0 -> 463248 bytes .../debugging_tools/network.functions | 23 + .../dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd | Bin 0 -> 7131314 bytes .../debugging_tools/qemu-nbd-systemd-mark | Bin 0 -> 7128103 bytes .../debugging_tools/setup-network.sh | 84 ++++ .../hooks/cmdline/enable-sysrq.sh | 2 + .../hooks/cmdline/expand-kcl-ip.sh | 36 ++ .../hooks/cmdline/mark-root-device.sh | 9 + .../hooks/mount/mount-root-device.sh | 4 + .../hooks/pre-mount/fetch-config.sh | 39 ++ .../hooks/pre-mount/mount-qcow.sh | 49 +++ .../hooks/pre-pivot/mount-tmp.sh | 40 ++ .../dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh | 1 + .../hooks/pre-udev/load-dnbd3-nbd-modules.sh | 32 ++ builder/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko | Bin 0 -> 1345285 bytes builder/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko | Bin 0 -> 463216 bytes builder/dnbd3-qcow2-rootfs/module-setup.sh | 121 ++++++ builder/dnbd3-qcow2-rootfs/readme.md | 472 +++++++++++++++++++++ builder/dnbd3-qcow2-rootfs/scripts/prepare-disks | 211 +++++++++ builder/dnbd3-qcow2-rootfs/scripts/setup-qcow2 | 137 ++++++ .../systemd-preserve-process-marker.c | 33 ++ .../dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules | 8 + dracut/INSTALL | 19 - dracut/dnbd3-qcow2-rootfs/TODO | 5 - dracut/dnbd3-qcow2-rootfs/binaries/busybox | Bin 504912 -> 0 bytes dracut/dnbd3-qcow2-rootfs/binaries/dnbd3-client | Bin 31150 -> 0 bytes .../binaries/systemd-preserve-process-marker | Bin 7728 -> 0 bytes dracut/dnbd3-qcow2-rootfs/debugging_tools/busybox | Bin 931664 -> 0 bytes dracut/dnbd3-qcow2-rootfs/debugging_tools/endless | Bin 6752 -> 0 bytes .../dnbd3-qcow2-rootfs/debugging_tools/endless.c | 10 - .../dnbd3-qcow2-rootfs/debugging_tools/nbd-client | Bin 59639 -> 0 bytes .../debugging_tools/nbd-debugging.ko | Bin 463248 -> 0 bytes .../debugging_tools/network.functions | 23 - dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd | Bin 7131314 -> 0 bytes .../debugging_tools/qemu-nbd-systemd-mark | Bin 7128103 -> 0 bytes .../debugging_tools/setup-network.sh | 84 ---- .../hooks/cmdline/enable-sysrq.sh | 2 - .../hooks/cmdline/expand-kcl-ip.sh | 36 -- .../hooks/cmdline/mark-root-device.sh | 9 - .../hooks/mount/mount-root-device.sh | 4 - .../hooks/pre-mount/fetch-config.sh | 39 -- .../hooks/pre-mount/mount-qcow.sh | 49 --- .../hooks/pre-pivot/mount-tmp.sh | 40 -- .../dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh | 1 - .../hooks/pre-udev/load-dnbd3-nbd-modules.sh | 32 -- dracut/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko | Bin 1345285 -> 0 bytes dracut/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko | Bin 463216 -> 0 bytes dracut/dnbd3-qcow2-rootfs/module-setup.sh | 121 ------ dracut/dnbd3-qcow2-rootfs/readme.md | 472 --------------------- dracut/dnbd3-qcow2-rootfs/scripts/prepare-disks | 211 --------- dracut/dnbd3-qcow2-rootfs/scripts/setup-qcow2 | 137 ------ .../systemd-preserve-process-marker.c | 33 -- .../dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules | 8 - mltk-ng | 66 --- mltk-ng.functions | 138 ------ packager/blacklists/README | 15 + packager/blacklists/essential/fontcache | 3 + packager/blacklists/essential/linux-base | 80 ++++ packager/blacklists/essential/linux-extended | 5 + packager/blacklists/essential/other-files | 3 + packager/blacklists/essential/policykit | 2 + packager/blacklists/essential/temp-files | 5 + packager/blacklists/essential/tm-scripts | 1 + packager/blacklists/package-managers/apt | 2 + packager/blacklists/package-managers/rpm | 5 + packager/blacklists/package-managers/yast | 5 + packager/blacklists/package-managers/yum | 1 + packager/blacklists/package-managers/zypper | 2 + packager/openslx | 68 +++ packager/openslx.functions | 138 ++++++ 92 files changed, 1670 insertions(+), 1668 deletions(-) delete mode 100644 blacklists/README delete mode 100644 blacklists/essential/fontcache delete mode 100644 blacklists/essential/linux-base delete mode 100644 blacklists/essential/linux-extended delete mode 100644 blacklists/essential/other-files delete mode 100644 blacklists/essential/policykit delete mode 100644 blacklists/essential/temp-files delete mode 100644 blacklists/essential/tm-scripts delete mode 100644 blacklists/package-managers/apt delete mode 100644 blacklists/package-managers/rpm delete mode 100644 blacklists/package-managers/yast delete mode 100644 blacklists/package-managers/yum delete mode 100644 blacklists/package-managers/zypper create mode 100644 builder/INSTALL create mode 100644 builder/dnbd3-qcow2-rootfs/TODO create mode 100755 builder/dnbd3-qcow2-rootfs/binaries/busybox create mode 100755 builder/dnbd3-qcow2-rootfs/binaries/dnbd3-client create mode 100755 builder/dnbd3-qcow2-rootfs/binaries/systemd-preserve-process-marker create mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/busybox create mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/endless create mode 100644 builder/dnbd3-qcow2-rootfs/debugging_tools/endless.c create mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-client create mode 100644 builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko create mode 100644 builder/dnbd3-qcow2-rootfs/debugging_tools/network.functions create mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd create mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark create mode 100644 builder/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/cmdline/enable-sysrq.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/cmdline/expand-kcl-ip.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/cmdline/mark-root-device.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/mount/mount-root-device.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/pre-mount/fetch-config.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/pre-mount/mount-qcow.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/pre-pivot/mount-tmp.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh create mode 100755 builder/dnbd3-qcow2-rootfs/hooks/pre-udev/load-dnbd3-nbd-modules.sh create mode 100755 builder/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko create mode 100644 builder/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko create mode 100644 builder/dnbd3-qcow2-rootfs/module-setup.sh create mode 100644 builder/dnbd3-qcow2-rootfs/readme.md create mode 100755 builder/dnbd3-qcow2-rootfs/scripts/prepare-disks create mode 100755 builder/dnbd3-qcow2-rootfs/scripts/setup-qcow2 create mode 100644 builder/dnbd3-qcow2-rootfs/systemd-preserve-process-marker.c create mode 100644 builder/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules delete mode 100644 dracut/INSTALL delete mode 100644 dracut/dnbd3-qcow2-rootfs/TODO delete mode 100755 dracut/dnbd3-qcow2-rootfs/binaries/busybox delete mode 100755 dracut/dnbd3-qcow2-rootfs/binaries/dnbd3-client delete mode 100755 dracut/dnbd3-qcow2-rootfs/binaries/systemd-preserve-process-marker delete mode 100755 dracut/dnbd3-qcow2-rootfs/debugging_tools/busybox delete mode 100755 dracut/dnbd3-qcow2-rootfs/debugging_tools/endless delete mode 100644 dracut/dnbd3-qcow2-rootfs/debugging_tools/endless.c delete mode 100755 dracut/dnbd3-qcow2-rootfs/debugging_tools/nbd-client delete mode 100644 dracut/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko delete mode 100644 dracut/dnbd3-qcow2-rootfs/debugging_tools/network.functions delete mode 100755 dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd delete mode 100755 dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark delete mode 100644 dracut/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/cmdline/enable-sysrq.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/cmdline/expand-kcl-ip.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/cmdline/mark-root-device.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/mount/mount-root-device.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/pre-mount/fetch-config.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/pre-mount/mount-qcow.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/pre-pivot/mount-tmp.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/hooks/pre-udev/load-dnbd3-nbd-modules.sh delete mode 100755 dracut/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko delete mode 100644 dracut/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko delete mode 100644 dracut/dnbd3-qcow2-rootfs/module-setup.sh delete mode 100644 dracut/dnbd3-qcow2-rootfs/readme.md delete mode 100755 dracut/dnbd3-qcow2-rootfs/scripts/prepare-disks delete mode 100755 dracut/dnbd3-qcow2-rootfs/scripts/setup-qcow2 delete mode 100644 dracut/dnbd3-qcow2-rootfs/systemd-preserve-process-marker.c delete mode 100644 dracut/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules delete mode 100755 mltk-ng delete mode 100755 mltk-ng.functions create mode 100644 packager/blacklists/README create mode 100644 packager/blacklists/essential/fontcache create mode 100644 packager/blacklists/essential/linux-base create mode 100644 packager/blacklists/essential/linux-extended create mode 100644 packager/blacklists/essential/other-files create mode 100644 packager/blacklists/essential/policykit create mode 100644 packager/blacklists/essential/temp-files create mode 100644 packager/blacklists/essential/tm-scripts create mode 100644 packager/blacklists/package-managers/apt create mode 100644 packager/blacklists/package-managers/rpm create mode 100644 packager/blacklists/package-managers/yast create mode 100644 packager/blacklists/package-managers/yum create mode 100644 packager/blacklists/package-managers/zypper create mode 100755 packager/openslx create mode 100755 packager/openslx.functions diff --git a/blacklists/README b/blacklists/README deleted file mode 100644 index ed3fe459..00000000 --- a/blacklists/README +++ /dev/null @@ -1,15 +0,0 @@ -This directory contains blacklists of files and directories that -should be excluded when cloning stage4 of a remote system. The -blacklists are split into groups, represented by sub-directories. -They contain one or more text files representing blacklists in rsync -"--exclude-from" format. - -There is a group called "essential", containg blacklists for essential -files and dirs that you always want to exclude from being cloned. -Other directories are create for specific software packages, like -gnome, or kde. - -For inclusion of desktop environments like Gnome or KDE a substructure -(subdirectory) called desktop-sessions was introduced. The files / -directories in there should describe only includes ("+ ....") to provide -files needed for a desktop environment. diff --git a/blacklists/essential/fontcache b/blacklists/essential/fontcache deleted file mode 100644 index 13d60d44..00000000 --- a/blacklists/essential/fontcache +++ /dev/null @@ -1,3 +0,0 @@ -+ /var/cache/fontconfig -+ /var/cache/fontconfig/* - diff --git a/blacklists/essential/linux-base b/blacklists/essential/linux-base deleted file mode 100644 index c3d023d7..00000000 --- a/blacklists/essential/linux-base +++ /dev/null @@ -1,80 +0,0 @@ -- /cdrom/* -- /dev/* -- /adm/* -- /afs/* -- /bfg/* -- /clustersw/* -- /cvmfs/* -- /gridsw/* -- /storage/* - -# This is where the bind-mount of mltk resides... -- /export/* -- /etc/*ppp* -- /etc/*pptp* -- /etc/dhcp* -- /etc/exports* -- /etc/fstab -#- /etc/group -- /etc/group- -- /etc/gshadow -- /etc/gshadow- -- /etc/hostname -- /etc/hosts -#- /etc/inputrc -- /etc/issue.net -# Always include ldconfig/cache of full system: -+ /etc/ld.so.** -#- /etc/localtime -#- /etc/login.defs -#- /etc/mtab -#- /etc/mtab.* -+ /etc/sysconfig/network-scripts/ifcfg-lo -- /etc/sysconfig/network-scripts/ifcfg-* -- /etc/networks -#- /etc/passwd -- /etc/passwd- -#- /etc/resolv.conf -#- /etc/resolvconf/ -#- /etc/shadow -- /etc/shadow- -#- /lib/modules/ -- /lost+found/ -- /media/* -- /mnt/* -- /opt/openslx -- /proc/* -- /run/* -#- /srv/ -- /sys/* -- /tmp/* -#- /usr/src/ -+ /var/backup/**/ -- /var/backup/** -+ /var/cache/**/ -- /var/cache/** -+ /var/crash/**/ -- /var/crash/** -+ /var/empty/**/ -- /var/empty/** -+ /var/lock/**/ -- /var/lock/** -+ /var/log/**/ -- /var/log/** -+ /var/mail/**/ -- /var/mail/** -#+ /var/spool/**/ -#- /var/spool/** -+ /var/spool/torque/* -- /var/tmp/* -- /var/lib/nova/instances/* -- /var/lib/libvirt - - - -## Interfering binaries/links -#- /sbin/shutdown -#- /sbin/reboot -#- /sbin/poweroff -#- /sbin/halt -##- /bin/sh diff --git a/blacklists/essential/linux-extended b/blacklists/essential/linux-extended deleted file mode 100644 index 3d81000a..00000000 --- a/blacklists/essential/linux-extended +++ /dev/null @@ -1,5 +0,0 @@ -- /home/* -- /root/* -+ /root/.bash* -+ /root/.ssh -- /etc/cups diff --git a/blacklists/essential/other-files b/blacklists/essential/other-files deleted file mode 100644 index d35a5736..00000000 --- a/blacklists/essential/other-files +++ /dev/null @@ -1,3 +0,0 @@ -- .svn -- .git -- *.gvfs diff --git a/blacklists/essential/policykit b/blacklists/essential/policykit deleted file mode 100644 index 2f42c0e0..00000000 --- a/blacklists/essential/policykit +++ /dev/null @@ -1,2 +0,0 @@ -#- /usr/share/pol*/actions/org.freedesktop.upower.* - diff --git a/blacklists/essential/temp-files b/blacklists/essential/temp-files deleted file mode 100644 index 50955d08..00000000 --- a/blacklists/essential/temp-files +++ /dev/null @@ -1,5 +0,0 @@ -- *~ -- *.bak -- *.old -- *.pid -- *.tmp diff --git a/blacklists/essential/tm-scripts b/blacklists/essential/tm-scripts deleted file mode 100644 index 393effea..00000000 --- a/blacklists/essential/tm-scripts +++ /dev/null @@ -1 +0,0 @@ -- **/tm-scripts diff --git a/blacklists/package-managers/apt b/blacklists/package-managers/apt deleted file mode 100644 index 5e019138..00000000 --- a/blacklists/package-managers/apt +++ /dev/null @@ -1,2 +0,0 @@ -+ /var/cache/apt/archives/partial/** - diff --git a/blacklists/package-managers/rpm b/blacklists/package-managers/rpm deleted file mode 100644 index 0527ee75..00000000 --- a/blacklists/package-managers/rpm +++ /dev/null @@ -1,5 +0,0 @@ -- *.rpmnew -- *.rpmsave -- /etc/*rpmnew -- /etc/*rpmorig -- /etc/*rpmsave diff --git a/blacklists/package-managers/yast b/blacklists/package-managers/yast deleted file mode 100644 index 9de1ec05..00000000 --- a/blacklists/package-managers/yast +++ /dev/null @@ -1,5 +0,0 @@ -- /var/lib/YaST2/you/mnt/* -- /var/lib/YaST2/backup_boot_sectors -- /etc/*YaST2save -- *.YaST2save - diff --git a/blacklists/package-managers/yum b/blacklists/package-managers/yum deleted file mode 100644 index 8b137891..00000000 --- a/blacklists/package-managers/yum +++ /dev/null @@ -1 +0,0 @@ - diff --git a/blacklists/package-managers/zypper b/blacklists/package-managers/zypper deleted file mode 100644 index fbab85d7..00000000 --- a/blacklists/package-managers/zypper +++ /dev/null @@ -1,2 +0,0 @@ -- /var/lib/zypp - diff --git a/builder/INSTALL b/builder/INSTALL new file mode 100644 index 00000000..e52f0c39 --- /dev/null +++ b/builder/INSTALL @@ -0,0 +1,19 @@ +This subfolder is dedicated to dracut related files. + +The folder 'dnbd3-qcow2-rootfs' is a dracut module used to setup +a client's rootfs based on a (read-only) dnbd3 export made writable +through the qcow2 container format of the qemu ecosystem. + +To use this module within dracut, you simply need to copy/link/mount +the above mentioned folder to '/usr/lib/dracut/modules.d' prefixed +with a numerical priority. We used '90' so far, so the module was linked +to '/usr/lib/dracut/modules.d/90dnbd3-qcow2-rootfs'. + +Once the module has been integrated in dracut's modules, you can build +the initramfs with the following command: + + dracut --no-hostonly --modules "dnbd3-qcow2-rootfs" + +Note that the '--no-hostonly' is critical if the machine dracut is +executed on and the clients supposed to boot the resulting initramfs +differ. diff --git a/builder/dnbd3-qcow2-rootfs/TODO b/builder/dnbd3-qcow2-rootfs/TODO new file mode 100644 index 00000000..2e92a1d0 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/TODO @@ -0,0 +1,5 @@ +* Dynamic building of dnbd3 / nbd kernel modules +* Dynamic building of dnbd3-client / systemd-preserver-process-marker + +* Research whether the dracut busybox module satisfies our requirements +* If not, compiling busybox should be done somehow diff --git a/builder/dnbd3-qcow2-rootfs/binaries/busybox b/builder/dnbd3-qcow2-rootfs/binaries/busybox new file mode 100755 index 00000000..7eceacf7 Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/binaries/busybox differ diff --git a/builder/dnbd3-qcow2-rootfs/binaries/dnbd3-client b/builder/dnbd3-qcow2-rootfs/binaries/dnbd3-client new file mode 100755 index 00000000..76924b49 Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/binaries/dnbd3-client differ diff --git a/builder/dnbd3-qcow2-rootfs/binaries/systemd-preserve-process-marker b/builder/dnbd3-qcow2-rootfs/binaries/systemd-preserve-process-marker new file mode 100755 index 00000000..45beb51d Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/binaries/systemd-preserve-process-marker differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/busybox b/builder/dnbd3-qcow2-rootfs/debugging_tools/busybox new file mode 100755 index 00000000..1212ae20 Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/debugging_tools/busybox differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/endless b/builder/dnbd3-qcow2-rootfs/debugging_tools/endless new file mode 100755 index 00000000..de7a8c0a Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/debugging_tools/endless differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/endless.c b/builder/dnbd3-qcow2-rootfs/debugging_tools/endless.c new file mode 100644 index 00000000..22c9bc50 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/debugging_tools/endless.c @@ -0,0 +1,10 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + // Provides a dummy worker. + while (1) + sleep(999999999); +} diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-client b/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-client new file mode 100755 index 00000000..7bb2207f Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-client differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko b/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko new file mode 100644 index 00000000..47cf6cd6 Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/network.functions b/builder/dnbd3-qcow2-rootfs/debugging_tools/network.functions new file mode 100644 index 00000000..89ca5a20 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/debugging_tools/network.functions @@ -0,0 +1,23 @@ +wait_for_iface() { + local DEVICE=$1 + local TIMEOUT=10 + echo -n "Waiting for interface $DEVICE: " + # Some systems don't have operstate. Seems to be hardware dependent + [ ! -e "/sys/class/net/${DEVICE}/operstate" ] && usleep 10000 + if [ -e "/sys/class/net/${DEVICE}/operstate" ]; then + while true; do + # check linkstate + [ "x$(cat "/sys/class/net/${DEVICE}/operstate")" == "xup" ] && break + TIMEOUT=$(( $TIMEOUT - 1 )) # don't wait forever, the pcnet iface of vmware will never be "up" although it's working + [ "$TIMEOUT" -le 0 ] && break + # else + echo -n "." + usleep 500000 + done + else + # we really don't have a operstate .. then just wait a sec and hope for the best. + sleep 1 + fi + echo ".$(cat "/sys/class/net/${DEVICE}/operstate" 2>/dev/null)" +} +true diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd b/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd new file mode 100755 index 00000000..b34a3ff7 Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark b/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark new file mode 100755 index 00000000..03c2a6b1 Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh b/builder/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh new file mode 100644 index 00000000..3b32a68c --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +echo "Setting up network..." + +echo "Main MAC address is '$MAC'" + +# setup network +source /inc/network.functions + +# set up loopback networking +echo "Setting up loopback" +ip link set dev lo up 2>/dev/null +ip addr add 127.0.0.1/8 dev lo 2>/dev/null + +echo "Setting up bridge" +BRIDGE="br0" + +# Following was supposed to prevent scripts from getting confused by multiple interfaces with same MAC - does not work though +## Flip mac address of original interface - this var is not local so init sees the changes too +#MAC="$(echo "$MAC" | awk -F ':' '{printf $1 ":" $2 ":" $5 ":" $3 ":" $6 ":" $4}')" +#ip link set addr "$MAC" "$SLAVE" + +mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d" + +#IP_OUT=$(ip a | sed -r ':a;N;$!ba;s/: ([a-z0-9]+): /####\1####/g;s/ether ([a-f0-9:]+) /####\1####/g'| grep -E -o '####[^ ]+####' | sed 's/#//g' | grep -B 1 ':') +IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#') + +if ! echo "$IP_OUT" | grep -q -- "$MAC"; then + drop_shell "Boot interface not found in interface list. NIC driver missing?" +fi + +for LINE in $IP_OUT; do + IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}') + IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[A-Z]' '[a-z]') # udev requires mac addesses to be lowercase (a-f), see http://www.debianhelp.co.uk/udev.htm + echo "${IFACE} = ${IFMAC}" + + if [ "x$IFMAC" == "x$MAC" ]; then + brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE" + brctl stp "$BRIDGE" 0 + brctl setfd "$BRIDGE" 0.000000000001 + ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE" + ip link set dev "$IFACE" up + wait_for_iface "$IFACE" + brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE" + + # save our variables for retry on fail + echo "IFACE=$IFACE" > /run/network.conf + + # analyze ip information from the kernel command line and put parts + # of it into several variables + if [ -n "$CLIENTIP" ] ; then + # set static ip address + ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE" + ip link set dev "$BRIDGE" up + [ -n "$GATEWAY" ] && ip route add default via "$GATEWAY" dev "$BRIDGE" + else + NOIPYET="yes" + fi + # Ignore this device later on when systemd handles network interfaces (see hacked 99-systemd.rules in systemd data dir) + echo "SUBSYSTEM==\"net\", ACTION==\"add\", KERNEL==\"eth*\", ATTR{address}==\"$IFMAC\", TAG+=\"openslxignore\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/01-ignore-boot-interface.rules" + fi + # youdev + echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$IFMAC\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$IFACE\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/70-net-boot-nic-name.rules" + # continue... + IFACE="" +done + +wait_for_iface "$BRIDGE" + +# udhcpc +PARAM= +if [ -n "$CLIENTIP" ]; then + PARAM="-r $CLIENTIP" +fi +echo -n "$CLIENTIP" > "/run/firstip" +echo -n "$GATEWAY" > "/run/firstgw" + +# save our variables for retry on fail ff. +echo "CLIENTIP=$CLIENTIP" >> /run/network.conf +echo "GATEWAY=$GATEWAY" >> /run/network.conf +echo "BRIDGE=$BRIDGE" >> /run/network.conf + +udhcpc $PARAM -O domain -O nissrv -O nisdomain -O wpad -O search -t 5 -T 2 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" +# udhcpc return value will be return value of this script diff --git a/builder/dnbd3-qcow2-rootfs/hooks/cmdline/enable-sysrq.sh b/builder/dnbd3-qcow2-rootfs/hooks/cmdline/enable-sysrq.sh new file mode 100755 index 00000000..f779aa7a --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/cmdline/enable-sysrq.sh @@ -0,0 +1,2 @@ +# enables magic sysrq keys +echo 1 > /proc/sys/kernel/sysrq diff --git a/builder/dnbd3-qcow2-rootfs/hooks/cmdline/expand-kcl-ip.sh b/builder/dnbd3-qcow2-rootfs/hooks/cmdline/expand-kcl-ip.sh new file mode 100755 index 00000000..9f617b09 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/cmdline/expand-kcl-ip.sh @@ -0,0 +1,36 @@ +command -v warn >/dev/null || . /lib/dracut-lib.sh + +# fakes the cmdline to fix the ip parsing in darcut's net-lib.sh +[ -d /fake ] || mkdir /fake + +# need to be a tmpfs for the hack to work +mount -t tmpfs tmpfs /fake + +for parameter in $(getargs ip=); do + local temp="$parameter:" + set -- + while [ -n "$temp" ]; do + set -- "$@" "${temp%%:*}" + temp=${temp#*:} + done + + [ -n "$1" ] && ip=$1 + [ -n "$2" ] && server_ip=$2 + [ -n "$3" ] && gateway_ip=$3 + [ -n "$4" ] && net_mask=$4 + + warn "PXE given net configuration: ip: $ip server_ip: $server_ip gateway_ip: $gateway_ip net_mask: $net_mask" + local final_dracut_ip_config="$ip::$gateway_ip:$net_mask:hiwi-test-28:eno1:none" + warn "Final dracut ip config: $final_dracut_ip_config" + sed --regexp-extended "s/ip=[^ ]*/ip=$final_dracut_ip_config/g" /proc/cmdline > /fake/cmdline +done + + +# bind mount it. Can we trust mount return codes here? +# # if so, we should check what we get in $? +mount -o bind /fake/cmdline /proc/cmdline + +# check if it worked +if ! grep 'hiwi-test-28:eno1:none' /proc/cmdline; then + warn 'Haxing cmdline did not work :( sad pandaz...' +fi diff --git a/builder/dnbd3-qcow2-rootfs/hooks/cmdline/mark-root-device.sh b/builder/dnbd3-qcow2-rootfs/hooks/cmdline/mark-root-device.sh new file mode 100755 index 00000000..b7282521 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/cmdline/mark-root-device.sh @@ -0,0 +1,9 @@ +# set rootok and root as dracut expects them to be set by +# the module preparing the root filesystem. +# +# Once the root filesystem is mounted per dnbd3 and +# exported as qcow2 per nbd, /dev/root will be a symlink +# to /dev/nbd0 as this is then our rootfs-device +rootok=1 +root=block:/dev/root + diff --git a/builder/dnbd3-qcow2-rootfs/hooks/mount/mount-root-device.sh b/builder/dnbd3-qcow2-rootfs/hooks/mount/mount-root-device.sh new file mode 100755 index 00000000..d02f9002 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/mount/mount-root-device.sh @@ -0,0 +1,4 @@ +# this rudimentary script just mounts the rootfs device that was symlinked to +# /dev/root to dracut's $NEWROOT (usually /sysroot). + +mount /dev/root $NEWROOT diff --git a/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/fetch-config.sh b/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/fetch-config.sh new file mode 100755 index 00000000..a90481c8 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/fetch-config.sh @@ -0,0 +1,39 @@ +# load dracut functions +command -v getarg >/dev/null || . /lib/dracut-lib.sh + +# read SLX_SERVER and SLX_BASE from the kernel command line +SLX_SERVER=$(getarg slxsrv) +SLX_BASE=$(getarg slxbase) +SLX_CONFIG_DIR="/opt/openslx" +SLX_CONFIG_FILE="/opt/openslx/config" + +if [ -z "$SLX_SERVER" ]; then + warn "No 'slxsrv' parameter found in the kernel command line!" + warn "Skipping OpenSLX configuration..." + return 1 +fi +if [ -z "$SLX_BASE" ]; then + warn "No 'slxbase' parameter found in the kernel command line!" + warn "Skipping OpenSLX configuration..." + return 1 +fi + +info "Getting configuration from OPENSLX-Server..." +WGET="$(busybox which wget)" +if [ -z $WGET ]; then + # do nothing + warn "'wget' not found. Skipping openslx configuration..." + return 1 +fi + +# ok then we are ready to download the config +mkdir -p "${SLX_CONFIG_DIR}" +$WGET -T 5 -q "http://${SLX_SERVER}/${SLX_BASE}/config" -O "${SLX_CONFIG_FILE}" +RET="$?" +if [ $RET -ne 0 ]; then + warn "Downloading OpenSLX configuration from ${SLX_SERVER}/${SLX_BASE} failed: $RET" + emergency_shell -n "$0" + return 1 +else + return 0 +fi diff --git a/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/mount-qcow.sh b/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/mount-qcow.sh new file mode 100755 index 00000000..d70492bf --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/mount-qcow.sh @@ -0,0 +1,49 @@ +############################################################################### +# CHECKS +# + +SETUP_ROOTFS_SCRIPT="/sbin/setup-qcow2" + +if [ ! -e "${SETUP_ROOTFS_SCRIPT}" ]; then + warn "No such file of directory: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +if [ ! -x "${SETUP_ROOTFS_SCRIPT}" ]; then + warn "Cannot execute: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +# +# END CHECKS +############################################################################### + +############################################################################### +# MAIN CODE +# + +# ok, let's source the setup script +if ! . ${SETUP_ROOTFS_SCRIPT} ; then + warn "Could not source: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +# just go over the functions in the right order ;-) +for fun in connect_dnbd3 create_qcow export_qcow connect_qcow; do + if ! $fun; then + # something failed, drop a shell for debugging + warn "'$fun' failed with: $?" + emergency_shell -n "Error in $fun" + return 1 + fi +done + +# all good, we are done +return 0 + +# +# END MAIN CODE +############################################################################### diff --git a/builder/dnbd3-qcow2-rootfs/hooks/pre-pivot/mount-tmp.sh b/builder/dnbd3-qcow2-rootfs/hooks/pre-pivot/mount-tmp.sh new file mode 100755 index 00000000..3e702064 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/pre-pivot/mount-tmp.sh @@ -0,0 +1,40 @@ +# This script only checks if we found a usable partition for the +# future /tmp. The discovery of that partition is done by udev during +# the initqueue. If a valid partition is found (either GPT with the label +# OPENSLX_TMP or MBR with the type 0x44) its path will be written to +# /tmp/openslx.tmpdisk +OPENSLX_TMP_DISK_FLAG="/tmp/openslx.disk.tmp" + +if [ ! -e "$OPENSLX_TMP_DISK_FLAG" ]; then + warn "'$OPENSLX_TMP_DISK_FLAG' not found!" + warn "Systemd will manage $NEWROOT/tmp on its own." + # no partition for the future /tmp found, just + # let systemd manage it then (probably a tmpfs) + return 1 +fi + +# in /tmp/openslx.disk.tmp is the name of the device +# to mount as /tmp in the real system +# meaning we need to mount it to /sysroot/tmp here. + +OPENSLX_TMP_DISK_DEV="$(cat $OPENSLX_TMP_DISK_FLAG)" + +# sanity check: is the content a block device? +if [ ! -b "$OPENSLX_TMP_DISK_DEV" ]; then + warn "'$OPENSLX_TMP_DISK_DEV' appears not to be a block device!" + warn "Systemd will manage $NEWROOT/tmp on its own." + return 1 +fi + +# all good, keep on +if ! mount -t auto "$OPENSLX_TMP_DISK_DEV" $NEWROOT/tmp; then + # something else went wrong :( + warn "Mounting '$OPENSLX_TMP_DISK_DEV' to '$NEWROOT/tmp' failed with: $!" + warn "Systemd will manage $NEWROOT/tmp on its own." + return 1 +fi + +# still here? mount worked wohoo +# set permissions +chmod a+rwxt $NEWROOT/tmp +return 0 diff --git a/builder/dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh b/builder/dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh new file mode 100755 index 00000000..9103afd9 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh @@ -0,0 +1 @@ +/sbin/initqueue --name ifup-lo --unique --onetime /sbin/ifup lo -m diff --git a/builder/dnbd3-qcow2-rootfs/hooks/pre-udev/load-dnbd3-nbd-modules.sh b/builder/dnbd3-qcow2-rootfs/hooks/pre-udev/load-dnbd3-nbd-modules.sh new file mode 100755 index 00000000..29f9f210 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/pre-udev/load-dnbd3-nbd-modules.sh @@ -0,0 +1,32 @@ +# include dracut-lib.sh to use 'warn' +command -v warn >/dev/null || . /lib/dracut-lib.sh + +NBD_MOD_PATH="/usr/lib/modules/current/extra/nbd.ko" +DNBD3_MOD_PATH="/usr/lib/modules/current/extra/dnbd3.ko" + +# do we actually have our modules? +if [ ! -e "${NBD_MOD_PATH}" ]; then + warn "No such file of directory: ${NBD_MOD_PATH}" + emergency_shell -n "Error in $0" + return 1 +fi +if [ ! -e "${DNBD3_MOD_PATH}" ]; then + warn "No such file of directory: ${DNBD3_MOD_PATH}" + emergency_shell -n "Error in $0" + return 1 +fi + +# load the kernel modules for dnbd3 and nbd +if ! insmod "${DNBD3_MOD_PATH}"; then + warn "Failed to load DNBD3 kernel module..." + emergency_shell -n "Error in $0" + return 1 +fi + +if ! insmod "${NBD_MOD_PATH}"; then + warn "Failed to load NBD kernel module..." + emergency_shell -n "Error in $0" + return 1 +fi + +return 0 diff --git a/builder/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko b/builder/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko new file mode 100755 index 00000000..d7b7ce3b Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko differ diff --git a/builder/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko b/builder/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko new file mode 100644 index 00000000..e8c3f40f Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko differ diff --git a/builder/dnbd3-qcow2-rootfs/module-setup.sh b/builder/dnbd3-qcow2-rootfs/module-setup.sh new file mode 100644 index 00000000..b3f14c1d --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/module-setup.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +check() { + if ! type -f qemu-nbd >/dev/null; then + echo "'qemu-nbd' not found on this system, install it to use this module." + return 1 + fi + if ! type -f qemu-img >/dev/null; then + echo "'qemu-img' not found on this system, install it to use this module." + return 1 + fi + if ! type -f nbd-client >/dev/null; then + echo "'nbd-client' not found on this system, install it to use this module." + return 1 + else + # check version + local nbd_client_version="$(nbd-client --help 2>&1 | grep -oE '3\.[0-9]+')" + local nbd_client_version_major="${nbd_client_version%.*}" + local nbd_client_version_minor="${nbd_client_version#*.}" + if [ "${nbd_client_version_major}" -ne 3 ]; then + # nbd-client probably too old + echo "The nbd-client major version is not 3, meaning its probably too old." + return 1 + fi + if [ "${nbd_client_version_minor}" -gt 8 ]; then + # TODO check if ver = 3.9 has the same new syntax... + echo "The nbd-client minor version is greater than 8. A new syntax has been + introduced starting with 3.10 which we do not support." + return 1 + fi + return 0 + fi +} + +depends() { + echo base network bash kernel-modules + return 0 +} + +installkernel() { + instmods ext4 +} + +install() { + ### BINARIES + # + # busybox: cause we want lightweight tools + inst "$moddir/binaries/busybox" /usr/bin/busybox + # dnbd3-client: needed to mount remote dnbd3 filesystem. + inst "$moddir/binaries/dnbd3-client" /usr/bin/dnbd3-client + # A generic wrapper program to prepend a "@" to each process + # spawned by given nested programs. + inst "$moddir/binaries/systemd-preserve-process-marker" \ + /usr/bin/systemd-preserve-process-marker + + # NOTE: These modules are build again Kernel: 3.10.0-229.1.2.el7.x86_64 + # TODO: build these in check() ! + inst "$moddir/kernel_modules/dnbd3.ko" \ + /usr/lib/modules/current/extra/dnbd3.ko + inst "$moddir/kernel_modules/nbd.ko" \ + /usr/lib/modules/current/extra/nbd.ko + + ### HOOKS + ## HOOK cmdline + # enables sysrq-shortcuts + inst_hook cmdline 00 "$moddir/hooks/cmdline/enable-sysrq.sh" + + # expands the ip parameter in the kernel command line to + # make it dracut-compatible + # TODO: dracut still parses this incorrectly... + inst_hook cmdline 10 "$moddir/hooks/cmdline/expand-kcl-ip.sh" + + # sets environment variables to tell dracut which device + # holds the future root filesystem + inst_hook cmdline 90 "$moddir/hooks/cmdline/mark-root-device.sh" + + ## HOOK pre-udev + # loads the dnbd3/nbd kernel modules + inst_hook pre-udev 00 "$moddir/hooks/pre-udev/load-dnbd3-nbd-modules.sh" + + # setup loopback device + inst_hook pre-udev 00 "$moddir/hooks/pre-udev/lo-setup.sh" + + ## HOOK pre-mount + # this is the configuration hook where the config stuff is wget'ed + inst_hook pre-mount 00 "$moddir/hooks/pre-mount/fetch-config.sh" + + # this is the main hook where all the magic is triggered + inst_hook pre-mount 10 "$moddir/hooks/pre-mount/mount-qcow.sh" + + ## HOOK mount + # this simply mounts the prepared /dev/root to $NEWROOT + # aka "the dracut way" + inst_hook mount 10 "$moddir/hooks/mount/mount-root-device.sh" + + ## HOOK pre-pivot + # this checks whether we found a partition suitable for + # the future /tmp and if so, mounts it + inst_hook pre-pivot 00 "$moddir/hooks/pre-pivot/mount-tmp.sh" + + ### SCRIPTS + # the main magic script containing all the functions needed + # to prepare the qcow2-based root filesystem + inst "$moddir/scripts/setup-qcow2" /sbin/setup-qcow2 + + # the script triggered by udev upon finding the right partitions + inst "$moddir/scripts/prepare-disks" /sbin/prepare-disks + + # udev rules detecting 44, 45, 46 partitions and running + # 'prepare-disks' to do then format/mount/use them + inst "$moddir/udev/70-openslx-disk.rules" /etc/udev/rules.d/70-openslx-disk.rules + + # Debugging Uncomment this version if you need some useful debugging tools + # in your iniramfs. + inst_multiple lsblk ping ip ifconfig sshd htop tail head cat vim \ + touch sed lsmod insmod qemu-img sleep route wget find lsof strace \ + chroot switch_root pivot_root qemu-nbd mount nbd-client fdisk mkfs.xfs + # Production: + # inst_multiple insmod qemu-img qemu-nbd + return 0 +} diff --git a/builder/dnbd3-qcow2-rootfs/readme.md b/builder/dnbd3-qcow2-rootfs/readme.md new file mode 100644 index 00000000..9ad0f968 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/readme.md @@ -0,0 +1,472 @@ +# TODO --ommit npd +# TODO Testmenue PW: t + +h1. Evaluation, dissection and modification of Linux remote boot + +h2. Inhalt + +{{toc}} + +#h2. Begriffe + +#* qcow - qemu copy-on-write +#* stage3.1 initramfs +#* stage4 finales System + +h2. Aufgabe + +Es wird ein Skript bzw. Dracut-Modul benötigt, dass ein initramfs basierend auf +systemd baut. Das resultierende initramfs muss Netzwerk-Support bereitstellen, +ein dnbd3 Blockdevice mounten können und einen "switch_root" auf das zuvor +gemountete Dateisystem umsetzen. Das Framework sollte möglichst +Distributionsunabhängig konstruiert sein. Es soll bereits vor dem +"switch_root", also bevor das eigentliche Zielsystem im Root-Verzeichnis +eingebunden werden systemd als init-System zum Einsatz kommen. Die Kernaufgabe +eine initramfs ist es alle nötigen Anwendungen bereitzustellen, die benötigt +werden, um dass finale Zielsystem einzubinden. In dieser konkreten +Aufgabenstellung muss, dass initramfs ein nicht schreibbares Blockgerät +eingebunden werden und eine schreibbare Zwischenshicht (Overlayfilesystem) +zusätzlich eingebunden werden. + +h2. Möglicher Technologien für das Overlaykonzept + +* Dateibasierte Overlay-FS (Union-FS, Alternat-Union-FS, Overlay-FS) + - Funktioniert derzeit nicht auf jedem Zielsystem (Kernel) + - Nicht für den Linux-Kernel zertifiziert oder lässt sich nicht über das + Root-System legen. + - Bei wenigen Änderungen in einer großen Datei muss komplette Datei in + der schreibbaren Schicht gespeichert werden. +* Blockorientierte Overlay-FS (Network-Block-Device, DNBD3, Qemu-Copy-On-Write-Image) + - NBD ist für den Linux-Kernel zertifiziert + - Weniger Netzwerkverkehr nötig, da nur geänderte Blöcke übertragen werden + müssen, statt ganze Dateien zu kopieren. + - DNBD3 hat Failover-Strategien, verzichtet auf komplexe Strategien zum + Schreiben in geänderte Blöcke über das Netzwerk + - Das verfügbare qcow2-Format bietet eine Technologie, um blockorientiert + Änderungen in einer zusätzlichen Dateisystemschicht zu speichern. + +h2. Zielablauf + +Der generelle Ablauf vor bzw. während des Ladens des initramfs und deren +Minilinux-System: + +# Boot PXE +> # Laden des initramfs images +> # Laden des Kernels +# Ausführen des iniramfs +> # Ausführen von Systemd +> > # Bereitstellen aller benötigten Dienste und Hardware (Netzwerk hochbringen) +> > # Mounten des finalen Dateisystems als Wurzel +> > # Wechsel (switch_root) in die finale Distribution +> > # Starten / Weiterausführen von Systemd als Init-System + +h2. Benötigte Pakete zum bauen des initramfs + +> * dracut +# TODO + +h2. Benötigte Pakete innerhalb des resultierenden initramfs + +> * systemd +> * quemu-img +> * quemu-nbd +> * nbd-client +> * dnbd3-client + +h2. Aufsetzen einer Test-Arbeitsumgebung für CentOS + +h3. CentOS7/ArchLinux/RedHat/Ubuntu + VirtualBox + VirtualBoxGuestAdditions + +Aufsetzen des *Dynamic Kernel Module Support*, um einfach neue VBox-Kernel-Module zu aktualisieren: + +> # Aktualisiere Paketdatenbank: @yum update@ +> # Intalliere C-Compiler: @yum install gcc@ +> # Lade erweitertes rpmforfe Repository: @wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm@ +> # Installiere Repository: @rpm -Uvh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm@ +> # Lade das DKMS-Paket: @wget ftp://rpmfind.net/linux/epel/5/x86_64/dkms-2.2.0.3-29.el5.noarch.rpm@ +> # Installiere DKMS-Paket: @yum localinstall dkms-2.2.0.3-25.el7.noarch.rpm --nogpgcheck@ +> # Aktiviere rpmforge Repository: @yum --enablerepo rpmforge install dkms@ +> # Installiere Entwicklertools zum bauen von Paketen: @yum groupinstall "Development Tools"@ +> # Installiere Metainformation zum Kernel: @yum install kernel-devel@ + +Installieren der VirtualBox-GuestAddtion: + +> # Lege die VirtualBox-GuestAddition-CD ein. +> # Mounte CD: @mount /dev/sr0 /mnt/ && cd /mnt/ && ./VBoxLinuxAdditions.run && reboot@ + +Erstellen eines Testboot Eintrags für Grub2: + +> - Füge in ??/etc/grub.d/40_custom?? den folgenden Inhalt hinzu: + +
+menuentry 'test' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.el7.x86_64-advanced-6c06919a-389a-4a50-8c6b-b086e65db9b0' {
+    load_video
+    set gfxpayload=keep
+    insmod gzio
+    insmod part_msdos
+    insmod xfs
+    set root='hd0,msdos1'
+    if [ x$feature_platform_search_hint = xy ]; then
+        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  4236333a-a808-4f6b-b4a6-d963f4a69a25
+    else
+        search --no-floppy --fs-uuid --set=root 4236333a-a808-4f6b-b4a6-d963f4a69a25
+    fi
+    linux16 /vmlinuz-3.10.0-123.el7.x86_64 root=UUID=6c06919a-389a-4a50-8c6b-b086e65db9b0 ro rd.lvm.lv=centos/swap crashkernel=auto  rd.lvm.lv=centos/root vconsole.font=latarcyrheb-sun16 vconsole.keymap=de rhgb quiet 
+    initrd16 /initramfs-test.img
+}
+
+ +> - Füge neuen Menüeintrag in die automatisch generierte Grub2 Konfigurations2-Datei hinzu: @grub2-mkconfig -o /boot/grub2/grub.cfg@ + +h2. Bauen eines Test-Initramfs + +Mache ein Backup vom aktuellen initamfs: +@cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.BACKUP@ + +Der folgende Befehl ersetzt das aktuelle Standart Initramfs mit dem neu +gebauten und berücksichtigt dabei alle bisher editierten Dracut-Module in +??/usr/lib/dracut/modules.d??. Die durchschnittliche Größe des resultierenden +initramfs beträgt komprimiert: zwischen 11 und 16 MB. + +

+dracut --verbose --force /boot/initramfs-3.10.0-123.el7.x86_64.test.img \
+    3.10.0-123.el7.x86_64
+
+ +h3. Konfiguration + +TODO + +# Configure "cmdline" from "Chapter 8. DRACUT.CMDLINE(7)" in virtualbox in "/boot/startup.sh" for uefi or in "/boot/grub2/grub.cfg" for grub2 + +h2. Bauen eines minimalen individuellen Test-Initramfs + +

+dracut --verbose --hostonly --force 
+    /boot/initramfs-3.10.0-123.el7.x86_64.test.img \
+    3.10.0-123.el7.x86_64
+
+ +Die Option "hostonly" veranlasst Dracut dazu nur alle nötigen Abhängigkeiten +für das aktuelle System in das resultierende Initramfs zu installieren. +Andernfalls fügt dracut viele zusätzliche Treiber hinzu, die die Größe der +resultierenden Datei erheblich vergrößern und damit größer wird als nötig. +Die durchschnittliche Größe des resultierenden initramfs beträgt +komprimiert: zwischen 11 und 16 MB. + +h2. Erstellen eines eigenen Dracut-Moduls + +Alle vorhanden Module befinden sich in ??/usr/lib/dracut/modules.d??. + +> # Erstelle ein neues Modul: @mkdir /usr/lib/dracut/modules.d/91test@ +> # Baue neues initramfs und achte darauf, dass ??\*\*Including module: test\*\*?? mit der Command-Line-Option ??--verbose?? ausgegeben wird. +> # Alle Modul-Installations-Informationen sind in der Datei ??module-setup.sh??: @touch /usr/lib/dracut/modules.d/91test/module-setup.sh@ +> # Konfiguriere Modul: +> > # Als erstes erstellt man eine ??check??-Funktion, die lediglich ??0?? + zurückgibt. Diese Funktion wird aufgerufen, wenn entschieden wird, welche + Dracutmodule geladen werden sollen. Durch zurückgeben der ??0?? wird das + Modul beim nächsten bauen eines Initramfs automatisch hinzugefügt ohne + das man es etwas in der ??/etc/dracut.conf?? oder per Command-Line-Option + "--add" angeben muss. Wenn die @$hostonly@ Variable gesetzt ist, dann + wird das Modul auch im "hostonly" Modus geladen. In diesem Fall sollte + die Funktion nur dann ??0?? zurückgeben, wenn das Modul auch wircklich + für den aktuellen Host benötigt wird. Wenn 255 zurückgegeben wird, wird + das Modul nur dann geladen, wenn es von einem andren Modul als + Abhängigkeit deklariert wurde. + +

+check() {
+    return 0
+}
+
+ +Als nächstes wird eine ??install??-Funktion erstellt. Die ??install??-Funktion +wird aufgerufen, wenn alle nicht Kernel spezifischen Ressourcen installiert +werden sollen. Es können Binärdateien, Skripte und andere statischen Dateien +installiert werden. Um einen Datei im aktuellen Modul-Ordner zu addressieren +sollte die Variable "$moddir" als Prefix eingesetzt werden. +Eine solche Funktion kann beispielsweise einen ??Command-Line-Hook?? triggern, +der modulespezifische ??Kernel-Command-Line-Optionen?? verarbeitet während das +initiale Minilinux bootet. Im folgenden Beispiel werden ??Command-Line-Optionen +mit Priorität 20 vom Shell-Skript ??parse-insmodpost.sh?? gelesen und +ausgewertet. Dadurch muss natürlich auch das entsprechende Skript in das +initramfs kopiert werden. Dies wird durch den Aufruf der Funktion +??inst_simple?? erreicht. + +

+install() {
+    inst_hook cmdline 20 "$moddir/parse-cmdline.sh"
+    inst_simple "$moddir/parse-cmdline.sh" /sbin/insmodpost.sh
+}
+
+ +Die ??parse-cmdline.sh?? parst die Kernel-Command-Line für die Argumente +??rd.driver.post??, verhindert, dass die Module automatisch geladen werden und +installiert den Hook ??hook.sh?? in der ??initqueue/settled??. Der Inhalt von +??parse-cmdline.sh?? könnte wie folgt aussehen: + +

+for p in $(getargs rd.driver.post=); do
+    echo "blacklist $p" >> /etc/modprobe.d/initramfsblacklist.conf
+done
+
+ +In einer ??depends??-Funktion können andere Dracut-Module als Abhängigkeit +deklariert werden. Diese müssen einfach per "echo" als String Leerzeichen +getrennt ausgegeben werden. + +

+depends() {
+    echo 'debug virtfs'
+}
+
+ +Mit dieser Funktion können zusätzliche benötigte Kernel-Command-Line-Argumente +ausgegeben werden, die benötigt werden um die aktuelle Maschine zu booten. +Die Ausgabe sollte mit einem Leerzeichen beginnen und keine neuen Zeilen +ausgeben. + +

+cmdline() {
+    echo 'TODO'
+}
+
+ +Mit der Funktion ??installkernel?? sollen alle kernelspezifischen Dateien +installiert werden. Siehe hierzu auch den Abschnitt +??Hilfsfunktionen zur Installation?? + +

+installkernel() {
+    TODO
+}
+
+ +h2. Hilfsfunktionen zur Installation + +??inst_multiple?? installiert mehrere Binärdateien. Sollten ausführbare Dateien +ohne entsprechendem Pfad ausgewählt werden, wird dracut folgende die Pfade +??/usr/sbin??, ??/sbin??, ??/usr/bin??, ??/bin?? durchsuchen, um den Pfad der +zugehörigen ausführbaren Datei zu ermitteln. Bei dem Kommando-Zeilen-Argument +??-o?? als erster Parameter werden Fehler bei nicht auffindbaren Dateien +unterdrückt. + +??inst_multiple [-o] [ …]?? + +??inst?? installiert eine referenzierte Datei an den korrespondierenden Ort im +??initramfs??. Die Datei wird innerhalb des ??initramfs?? am gleichen Ort zu +finden sein wie auf der Referenzmaschine. Optional kann als zweites Argument +ein anderer Ort für das temporäre Dateisystem angegeben werden. + +??inst []?? + +??inst_hook?? installiert eine ausführbare Datei im Pfad ???? im +Dracut-hook-Ordner ????. Der Einstiegspunkt wird mit Priorität +???? zur Laufzeit des initialen Mini-Linux-Systems ausgeführt. + +??inst_hook ?? + +??inst_rules?? installiert einen oder mehrere udev-Regeln. Nicht-existente +udev-Regeln werden beim bauen des initramfs gemeldet, führen aber nicht zum +Abbruch. + +??inst_rules [ …]?? + +??instmods?? installiert einen oder mehrere Kernel-Module in das initramfs. +???? kann auch ein komplettes Subsystem darstellen, wenn es mit +dem Prefiy "=" beginnt (z.B. "=drivers/net/team"). ??instmods?? sollte nur +innerhalb der ??installkernel()??-Funktion verwendet werden. Ist ??$hostonly?? +gesetzt und das aktuelle Modul nicht im Referenzsystem geladen und wird +demnach nicht in ??/sys/…/uevent MODALIAS?? verwendet, wird dieses nicht in +das initramfs integriert. Soll das Modul in jedem Fall geladen werden, kann +folgende Syntax verwendet werden: + +

+installkernel() {
+    hostonly='' instmods 
+}
+
+ +??instmods [ … ]?? + +h3. Konfiguration + +TODO + +h3. Debugging + +TODO + +h2. Build kernel specific dnbd3 kernel module + +> # Installiere Metainformation zum Kernel: @yum install kernel-devel@ +> # Installiere cmake zum Bauen von dnbd3: @yum install cmake@ +> # Installiere zlib-devel zum Bauen von dnbd3: @yum install zlib-devel@ + +Die kernel header Dateien liegen in: + +/usr/lib/modules/3.10.0-229.1.2.el7.x86_64 + +TOOD + +dnbd3-client -h 132.230.4.1 -i stage4/torben/test -r 1 + +> # Installiere qemu-img: @yum install qemu-img@ +> # Installiere nbd: @wget http://dl.fedoraproject.org/pub/epel/6/x86_64/nbd-2.9.20-7.el6.x86_64.rpm && rpm -Uvh nbd-2.9.20-7.el6.x86_64.rpm@ + +NOTE: Disable NetworkManager to avoid reloading network on boot: systemctl disable NetworkManager + +h2. CentOS7 @rpmbuild@ + +First "Set up RPM build env":http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment +Now in that user's home, e.g. @/home/builder@: +
+# install yumdownloader
+yum install yum-utils
+
+# download source in /home/builder/
+yumdownloader --source systemd
+
+# should have now have a file ~/systemd-208-20.el7_1.2.src.rpm
+# "install" it in ~/rpmbuild
+rpm -ivh systemd-208-20.el7_1.2.src.rpm
+
+# install building deps
+yum-builddep ~/rpmbuild/SPECS/systemd.spec
+
+# now check if everything is working, by running the simple %prep% phase
+# (unpacks source & applies patches)
+rpmbuild -bp ~/rpmbuild/SPECS/systemd.spec
+
+# if it worked, we can probably compile
+# this runs %prep% and %build%
+rpmbuild -bp ~/rpmbuild/SPECS/systemd.spec
+
+ +dmesg + 998 ping 8.8.8.8 + 999 shutdown .h now + 1000 shutdown -h now + 1001 y search yumdownloader + 1002 y install yum-utils + 1003 yumdownloader --help + 1004 yumdownloader --source glib2 qemu + 1005 yumdownloader --source qemu-img + 1006 ls + 1007 mkdir glib2_source + 1008 cd glib2 + 1009 cd glib2_source/ + 1010 rpm2cpio ../glib2-2.40.0-4.el7.src.rpm | cpio -idmv + 1011 ls + 1012 tar xf glib-2.40.0.tar.xz + 1013 ls + 1014 cd glib-2.40.0 + 1015 ls + 1016 ./configure --enable-static + 1017 make + 1018 ls + 1019 make + 1020 y search zlib + 1021 y search zlib-static + 1022 y install zlib-static + 1023 ./configure --enable-static + 1024 y search libffi + 1025 y install libffi + 1026 y install libffi-devel + 1027 ./configure --enable-static + 1028 make + 1029 ls + 1030 cd build/ + 1031 ls + 1032 .. + 1033 l + 1034 ls + 1035 make install + 1036 .. + 1037 l + 1038 .. + 1039 l + 1040 mkdir qemu-kvm + 1041 cd qemu-kvm + 1042 ls + 1043 rpm2cpio ../qemu-kvm-1.5.3-86.el7_1.1.src.rpm | cpio -idmv + 1044 l + 1045 pwd + 1046 ls + 1047 l + 1048 ls + 1049 .. + 1050 l + 1051 git clone git://git.qemu.org/qemu.git qemu + 1052 ls + 1053 rm qemu-kvm -rf + 1054 rm qemu-kvm-1.5.3-86.el7_1.1.src.rpm + 1055 l + 1056 cd qemu/ + 1057 l + 1058 ./configure --static --target-list=x86_64-linux-user + 1059 y install zlib + 1060 y install zlib-devel + 1061 y install zlib2 + 1062 y search zlib + 1063 y install zlib-static + 1064 y install zlib + 1065 ll /lib64/libz.a + 1066 ./configure --static --target-list=x86_64-linux-user + 1067 make clean + 1068 ./configure --static + 1069 y search zlib + 1070 y search zlib-static..x86_64 + 1071 y search zlib-static.x86_64 + 1072 y install zlib-static.x86_64 + 1073 ldconfig + 1074 ./configure --static + 1075 ./configure --help + 1076 ./configure --help | grep zlib + 1077 y search zlib + 1078 y install zlib-devel zlib-static zlib + 1079 y deinstall zlib + 1080 y remove zlib + 1081 y search libz + 1082 ls + 1083 git submodule update --init dtc + 1084 ./configure --static --target-list=x86_64-linux-user + 1085 find / -name zlib + 1086 find / -name libz + 1087 find / -name *libz* + 1088 find / -name *zlib* + 1089 ls + 1090 ./configure --disable-zlib-test --static --target-list=x86_64-linux-user + 1091 y search base-devel + 1092 y search devel + 1093 yum groupinstall "Development Tools" + 1094 yum groups mark install + 1095 yum group mark install + 1096 yum groupinstall "Development Tools" + 1097 yum groups mark install + 1098 yum grouplist + 1099 y search zlibrary + 1100 y search glibc + 1101 y install glibc-static + 1102 ls + 1103 ./configure --static --target-list=x86_64-linux-user + 1104 y search glib + 1105 y search glib-2 + 1106 y search glib2-devel + 1107 y install glib2-devel + 1108 ./configure --static --target-list=x86_64-linux-user + 1109 git submodule update --init pixman + 1110 ./configure --static --target-list=x86_64-linux-user + 1111 ls + 1112 ll + 1113 make -j3 + 1114 l + 1115 ldd qemu-nbd + 1116 history + +h2. Quellen + +* "Main Page Dracut on kerne.org":https://dracut.wiki.kernel.org/index.php/Main_Page +* "Documentation on kernel.org":https://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html +* "Enable addional repository":http://www.tecmint.com/enable-rpmforge-repository +* "Getting Dynamic Kernel Module Support":http://rpmfind.net/linux/rpm2html/search.php?query=dkms diff --git a/builder/dnbd3-qcow2-rootfs/scripts/prepare-disks b/builder/dnbd3-qcow2-rootfs/scripts/prepare-disks new file mode 100755 index 00000000..2e68dd9e --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/scripts/prepare-disks @@ -0,0 +1,211 @@ +#!/bin/bash +############################################################################### +# GLOBALS +# + +# flag file containing pids of running instances for concurrency checks +declare -rg OPENSLX_DISK_FLAG="/tmp/openslx.disk" +# file that will contain the name of the device used for the /tmp partition +# - label 'OPENSLX_TMP' in GPT / type '0x44' in MBR +declare -rg OPENSLX_TMP_MARKER="/tmp/openslx.disk.tmp" +# file that will contain the name of the device used for storing qcow2 +# - label 'OPENSLX_SYS' in GPT / type '0x46' in MBR +declare -rg OPENSLX_SYS_MARKER="/tmp/openslx.disk.sys" +# mount point for system partition +declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" + +# +# END GLOBALS +############################################################################### + +############################################################################### +# FUNCTION DEFINITIONS +# +# helper to mount the OPENSLX_SYS partition to /opt/openslx/system +# Usage: mount_sys_part +mount_sys_part() { + if [ ! -b "$1" ]; then + warn "($$) Refusing to mount '$1' as its not a block device!" + return 1 + fi + + local OPENSLX_SYS_DEVICE="$1" + mkdir -p ${OPENSLX_SYS_MOUNT} + if ! mount -t auto "${OPENSLX_SYS_DEVICE}" "${OPENSLX_SYS_MOUNT}"; then + warn "($$) Mounting '${OPENSLX_SYS_DEVICE}' to '${OPENSLX_SYS_MOUNT}' failed." + return 1 + fi + return 0 + +} +# +# generic helper to format the given partition with the given filesystem or +# from the prefdefined list of xfs, ext4, ... +# Usage: format_disk +# e.g. format_disk /dev/sda1 xfs +format_disk () { + local TARGET_DEVICE="$1" + local fslist="xfs ext4" + # if we have a second arguments, its the filesystem of choice + local fs + [ $# -ge 2 ] && fslist="$2" + for fs in $fslist ; do + unset found + local MKFS="$(busybox which mkfs.$fs)" + if [ -n $MKFS ]; then + found=yes + case "mkfs.$fs" in + mkfs.xfs) fopt="-fq" ;; + mkfs.ext4) fopt="-Fq" ;; + esac + info "($$) Formatting $TARGET_DEVICE as $fs" + return $(${MKFS} ${fopt} "${TARGET_DEVICE}") + fi + [ -n "$found" ] && break + done + # still here? then we didn't find a proper formatter... + warn "($$) Could not format $PART_DEV as $fs." + return 1 +} + +# +# END FUNCTION DEFINITIONS +############################################################################### + +############################################################################### +# MAIN CODE +# + +command -v warn >/dev/null || . /lib/dracut-lib.sh + +# let check the arguments +if [ "$#" -ne 2 ]; then + warn "($$) '$0' need 2 arguments: '$0 [OPENSLX_SYS|OPENSLX_TMP] '" + exit 1 +fi +# $1 sane? +if [ "x$1" != "xOPENSLX_SYS" ] && [ "x$1" != "xOPENSLX_TMP" ]; then + warn "($$) First arg needs to be either 'OPENSLX_SYS' or 'OPENSLX_TMP', given: $1" + exit 1 +fi +# $2 sane? +if [ ! -b "/dev/$2" ]; then + warn "($$) Second arg appears not to be a block device!" + exit 1 +fi + +# ok all seems well, set the arguments +PART_TYPE="$1" +PART_DEV="/dev/$2" + +unset OPENSLX_TMP_DEVICE +unset OPENSLX_SYS_DEVICE + +# lets check if we are already running +INSTANCES="$(grep "$PART_TYPE" "$OPENSLX_DISK_FLAG" | busybox wc -l)" +if [ "$INSTANCES" -ge 1 ]; then + # uhoh we are not alone! Need to check + # if the other instance actually did its job + warn "($$) '$0' already running for $PART_TYPE on $PART_DEV... checking state." + # here two/three cases depending on which PART_TYPE we are + # currently processing. + for timeout in 1 1 2; do + # always give the other instance time to finish + # but only check 3 times overall + sleep $timeout + case "$PART_TYPE" in + OPENSLX_TMP) + # was the tmp partition marker created with a device? + if [ ! -f "${OPENSLX_TMP_MARKER}" ]; then + info "($$) Invalid state: no marker for $PART_TYPE" + continue + fi + # it was, is it a valid block device? + OPENSLX_TMP_DEVICE="$(cat ${OPENSLX_TMP_MARKER})" + if [ -z $OPENSLX_TMP_DEVICE -o ! -b $OPENSLX_TMP_DEVICE ]; then + info "($$) Invalid state: no for device $OPENSLX_TMP_DEVICE" + continue + fi + # its detected, its a block device and as mounting is + # done later, we can not check for more at this point + info "($$) Valid state for $OPENSLX_TMP_DEVICE as $PART_TYPE" + exit 0 + ;; + OPENSLX_SYS) + # was the system partition marker created with a device? + if [ ! -f "${OPENSLX_SYS_MARKER}" ]; then + info "($$) Invalid state: no marker for $PART_TYPE" + continue + fi + # it was, is it a valid block device? + OPENSLX_SYS_DEVICE="$(cat ${OPENSLX_SYS_MARKER})" + if [ -z $OPENSLX_SYS_DEVICE -o ! -b $OPENSLX_SYS_DEVICE ]; then + info "($$) Invalid state: no for device $OPENSLX_SYS_DEVICE" + continue + fi + # its detected, its a block device, is it mounted? + if mount | grep -qE "^$OPENSLX_SYS_DEVICE\ on $OPENSLX_SYS_MOUNT"; then + info "($$) Valid state for $OPENSLX_SYS_DEVICE as $PART_TYPE" + exit 0 + fi + # if its not mounted, we want to keep on, so no exit! + ;; + *) + # weird case which should never happen + warn "($$) If you see this, then $0 was called with a bad PART_TYPE: $@" + continue + ;; + esac + done + warn "($$) Timeout reached!" + warn "($$) '$PART_TYPE' was found but not device was associated to it!" +fi + +# We write our pid to $OPENSLX_DISK_FLAG in order to make sure +# we are the only instance of this script running. +info "($$) Processing: $PART_TYPE -> $PART_DEV ($$)" +echo "$PART_TYPE.$$" >> "$OPENSLX_DISK_FLAG" + +# if we are still here, then we can go on and process the partition +if [ "$PART_TYPE" = "OPENSLX_TMP" ]; then + # always format /tmp partition + if ! format_disk "${PART_DEV}" xfs; then + # error while formatting, cleanup + warn "($$) Error formatting $PART_DEV ... removing $$" + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 1 + fi + info "($$) Using '$PART_DEV' as '$PART_TYPE'" + # mark it for later: in pre-pivot we will check this file + # and mount it as $NEWROOT/tmp + echo "$PART_DEV" > "$OPENSLX_TMP_MARKER" + # remove our pid from OPENSLX_DISK_FLAG + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 0 +fi +if [ "$PART_TYPE" = "OPENSLX_SYS" ]; then + # TODO make the formatting of the system partition configurable + if ! format_disk "${PART_DEV}" xfs; then + # error while formatting, cleanup + warn "($$) Error formatting $PART_DEV ... removing $$" + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 1 + fi + # mark it + # mount it now, since qemu-nbd needs it asap! + if mount_sys_part "$PART_DEV"; then + # mount worked, mark it as done + info "($$) Using '$PART_DEV' as '$PART_TYPE'" + echo "$PART_DEV" > "$OPENSLX_SYS_MARKER" + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 0 + else + warn "($$) 'mount_sys_part' failed in $0" + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 1 + fi +fi + +# +# END MAIN CODE +############################################################################### diff --git a/builder/dnbd3-qcow2-rootfs/scripts/setup-qcow2 b/builder/dnbd3-qcow2-rootfs/scripts/setup-qcow2 new file mode 100755 index 00000000..70babc17 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/scripts/setup-qcow2 @@ -0,0 +1,137 @@ +#!/usr/bin/bash + +# dracut-lib to use debugging functions +command -v warn >/dev/null || . /lib/dracut-lib.sh +command -v emergency_shell >/dev/null || . /lib/dracut-lib.sh + +############################################################################### +# GLOBALS +# +# TODO make this configurable +[ -f /opt/openslx/config ] && . /opt/openslx/config +[ -z $SLX_DNBD3_SERVER ] && SLX_DNBD3_SERVER="132.230.4.1" +[ -z $SLX_STAGE4 ] && SLX_STAGE4="stage4/joe/centos7" +[ -z $SLX_STAGE4_RID ] && SLX_STAGE4_RID="4" +declare -rg DNBD3_SERVER="$SLX_DNBD3_SERVER" +declare -rg DNBD3_IMAGE="$SLX_STAGE4" +declare -rg DNBD3_RID="$SLX_STAGE4_RID" +declare -rg DNBD3_DEVICE="/dev/dnbd0" +declare -rg QCOW_CONTAINER="/opt/openslx/system/system.qcow2" +# +# END GLOBALS +############################################################################### + +############################################################################### +# FUNCTION DEFINITIONS +# +# helper to do some sanity checks +check_dnbd3() { + if [ ! command -v "dnbd3-client" >/dev/null ]; then + warn "No 'dnbd3-client' found. Was the initramfs built correctly?" + emergency_shell -n "Error in $0" + return 1 + fi + return 0 +} + +# helper to connect to the dnbd3-server +connect_dnbd3() { + # check if it already connected + local current_image_name="$(cat /sys/block/${DNBD3_DEVICE#/dev/}/net/image_name)" + [ "x${current_image_name}" != "x(null)" ] && return 0 + + # not connected yet, do it + if ! dnbd3-client -h "${DNBD3_SERVER}" \ + -i "${DNBD3_IMAGE}" \ + -r "${DNBD3_RID}" \ + -d "${DNBD3_DEVICE}" ; then + warn "Failed to mount $DNBD3_IMAGE from $DNBD3_SERVER to $DNBD3_DEVICE" + emergency_shell -n "Error in $0" + return 1 + fi + return 0 +} + +# helper to create the qcow2 container file using +# DNBD3_DEVICE as the base of the filesystem +# QCOW_CONTAINER as the writable file +# (our future rootfs) +create_qcow() { + # check if we already created the qcow2-container + [ -e "$QCOW_CONTAINER" ] && return 0 + + # check if we have our target directory, if not create it + [ ! -d "$(busybox dirname $QCOW_CONTAINER)" ] && \ + mkdir -p "$(busybox dirname $QCOW_CONTAINER)" + + # we did not, let's create it + if ! qemu-img create -f qcow2 -o \ + backing_file="$DNBD3_DEVICE",backing_fmt=qcow2 "$QCOW_CONTAINER"; then + warn "Failed to create qcow2-Container from $DNBD3_DEVICE" + emergency_shell -n "Error in $0" + rm -f -- "$QCOW_CONTAINER" + return 1 + fi + return 0 +} +# helper to start qemu-nbd on localhost:2000 +# use our wrapper to set argv[0][0] to '@' +# this keeps qemu-nbd running after switching root +export_qcow() { + # check if we already have a qemu-nbd + if [ -e /tmp/qemu-nbd.pid ]; then + kill -0 $(cat /tmp/qemu-nbd.pid) && return 0 + fi + # since we use the wrapper, we need a little more logic to see if it runs + /usr/bin/systemd-preserve-process-marker \ + /usr/bin/qemu-nbd -t -p 2000 "$QCOW_CONTAINER" & + # the wrapper returns 255 if the qemu-nbd binary is missing + local qemu_nbd_pid="$!" + for i in 0.5 1 2; do + sleep $i + if ! kill -0 $qemu_nbd_pid; then + # not running + wait $qemu_nbd_pid + local ret_wrapper="$?" + if [ "${ret_wrapper}" -eq 127 ]; then + # wrapper was not found by bash + warn "No such file or directory: /usr/bin/systemd-preserve-process-marker" + elif [ "${ret_wrapper}" -eq 255 ]; then + # qemu-nbd was not found + warn "No such file or directory: /usr/bin/qemu-nbd" + fi + emergency_shell -n "Error in $0" + return 1 + else + # all good, qemu-nbd is running, remember its pid + echo $qemu_nbd_pid > /tmp/qemu-nbd.pid + return 0 + fi + done + # fallback + return 1 +} +# helper to mount the qcow2-container per nbd +connect_qcow() { + # try to mount the locally exported qcow2-container using nbd-client + if /usr/bin/systemd-preserve-process-marker \ + nbd-client --persist 127.0.0.1 2000 /dev/nbd0; then + # it worked, lets set the symlink to /dev/root as dracut needs it + # later on to mount that device to the future root (/sysroot) + ln -sf /dev/nbd0 /dev/root + return 0 + else + # this is pretty bad, dracut would spawn an emergency later on + # since there is no /dev/root to mount. + # For debugging purposes, we drop an emergency shell ourselves + # if the mount fails. + warn "Could not mount /dev/nbd0 from 127.0.0.1:2000." + emergency_shell -n "Error in $0" + return 1 + fi +} +# +# END FUNCTION DEFINITIONS +############################################################################### + +# No main, use functions! diff --git a/builder/dnbd3-qcow2-rootfs/systemd-preserve-process-marker.c b/builder/dnbd3-qcow2-rootfs/systemd-preserve-process-marker.c new file mode 100644 index 00000000..8f0fc108 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/systemd-preserve-process-marker.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +void print_array(int argc, char *argv[]) { + // Helper function to print given array with given length. + int i = 0; + int j = 0; + for (i = 0; i < argc; i ++) { + j = 0; + while(argv[i][j] != '\0') + printf("%c", argv[i][j++]); + printf(" "); + } + printf("\n"); +} +int main(int argc, char *argv[]) { + int count; + // Last item acts as null pointer. + char **copy = calloc(sizeof(char *), argc); + // Slice first given command line argument. + for (count = 0; count < argc - 1; count++) + copy[count] = strdup(argv[count + 1]); + // Adding systemd indicator to preserve wrapped process during changing + // root filesystem. We mark wrapper and child process. + argv[0][0] = '@'; + copy[0][0] = '@'; + if (-1 == execvp(argv[1], copy)) { + perror("Executing child process failed."); + return -1; + } +} diff --git a/builder/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules b/builder/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules new file mode 100644 index 00000000..3f5e382f --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules @@ -0,0 +1,8 @@ +# GPT rules +KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="gpt" ENV{ID_PART_ENTRY_NAME}=="OPENSLX_TMP" RUN+="/sbin/prepare-disks %E{ID_PART_ENTRY_NAME} %k" +KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="gpt" ENV{ID_PART_ENTRY_NAME}=="OPENSLX_SYS" RUN+="/sbin/prepare-disks %E{ID_PART_ENTRY_NAME} %k" + +# MBR rules +KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="dos" ENV{ID_PART_ENTRY_TYPE}=="0x44" RUN+="/sbin/prepare-disks OPENSLX_TMP %k" +KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="dos" ENV{ID_PART_ENTRY_TYPE}=="0x46" RUN+="/sbin/prepare-disks OPENSLX_SYS %k" + diff --git a/dracut/INSTALL b/dracut/INSTALL deleted file mode 100644 index e52f0c39..00000000 --- a/dracut/INSTALL +++ /dev/null @@ -1,19 +0,0 @@ -This subfolder is dedicated to dracut related files. - -The folder 'dnbd3-qcow2-rootfs' is a dracut module used to setup -a client's rootfs based on a (read-only) dnbd3 export made writable -through the qcow2 container format of the qemu ecosystem. - -To use this module within dracut, you simply need to copy/link/mount -the above mentioned folder to '/usr/lib/dracut/modules.d' prefixed -with a numerical priority. We used '90' so far, so the module was linked -to '/usr/lib/dracut/modules.d/90dnbd3-qcow2-rootfs'. - -Once the module has been integrated in dracut's modules, you can build -the initramfs with the following command: - - dracut --no-hostonly --modules "dnbd3-qcow2-rootfs" - -Note that the '--no-hostonly' is critical if the machine dracut is -executed on and the clients supposed to boot the resulting initramfs -differ. diff --git a/dracut/dnbd3-qcow2-rootfs/TODO b/dracut/dnbd3-qcow2-rootfs/TODO deleted file mode 100644 index 2e92a1d0..00000000 --- a/dracut/dnbd3-qcow2-rootfs/TODO +++ /dev/null @@ -1,5 +0,0 @@ -* Dynamic building of dnbd3 / nbd kernel modules -* Dynamic building of dnbd3-client / systemd-preserver-process-marker - -* Research whether the dracut busybox module satisfies our requirements -* If not, compiling busybox should be done somehow diff --git a/dracut/dnbd3-qcow2-rootfs/binaries/busybox b/dracut/dnbd3-qcow2-rootfs/binaries/busybox deleted file mode 100755 index 7eceacf7..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/binaries/busybox and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/binaries/dnbd3-client b/dracut/dnbd3-qcow2-rootfs/binaries/dnbd3-client deleted file mode 100755 index 76924b49..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/binaries/dnbd3-client and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/binaries/systemd-preserve-process-marker b/dracut/dnbd3-qcow2-rootfs/binaries/systemd-preserve-process-marker deleted file mode 100755 index 45beb51d..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/binaries/systemd-preserve-process-marker and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/busybox b/dracut/dnbd3-qcow2-rootfs/debugging_tools/busybox deleted file mode 100755 index 1212ae20..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/debugging_tools/busybox and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/endless b/dracut/dnbd3-qcow2-rootfs/debugging_tools/endless deleted file mode 100755 index de7a8c0a..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/debugging_tools/endless and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/endless.c b/dracut/dnbd3-qcow2-rootfs/debugging_tools/endless.c deleted file mode 100644 index 22c9bc50..00000000 --- a/dracut/dnbd3-qcow2-rootfs/debugging_tools/endless.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include -#include - -int main(int argc, char *argv[]) { - // Provides a dummy worker. - while (1) - sleep(999999999); -} diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/nbd-client b/dracut/dnbd3-qcow2-rootfs/debugging_tools/nbd-client deleted file mode 100755 index 7bb2207f..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/debugging_tools/nbd-client and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko b/dracut/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko deleted file mode 100644 index 47cf6cd6..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/network.functions b/dracut/dnbd3-qcow2-rootfs/debugging_tools/network.functions deleted file mode 100644 index 89ca5a20..00000000 --- a/dracut/dnbd3-qcow2-rootfs/debugging_tools/network.functions +++ /dev/null @@ -1,23 +0,0 @@ -wait_for_iface() { - local DEVICE=$1 - local TIMEOUT=10 - echo -n "Waiting for interface $DEVICE: " - # Some systems don't have operstate. Seems to be hardware dependent - [ ! -e "/sys/class/net/${DEVICE}/operstate" ] && usleep 10000 - if [ -e "/sys/class/net/${DEVICE}/operstate" ]; then - while true; do - # check linkstate - [ "x$(cat "/sys/class/net/${DEVICE}/operstate")" == "xup" ] && break - TIMEOUT=$(( $TIMEOUT - 1 )) # don't wait forever, the pcnet iface of vmware will never be "up" although it's working - [ "$TIMEOUT" -le 0 ] && break - # else - echo -n "." - usleep 500000 - done - else - # we really don't have a operstate .. then just wait a sec and hope for the best. - sleep 1 - fi - echo ".$(cat "/sys/class/net/${DEVICE}/operstate" 2>/dev/null)" -} -true diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd b/dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd deleted file mode 100755 index b34a3ff7..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark b/dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark deleted file mode 100755 index 03c2a6b1..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh b/dracut/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh deleted file mode 100644 index 3b32a68c..00000000 --- a/dracut/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash - -echo "Setting up network..." - -echo "Main MAC address is '$MAC'" - -# setup network -source /inc/network.functions - -# set up loopback networking -echo "Setting up loopback" -ip link set dev lo up 2>/dev/null -ip addr add 127.0.0.1/8 dev lo 2>/dev/null - -echo "Setting up bridge" -BRIDGE="br0" - -# Following was supposed to prevent scripts from getting confused by multiple interfaces with same MAC - does not work though -## Flip mac address of original interface - this var is not local so init sees the changes too -#MAC="$(echo "$MAC" | awk -F ':' '{printf $1 ":" $2 ":" $5 ":" $3 ":" $6 ":" $4}')" -#ip link set addr "$MAC" "$SLAVE" - -mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d" - -#IP_OUT=$(ip a | sed -r ':a;N;$!ba;s/: ([a-z0-9]+): /####\1####/g;s/ether ([a-f0-9:]+) /####\1####/g'| grep -E -o '####[^ ]+####' | sed 's/#//g' | grep -B 1 ':') -IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#') - -if ! echo "$IP_OUT" | grep -q -- "$MAC"; then - drop_shell "Boot interface not found in interface list. NIC driver missing?" -fi - -for LINE in $IP_OUT; do - IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}') - IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[A-Z]' '[a-z]') # udev requires mac addesses to be lowercase (a-f), see http://www.debianhelp.co.uk/udev.htm - echo "${IFACE} = ${IFMAC}" - - if [ "x$IFMAC" == "x$MAC" ]; then - brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE" - brctl stp "$BRIDGE" 0 - brctl setfd "$BRIDGE" 0.000000000001 - ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE" - ip link set dev "$IFACE" up - wait_for_iface "$IFACE" - brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE" - - # save our variables for retry on fail - echo "IFACE=$IFACE" > /run/network.conf - - # analyze ip information from the kernel command line and put parts - # of it into several variables - if [ -n "$CLIENTIP" ] ; then - # set static ip address - ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE" - ip link set dev "$BRIDGE" up - [ -n "$GATEWAY" ] && ip route add default via "$GATEWAY" dev "$BRIDGE" - else - NOIPYET="yes" - fi - # Ignore this device later on when systemd handles network interfaces (see hacked 99-systemd.rules in systemd data dir) - echo "SUBSYSTEM==\"net\", ACTION==\"add\", KERNEL==\"eth*\", ATTR{address}==\"$IFMAC\", TAG+=\"openslxignore\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/01-ignore-boot-interface.rules" - fi - # youdev - echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$IFMAC\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$IFACE\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/70-net-boot-nic-name.rules" - # continue... - IFACE="" -done - -wait_for_iface "$BRIDGE" - -# udhcpc -PARAM= -if [ -n "$CLIENTIP" ]; then - PARAM="-r $CLIENTIP" -fi -echo -n "$CLIENTIP" > "/run/firstip" -echo -n "$GATEWAY" > "/run/firstgw" - -# save our variables for retry on fail ff. -echo "CLIENTIP=$CLIENTIP" >> /run/network.conf -echo "GATEWAY=$GATEWAY" >> /run/network.conf -echo "BRIDGE=$BRIDGE" >> /run/network.conf - -udhcpc $PARAM -O domain -O nissrv -O nisdomain -O wpad -O search -t 5 -T 2 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" -# udhcpc return value will be return value of this script diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/enable-sysrq.sh b/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/enable-sysrq.sh deleted file mode 100755 index f779aa7a..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/enable-sysrq.sh +++ /dev/null @@ -1,2 +0,0 @@ -# enables magic sysrq keys -echo 1 > /proc/sys/kernel/sysrq diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/expand-kcl-ip.sh b/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/expand-kcl-ip.sh deleted file mode 100755 index 9f617b09..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/expand-kcl-ip.sh +++ /dev/null @@ -1,36 +0,0 @@ -command -v warn >/dev/null || . /lib/dracut-lib.sh - -# fakes the cmdline to fix the ip parsing in darcut's net-lib.sh -[ -d /fake ] || mkdir /fake - -# need to be a tmpfs for the hack to work -mount -t tmpfs tmpfs /fake - -for parameter in $(getargs ip=); do - local temp="$parameter:" - set -- - while [ -n "$temp" ]; do - set -- "$@" "${temp%%:*}" - temp=${temp#*:} - done - - [ -n "$1" ] && ip=$1 - [ -n "$2" ] && server_ip=$2 - [ -n "$3" ] && gateway_ip=$3 - [ -n "$4" ] && net_mask=$4 - - warn "PXE given net configuration: ip: $ip server_ip: $server_ip gateway_ip: $gateway_ip net_mask: $net_mask" - local final_dracut_ip_config="$ip::$gateway_ip:$net_mask:hiwi-test-28:eno1:none" - warn "Final dracut ip config: $final_dracut_ip_config" - sed --regexp-extended "s/ip=[^ ]*/ip=$final_dracut_ip_config/g" /proc/cmdline > /fake/cmdline -done - - -# bind mount it. Can we trust mount return codes here? -# # if so, we should check what we get in $? -mount -o bind /fake/cmdline /proc/cmdline - -# check if it worked -if ! grep 'hiwi-test-28:eno1:none' /proc/cmdline; then - warn 'Haxing cmdline did not work :( sad pandaz...' -fi diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/mark-root-device.sh b/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/mark-root-device.sh deleted file mode 100755 index b7282521..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/cmdline/mark-root-device.sh +++ /dev/null @@ -1,9 +0,0 @@ -# set rootok and root as dracut expects them to be set by -# the module preparing the root filesystem. -# -# Once the root filesystem is mounted per dnbd3 and -# exported as qcow2 per nbd, /dev/root will be a symlink -# to /dev/nbd0 as this is then our rootfs-device -rootok=1 -root=block:/dev/root - diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/mount/mount-root-device.sh b/dracut/dnbd3-qcow2-rootfs/hooks/mount/mount-root-device.sh deleted file mode 100755 index d02f9002..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/mount/mount-root-device.sh +++ /dev/null @@ -1,4 +0,0 @@ -# this rudimentary script just mounts the rootfs device that was symlinked to -# /dev/root to dracut's $NEWROOT (usually /sysroot). - -mount /dev/root $NEWROOT diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/pre-mount/fetch-config.sh b/dracut/dnbd3-qcow2-rootfs/hooks/pre-mount/fetch-config.sh deleted file mode 100755 index a90481c8..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/pre-mount/fetch-config.sh +++ /dev/null @@ -1,39 +0,0 @@ -# load dracut functions -command -v getarg >/dev/null || . /lib/dracut-lib.sh - -# read SLX_SERVER and SLX_BASE from the kernel command line -SLX_SERVER=$(getarg slxsrv) -SLX_BASE=$(getarg slxbase) -SLX_CONFIG_DIR="/opt/openslx" -SLX_CONFIG_FILE="/opt/openslx/config" - -if [ -z "$SLX_SERVER" ]; then - warn "No 'slxsrv' parameter found in the kernel command line!" - warn "Skipping OpenSLX configuration..." - return 1 -fi -if [ -z "$SLX_BASE" ]; then - warn "No 'slxbase' parameter found in the kernel command line!" - warn "Skipping OpenSLX configuration..." - return 1 -fi - -info "Getting configuration from OPENSLX-Server..." -WGET="$(busybox which wget)" -if [ -z $WGET ]; then - # do nothing - warn "'wget' not found. Skipping openslx configuration..." - return 1 -fi - -# ok then we are ready to download the config -mkdir -p "${SLX_CONFIG_DIR}" -$WGET -T 5 -q "http://${SLX_SERVER}/${SLX_BASE}/config" -O "${SLX_CONFIG_FILE}" -RET="$?" -if [ $RET -ne 0 ]; then - warn "Downloading OpenSLX configuration from ${SLX_SERVER}/${SLX_BASE} failed: $RET" - emergency_shell -n "$0" - return 1 -else - return 0 -fi diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/pre-mount/mount-qcow.sh b/dracut/dnbd3-qcow2-rootfs/hooks/pre-mount/mount-qcow.sh deleted file mode 100755 index d70492bf..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/pre-mount/mount-qcow.sh +++ /dev/null @@ -1,49 +0,0 @@ -############################################################################### -# CHECKS -# - -SETUP_ROOTFS_SCRIPT="/sbin/setup-qcow2" - -if [ ! -e "${SETUP_ROOTFS_SCRIPT}" ]; then - warn "No such file of directory: ${SETUP_ROOTFS_SCRIPT}" - emergency_shell -n "Error in $0" - return 1 -fi - -if [ ! -x "${SETUP_ROOTFS_SCRIPT}" ]; then - warn "Cannot execute: ${SETUP_ROOTFS_SCRIPT}" - emergency_shell -n "Error in $0" - return 1 -fi - -# -# END CHECKS -############################################################################### - -############################################################################### -# MAIN CODE -# - -# ok, let's source the setup script -if ! . ${SETUP_ROOTFS_SCRIPT} ; then - warn "Could not source: ${SETUP_ROOTFS_SCRIPT}" - emergency_shell -n "Error in $0" - return 1 -fi - -# just go over the functions in the right order ;-) -for fun in connect_dnbd3 create_qcow export_qcow connect_qcow; do - if ! $fun; then - # something failed, drop a shell for debugging - warn "'$fun' failed with: $?" - emergency_shell -n "Error in $fun" - return 1 - fi -done - -# all good, we are done -return 0 - -# -# END MAIN CODE -############################################################################### diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/pre-pivot/mount-tmp.sh b/dracut/dnbd3-qcow2-rootfs/hooks/pre-pivot/mount-tmp.sh deleted file mode 100755 index 3e702064..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/pre-pivot/mount-tmp.sh +++ /dev/null @@ -1,40 +0,0 @@ -# This script only checks if we found a usable partition for the -# future /tmp. The discovery of that partition is done by udev during -# the initqueue. If a valid partition is found (either GPT with the label -# OPENSLX_TMP or MBR with the type 0x44) its path will be written to -# /tmp/openslx.tmpdisk -OPENSLX_TMP_DISK_FLAG="/tmp/openslx.disk.tmp" - -if [ ! -e "$OPENSLX_TMP_DISK_FLAG" ]; then - warn "'$OPENSLX_TMP_DISK_FLAG' not found!" - warn "Systemd will manage $NEWROOT/tmp on its own." - # no partition for the future /tmp found, just - # let systemd manage it then (probably a tmpfs) - return 1 -fi - -# in /tmp/openslx.disk.tmp is the name of the device -# to mount as /tmp in the real system -# meaning we need to mount it to /sysroot/tmp here. - -OPENSLX_TMP_DISK_DEV="$(cat $OPENSLX_TMP_DISK_FLAG)" - -# sanity check: is the content a block device? -if [ ! -b "$OPENSLX_TMP_DISK_DEV" ]; then - warn "'$OPENSLX_TMP_DISK_DEV' appears not to be a block device!" - warn "Systemd will manage $NEWROOT/tmp on its own." - return 1 -fi - -# all good, keep on -if ! mount -t auto "$OPENSLX_TMP_DISK_DEV" $NEWROOT/tmp; then - # something else went wrong :( - warn "Mounting '$OPENSLX_TMP_DISK_DEV' to '$NEWROOT/tmp' failed with: $!" - warn "Systemd will manage $NEWROOT/tmp on its own." - return 1 -fi - -# still here? mount worked wohoo -# set permissions -chmod a+rwxt $NEWROOT/tmp -return 0 diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh b/dracut/dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh deleted file mode 100755 index 9103afd9..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/pre-udev/lo-setup.sh +++ /dev/null @@ -1 +0,0 @@ -/sbin/initqueue --name ifup-lo --unique --onetime /sbin/ifup lo -m diff --git a/dracut/dnbd3-qcow2-rootfs/hooks/pre-udev/load-dnbd3-nbd-modules.sh b/dracut/dnbd3-qcow2-rootfs/hooks/pre-udev/load-dnbd3-nbd-modules.sh deleted file mode 100755 index 29f9f210..00000000 --- a/dracut/dnbd3-qcow2-rootfs/hooks/pre-udev/load-dnbd3-nbd-modules.sh +++ /dev/null @@ -1,32 +0,0 @@ -# include dracut-lib.sh to use 'warn' -command -v warn >/dev/null || . /lib/dracut-lib.sh - -NBD_MOD_PATH="/usr/lib/modules/current/extra/nbd.ko" -DNBD3_MOD_PATH="/usr/lib/modules/current/extra/dnbd3.ko" - -# do we actually have our modules? -if [ ! -e "${NBD_MOD_PATH}" ]; then - warn "No such file of directory: ${NBD_MOD_PATH}" - emergency_shell -n "Error in $0" - return 1 -fi -if [ ! -e "${DNBD3_MOD_PATH}" ]; then - warn "No such file of directory: ${DNBD3_MOD_PATH}" - emergency_shell -n "Error in $0" - return 1 -fi - -# load the kernel modules for dnbd3 and nbd -if ! insmod "${DNBD3_MOD_PATH}"; then - warn "Failed to load DNBD3 kernel module..." - emergency_shell -n "Error in $0" - return 1 -fi - -if ! insmod "${NBD_MOD_PATH}"; then - warn "Failed to load NBD kernel module..." - emergency_shell -n "Error in $0" - return 1 -fi - -return 0 diff --git a/dracut/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko b/dracut/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko deleted file mode 100755 index d7b7ce3b..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/kernel_modules/dnbd3.ko and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko b/dracut/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko deleted file mode 100644 index e8c3f40f..00000000 Binary files a/dracut/dnbd3-qcow2-rootfs/kernel_modules/nbd.ko and /dev/null differ diff --git a/dracut/dnbd3-qcow2-rootfs/module-setup.sh b/dracut/dnbd3-qcow2-rootfs/module-setup.sh deleted file mode 100644 index b3f14c1d..00000000 --- a/dracut/dnbd3-qcow2-rootfs/module-setup.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash - -check() { - if ! type -f qemu-nbd >/dev/null; then - echo "'qemu-nbd' not found on this system, install it to use this module." - return 1 - fi - if ! type -f qemu-img >/dev/null; then - echo "'qemu-img' not found on this system, install it to use this module." - return 1 - fi - if ! type -f nbd-client >/dev/null; then - echo "'nbd-client' not found on this system, install it to use this module." - return 1 - else - # check version - local nbd_client_version="$(nbd-client --help 2>&1 | grep -oE '3\.[0-9]+')" - local nbd_client_version_major="${nbd_client_version%.*}" - local nbd_client_version_minor="${nbd_client_version#*.}" - if [ "${nbd_client_version_major}" -ne 3 ]; then - # nbd-client probably too old - echo "The nbd-client major version is not 3, meaning its probably too old." - return 1 - fi - if [ "${nbd_client_version_minor}" -gt 8 ]; then - # TODO check if ver = 3.9 has the same new syntax... - echo "The nbd-client minor version is greater than 8. A new syntax has been - introduced starting with 3.10 which we do not support." - return 1 - fi - return 0 - fi -} - -depends() { - echo base network bash kernel-modules - return 0 -} - -installkernel() { - instmods ext4 -} - -install() { - ### BINARIES - # - # busybox: cause we want lightweight tools - inst "$moddir/binaries/busybox" /usr/bin/busybox - # dnbd3-client: needed to mount remote dnbd3 filesystem. - inst "$moddir/binaries/dnbd3-client" /usr/bin/dnbd3-client - # A generic wrapper program to prepend a "@" to each process - # spawned by given nested programs. - inst "$moddir/binaries/systemd-preserve-process-marker" \ - /usr/bin/systemd-preserve-process-marker - - # NOTE: These modules are build again Kernel: 3.10.0-229.1.2.el7.x86_64 - # TODO: build these in check() ! - inst "$moddir/kernel_modules/dnbd3.ko" \ - /usr/lib/modules/current/extra/dnbd3.ko - inst "$moddir/kernel_modules/nbd.ko" \ - /usr/lib/modules/current/extra/nbd.ko - - ### HOOKS - ## HOOK cmdline - # enables sysrq-shortcuts - inst_hook cmdline 00 "$moddir/hooks/cmdline/enable-sysrq.sh" - - # expands the ip parameter in the kernel command line to - # make it dracut-compatible - # TODO: dracut still parses this incorrectly... - inst_hook cmdline 10 "$moddir/hooks/cmdline/expand-kcl-ip.sh" - - # sets environment variables to tell dracut which device - # holds the future root filesystem - inst_hook cmdline 90 "$moddir/hooks/cmdline/mark-root-device.sh" - - ## HOOK pre-udev - # loads the dnbd3/nbd kernel modules - inst_hook pre-udev 00 "$moddir/hooks/pre-udev/load-dnbd3-nbd-modules.sh" - - # setup loopback device - inst_hook pre-udev 00 "$moddir/hooks/pre-udev/lo-setup.sh" - - ## HOOK pre-mount - # this is the configuration hook where the config stuff is wget'ed - inst_hook pre-mount 00 "$moddir/hooks/pre-mount/fetch-config.sh" - - # this is the main hook where all the magic is triggered - inst_hook pre-mount 10 "$moddir/hooks/pre-mount/mount-qcow.sh" - - ## HOOK mount - # this simply mounts the prepared /dev/root to $NEWROOT - # aka "the dracut way" - inst_hook mount 10 "$moddir/hooks/mount/mount-root-device.sh" - - ## HOOK pre-pivot - # this checks whether we found a partition suitable for - # the future /tmp and if so, mounts it - inst_hook pre-pivot 00 "$moddir/hooks/pre-pivot/mount-tmp.sh" - - ### SCRIPTS - # the main magic script containing all the functions needed - # to prepare the qcow2-based root filesystem - inst "$moddir/scripts/setup-qcow2" /sbin/setup-qcow2 - - # the script triggered by udev upon finding the right partitions - inst "$moddir/scripts/prepare-disks" /sbin/prepare-disks - - # udev rules detecting 44, 45, 46 partitions and running - # 'prepare-disks' to do then format/mount/use them - inst "$moddir/udev/70-openslx-disk.rules" /etc/udev/rules.d/70-openslx-disk.rules - - # Debugging Uncomment this version if you need some useful debugging tools - # in your iniramfs. - inst_multiple lsblk ping ip ifconfig sshd htop tail head cat vim \ - touch sed lsmod insmod qemu-img sleep route wget find lsof strace \ - chroot switch_root pivot_root qemu-nbd mount nbd-client fdisk mkfs.xfs - # Production: - # inst_multiple insmod qemu-img qemu-nbd - return 0 -} diff --git a/dracut/dnbd3-qcow2-rootfs/readme.md b/dracut/dnbd3-qcow2-rootfs/readme.md deleted file mode 100644 index 9ad0f968..00000000 --- a/dracut/dnbd3-qcow2-rootfs/readme.md +++ /dev/null @@ -1,472 +0,0 @@ -# TODO --ommit npd -# TODO Testmenue PW: t - -h1. Evaluation, dissection and modification of Linux remote boot - -h2. Inhalt - -{{toc}} - -#h2. Begriffe - -#* qcow - qemu copy-on-write -#* stage3.1 initramfs -#* stage4 finales System - -h2. Aufgabe - -Es wird ein Skript bzw. Dracut-Modul benötigt, dass ein initramfs basierend auf -systemd baut. Das resultierende initramfs muss Netzwerk-Support bereitstellen, -ein dnbd3 Blockdevice mounten können und einen "switch_root" auf das zuvor -gemountete Dateisystem umsetzen. Das Framework sollte möglichst -Distributionsunabhängig konstruiert sein. Es soll bereits vor dem -"switch_root", also bevor das eigentliche Zielsystem im Root-Verzeichnis -eingebunden werden systemd als init-System zum Einsatz kommen. Die Kernaufgabe -eine initramfs ist es alle nötigen Anwendungen bereitzustellen, die benötigt -werden, um dass finale Zielsystem einzubinden. In dieser konkreten -Aufgabenstellung muss, dass initramfs ein nicht schreibbares Blockgerät -eingebunden werden und eine schreibbare Zwischenshicht (Overlayfilesystem) -zusätzlich eingebunden werden. - -h2. Möglicher Technologien für das Overlaykonzept - -* Dateibasierte Overlay-FS (Union-FS, Alternat-Union-FS, Overlay-FS) - - Funktioniert derzeit nicht auf jedem Zielsystem (Kernel) - - Nicht für den Linux-Kernel zertifiziert oder lässt sich nicht über das - Root-System legen. - - Bei wenigen Änderungen in einer großen Datei muss komplette Datei in - der schreibbaren Schicht gespeichert werden. -* Blockorientierte Overlay-FS (Network-Block-Device, DNBD3, Qemu-Copy-On-Write-Image) - - NBD ist für den Linux-Kernel zertifiziert - - Weniger Netzwerkverkehr nötig, da nur geänderte Blöcke übertragen werden - müssen, statt ganze Dateien zu kopieren. - - DNBD3 hat Failover-Strategien, verzichtet auf komplexe Strategien zum - Schreiben in geänderte Blöcke über das Netzwerk - - Das verfügbare qcow2-Format bietet eine Technologie, um blockorientiert - Änderungen in einer zusätzlichen Dateisystemschicht zu speichern. - -h2. Zielablauf - -Der generelle Ablauf vor bzw. während des Ladens des initramfs und deren -Minilinux-System: - -# Boot PXE -> # Laden des initramfs images -> # Laden des Kernels -# Ausführen des iniramfs -> # Ausführen von Systemd -> > # Bereitstellen aller benötigten Dienste und Hardware (Netzwerk hochbringen) -> > # Mounten des finalen Dateisystems als Wurzel -> > # Wechsel (switch_root) in die finale Distribution -> > # Starten / Weiterausführen von Systemd als Init-System - -h2. Benötigte Pakete zum bauen des initramfs - -> * dracut -# TODO - -h2. Benötigte Pakete innerhalb des resultierenden initramfs - -> * systemd -> * quemu-img -> * quemu-nbd -> * nbd-client -> * dnbd3-client - -h2. Aufsetzen einer Test-Arbeitsumgebung für CentOS - -h3. CentOS7/ArchLinux/RedHat/Ubuntu + VirtualBox + VirtualBoxGuestAdditions - -Aufsetzen des *Dynamic Kernel Module Support*, um einfach neue VBox-Kernel-Module zu aktualisieren: - -> # Aktualisiere Paketdatenbank: @yum update@ -> # Intalliere C-Compiler: @yum install gcc@ -> # Lade erweitertes rpmforfe Repository: @wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm@ -> # Installiere Repository: @rpm -Uvh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm@ -> # Lade das DKMS-Paket: @wget ftp://rpmfind.net/linux/epel/5/x86_64/dkms-2.2.0.3-29.el5.noarch.rpm@ -> # Installiere DKMS-Paket: @yum localinstall dkms-2.2.0.3-25.el7.noarch.rpm --nogpgcheck@ -> # Aktiviere rpmforge Repository: @yum --enablerepo rpmforge install dkms@ -> # Installiere Entwicklertools zum bauen von Paketen: @yum groupinstall "Development Tools"@ -> # Installiere Metainformation zum Kernel: @yum install kernel-devel@ - -Installieren der VirtualBox-GuestAddtion: - -> # Lege die VirtualBox-GuestAddition-CD ein. -> # Mounte CD: @mount /dev/sr0 /mnt/ && cd /mnt/ && ./VBoxLinuxAdditions.run && reboot@ - -Erstellen eines Testboot Eintrags für Grub2: - -> - Füge in ??/etc/grub.d/40_custom?? den folgenden Inhalt hinzu: - -
-menuentry 'test' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.el7.x86_64-advanced-6c06919a-389a-4a50-8c6b-b086e65db9b0' {
-    load_video
-    set gfxpayload=keep
-    insmod gzio
-    insmod part_msdos
-    insmod xfs
-    set root='hd0,msdos1'
-    if [ x$feature_platform_search_hint = xy ]; then
-        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  4236333a-a808-4f6b-b4a6-d963f4a69a25
-    else
-        search --no-floppy --fs-uuid --set=root 4236333a-a808-4f6b-b4a6-d963f4a69a25
-    fi
-    linux16 /vmlinuz-3.10.0-123.el7.x86_64 root=UUID=6c06919a-389a-4a50-8c6b-b086e65db9b0 ro rd.lvm.lv=centos/swap crashkernel=auto  rd.lvm.lv=centos/root vconsole.font=latarcyrheb-sun16 vconsole.keymap=de rhgb quiet 
-    initrd16 /initramfs-test.img
-}
-
- -> - Füge neuen Menüeintrag in die automatisch generierte Grub2 Konfigurations2-Datei hinzu: @grub2-mkconfig -o /boot/grub2/grub.cfg@ - -h2. Bauen eines Test-Initramfs - -Mache ein Backup vom aktuellen initamfs: -@cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.BACKUP@ - -Der folgende Befehl ersetzt das aktuelle Standart Initramfs mit dem neu -gebauten und berücksichtigt dabei alle bisher editierten Dracut-Module in -??/usr/lib/dracut/modules.d??. Die durchschnittliche Größe des resultierenden -initramfs beträgt komprimiert: zwischen 11 und 16 MB. - -

-dracut --verbose --force /boot/initramfs-3.10.0-123.el7.x86_64.test.img \
-    3.10.0-123.el7.x86_64
-
- -h3. Konfiguration - -TODO - -# Configure "cmdline" from "Chapter 8. DRACUT.CMDLINE(7)" in virtualbox in "/boot/startup.sh" for uefi or in "/boot/grub2/grub.cfg" for grub2 - -h2. Bauen eines minimalen individuellen Test-Initramfs - -

-dracut --verbose --hostonly --force 
-    /boot/initramfs-3.10.0-123.el7.x86_64.test.img \
-    3.10.0-123.el7.x86_64
-
- -Die Option "hostonly" veranlasst Dracut dazu nur alle nötigen Abhängigkeiten -für das aktuelle System in das resultierende Initramfs zu installieren. -Andernfalls fügt dracut viele zusätzliche Treiber hinzu, die die Größe der -resultierenden Datei erheblich vergrößern und damit größer wird als nötig. -Die durchschnittliche Größe des resultierenden initramfs beträgt -komprimiert: zwischen 11 und 16 MB. - -h2. Erstellen eines eigenen Dracut-Moduls - -Alle vorhanden Module befinden sich in ??/usr/lib/dracut/modules.d??. - -> # Erstelle ein neues Modul: @mkdir /usr/lib/dracut/modules.d/91test@ -> # Baue neues initramfs und achte darauf, dass ??\*\*Including module: test\*\*?? mit der Command-Line-Option ??--verbose?? ausgegeben wird. -> # Alle Modul-Installations-Informationen sind in der Datei ??module-setup.sh??: @touch /usr/lib/dracut/modules.d/91test/module-setup.sh@ -> # Konfiguriere Modul: -> > # Als erstes erstellt man eine ??check??-Funktion, die lediglich ??0?? - zurückgibt. Diese Funktion wird aufgerufen, wenn entschieden wird, welche - Dracutmodule geladen werden sollen. Durch zurückgeben der ??0?? wird das - Modul beim nächsten bauen eines Initramfs automatisch hinzugefügt ohne - das man es etwas in der ??/etc/dracut.conf?? oder per Command-Line-Option - "--add" angeben muss. Wenn die @$hostonly@ Variable gesetzt ist, dann - wird das Modul auch im "hostonly" Modus geladen. In diesem Fall sollte - die Funktion nur dann ??0?? zurückgeben, wenn das Modul auch wircklich - für den aktuellen Host benötigt wird. Wenn 255 zurückgegeben wird, wird - das Modul nur dann geladen, wenn es von einem andren Modul als - Abhängigkeit deklariert wurde. - -

-check() {
-    return 0
-}
-
- -Als nächstes wird eine ??install??-Funktion erstellt. Die ??install??-Funktion -wird aufgerufen, wenn alle nicht Kernel spezifischen Ressourcen installiert -werden sollen. Es können Binärdateien, Skripte und andere statischen Dateien -installiert werden. Um einen Datei im aktuellen Modul-Ordner zu addressieren -sollte die Variable "$moddir" als Prefix eingesetzt werden. -Eine solche Funktion kann beispielsweise einen ??Command-Line-Hook?? triggern, -der modulespezifische ??Kernel-Command-Line-Optionen?? verarbeitet während das -initiale Minilinux bootet. Im folgenden Beispiel werden ??Command-Line-Optionen -mit Priorität 20 vom Shell-Skript ??parse-insmodpost.sh?? gelesen und -ausgewertet. Dadurch muss natürlich auch das entsprechende Skript in das -initramfs kopiert werden. Dies wird durch den Aufruf der Funktion -??inst_simple?? erreicht. - -

-install() {
-    inst_hook cmdline 20 "$moddir/parse-cmdline.sh"
-    inst_simple "$moddir/parse-cmdline.sh" /sbin/insmodpost.sh
-}
-
- -Die ??parse-cmdline.sh?? parst die Kernel-Command-Line für die Argumente -??rd.driver.post??, verhindert, dass die Module automatisch geladen werden und -installiert den Hook ??hook.sh?? in der ??initqueue/settled??. Der Inhalt von -??parse-cmdline.sh?? könnte wie folgt aussehen: - -

-for p in $(getargs rd.driver.post=); do
-    echo "blacklist $p" >> /etc/modprobe.d/initramfsblacklist.conf
-done
-
- -In einer ??depends??-Funktion können andere Dracut-Module als Abhängigkeit -deklariert werden. Diese müssen einfach per "echo" als String Leerzeichen -getrennt ausgegeben werden. - -

-depends() {
-    echo 'debug virtfs'
-}
-
- -Mit dieser Funktion können zusätzliche benötigte Kernel-Command-Line-Argumente -ausgegeben werden, die benötigt werden um die aktuelle Maschine zu booten. -Die Ausgabe sollte mit einem Leerzeichen beginnen und keine neuen Zeilen -ausgeben. - -

-cmdline() {
-    echo 'TODO'
-}
-
- -Mit der Funktion ??installkernel?? sollen alle kernelspezifischen Dateien -installiert werden. Siehe hierzu auch den Abschnitt -??Hilfsfunktionen zur Installation?? - -

-installkernel() {
-    TODO
-}
-
- -h2. Hilfsfunktionen zur Installation - -??inst_multiple?? installiert mehrere Binärdateien. Sollten ausführbare Dateien -ohne entsprechendem Pfad ausgewählt werden, wird dracut folgende die Pfade -??/usr/sbin??, ??/sbin??, ??/usr/bin??, ??/bin?? durchsuchen, um den Pfad der -zugehörigen ausführbaren Datei zu ermitteln. Bei dem Kommando-Zeilen-Argument -??-o?? als erster Parameter werden Fehler bei nicht auffindbaren Dateien -unterdrückt. - -??inst_multiple [-o] [ …]?? - -??inst?? installiert eine referenzierte Datei an den korrespondierenden Ort im -??initramfs??. Die Datei wird innerhalb des ??initramfs?? am gleichen Ort zu -finden sein wie auf der Referenzmaschine. Optional kann als zweites Argument -ein anderer Ort für das temporäre Dateisystem angegeben werden. - -??inst []?? - -??inst_hook?? installiert eine ausführbare Datei im Pfad ???? im -Dracut-hook-Ordner ????. Der Einstiegspunkt wird mit Priorität -???? zur Laufzeit des initialen Mini-Linux-Systems ausgeführt. - -??inst_hook ?? - -??inst_rules?? installiert einen oder mehrere udev-Regeln. Nicht-existente -udev-Regeln werden beim bauen des initramfs gemeldet, führen aber nicht zum -Abbruch. - -??inst_rules [ …]?? - -??instmods?? installiert einen oder mehrere Kernel-Module in das initramfs. -???? kann auch ein komplettes Subsystem darstellen, wenn es mit -dem Prefiy "=" beginnt (z.B. "=drivers/net/team"). ??instmods?? sollte nur -innerhalb der ??installkernel()??-Funktion verwendet werden. Ist ??$hostonly?? -gesetzt und das aktuelle Modul nicht im Referenzsystem geladen und wird -demnach nicht in ??/sys/…/uevent MODALIAS?? verwendet, wird dieses nicht in -das initramfs integriert. Soll das Modul in jedem Fall geladen werden, kann -folgende Syntax verwendet werden: - -

-installkernel() {
-    hostonly='' instmods 
-}
-
- -??instmods [ … ]?? - -h3. Konfiguration - -TODO - -h3. Debugging - -TODO - -h2. Build kernel specific dnbd3 kernel module - -> # Installiere Metainformation zum Kernel: @yum install kernel-devel@ -> # Installiere cmake zum Bauen von dnbd3: @yum install cmake@ -> # Installiere zlib-devel zum Bauen von dnbd3: @yum install zlib-devel@ - -Die kernel header Dateien liegen in: - -/usr/lib/modules/3.10.0-229.1.2.el7.x86_64 - -TOOD - -dnbd3-client -h 132.230.4.1 -i stage4/torben/test -r 1 - -> # Installiere qemu-img: @yum install qemu-img@ -> # Installiere nbd: @wget http://dl.fedoraproject.org/pub/epel/6/x86_64/nbd-2.9.20-7.el6.x86_64.rpm && rpm -Uvh nbd-2.9.20-7.el6.x86_64.rpm@ - -NOTE: Disable NetworkManager to avoid reloading network on boot: systemctl disable NetworkManager - -h2. CentOS7 @rpmbuild@ - -First "Set up RPM build env":http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment -Now in that user's home, e.g. @/home/builder@: -
-# install yumdownloader
-yum install yum-utils
-
-# download source in /home/builder/
-yumdownloader --source systemd
-
-# should have now have a file ~/systemd-208-20.el7_1.2.src.rpm
-# "install" it in ~/rpmbuild
-rpm -ivh systemd-208-20.el7_1.2.src.rpm
-
-# install building deps
-yum-builddep ~/rpmbuild/SPECS/systemd.spec
-
-# now check if everything is working, by running the simple %prep% phase
-# (unpacks source & applies patches)
-rpmbuild -bp ~/rpmbuild/SPECS/systemd.spec
-
-# if it worked, we can probably compile
-# this runs %prep% and %build%
-rpmbuild -bp ~/rpmbuild/SPECS/systemd.spec
-
- -dmesg - 998 ping 8.8.8.8 - 999 shutdown .h now - 1000 shutdown -h now - 1001 y search yumdownloader - 1002 y install yum-utils - 1003 yumdownloader --help - 1004 yumdownloader --source glib2 qemu - 1005 yumdownloader --source qemu-img - 1006 ls - 1007 mkdir glib2_source - 1008 cd glib2 - 1009 cd glib2_source/ - 1010 rpm2cpio ../glib2-2.40.0-4.el7.src.rpm | cpio -idmv - 1011 ls - 1012 tar xf glib-2.40.0.tar.xz - 1013 ls - 1014 cd glib-2.40.0 - 1015 ls - 1016 ./configure --enable-static - 1017 make - 1018 ls - 1019 make - 1020 y search zlib - 1021 y search zlib-static - 1022 y install zlib-static - 1023 ./configure --enable-static - 1024 y search libffi - 1025 y install libffi - 1026 y install libffi-devel - 1027 ./configure --enable-static - 1028 make - 1029 ls - 1030 cd build/ - 1031 ls - 1032 .. - 1033 l - 1034 ls - 1035 make install - 1036 .. - 1037 l - 1038 .. - 1039 l - 1040 mkdir qemu-kvm - 1041 cd qemu-kvm - 1042 ls - 1043 rpm2cpio ../qemu-kvm-1.5.3-86.el7_1.1.src.rpm | cpio -idmv - 1044 l - 1045 pwd - 1046 ls - 1047 l - 1048 ls - 1049 .. - 1050 l - 1051 git clone git://git.qemu.org/qemu.git qemu - 1052 ls - 1053 rm qemu-kvm -rf - 1054 rm qemu-kvm-1.5.3-86.el7_1.1.src.rpm - 1055 l - 1056 cd qemu/ - 1057 l - 1058 ./configure --static --target-list=x86_64-linux-user - 1059 y install zlib - 1060 y install zlib-devel - 1061 y install zlib2 - 1062 y search zlib - 1063 y install zlib-static - 1064 y install zlib - 1065 ll /lib64/libz.a - 1066 ./configure --static --target-list=x86_64-linux-user - 1067 make clean - 1068 ./configure --static - 1069 y search zlib - 1070 y search zlib-static..x86_64 - 1071 y search zlib-static.x86_64 - 1072 y install zlib-static.x86_64 - 1073 ldconfig - 1074 ./configure --static - 1075 ./configure --help - 1076 ./configure --help | grep zlib - 1077 y search zlib - 1078 y install zlib-devel zlib-static zlib - 1079 y deinstall zlib - 1080 y remove zlib - 1081 y search libz - 1082 ls - 1083 git submodule update --init dtc - 1084 ./configure --static --target-list=x86_64-linux-user - 1085 find / -name zlib - 1086 find / -name libz - 1087 find / -name *libz* - 1088 find / -name *zlib* - 1089 ls - 1090 ./configure --disable-zlib-test --static --target-list=x86_64-linux-user - 1091 y search base-devel - 1092 y search devel - 1093 yum groupinstall "Development Tools" - 1094 yum groups mark install - 1095 yum group mark install - 1096 yum groupinstall "Development Tools" - 1097 yum groups mark install - 1098 yum grouplist - 1099 y search zlibrary - 1100 y search glibc - 1101 y install glibc-static - 1102 ls - 1103 ./configure --static --target-list=x86_64-linux-user - 1104 y search glib - 1105 y search glib-2 - 1106 y search glib2-devel - 1107 y install glib2-devel - 1108 ./configure --static --target-list=x86_64-linux-user - 1109 git submodule update --init pixman - 1110 ./configure --static --target-list=x86_64-linux-user - 1111 ls - 1112 ll - 1113 make -j3 - 1114 l - 1115 ldd qemu-nbd - 1116 history - -h2. Quellen - -* "Main Page Dracut on kerne.org":https://dracut.wiki.kernel.org/index.php/Main_Page -* "Documentation on kernel.org":https://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html -* "Enable addional repository":http://www.tecmint.com/enable-rpmforge-repository -* "Getting Dynamic Kernel Module Support":http://rpmfind.net/linux/rpm2html/search.php?query=dkms diff --git a/dracut/dnbd3-qcow2-rootfs/scripts/prepare-disks b/dracut/dnbd3-qcow2-rootfs/scripts/prepare-disks deleted file mode 100755 index 2e68dd9e..00000000 --- a/dracut/dnbd3-qcow2-rootfs/scripts/prepare-disks +++ /dev/null @@ -1,211 +0,0 @@ -#!/bin/bash -############################################################################### -# GLOBALS -# - -# flag file containing pids of running instances for concurrency checks -declare -rg OPENSLX_DISK_FLAG="/tmp/openslx.disk" -# file that will contain the name of the device used for the /tmp partition -# - label 'OPENSLX_TMP' in GPT / type '0x44' in MBR -declare -rg OPENSLX_TMP_MARKER="/tmp/openslx.disk.tmp" -# file that will contain the name of the device used for storing qcow2 -# - label 'OPENSLX_SYS' in GPT / type '0x46' in MBR -declare -rg OPENSLX_SYS_MARKER="/tmp/openslx.disk.sys" -# mount point for system partition -declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" - -# -# END GLOBALS -############################################################################### - -############################################################################### -# FUNCTION DEFINITIONS -# -# helper to mount the OPENSLX_SYS partition to /opt/openslx/system -# Usage: mount_sys_part -mount_sys_part() { - if [ ! -b "$1" ]; then - warn "($$) Refusing to mount '$1' as its not a block device!" - return 1 - fi - - local OPENSLX_SYS_DEVICE="$1" - mkdir -p ${OPENSLX_SYS_MOUNT} - if ! mount -t auto "${OPENSLX_SYS_DEVICE}" "${OPENSLX_SYS_MOUNT}"; then - warn "($$) Mounting '${OPENSLX_SYS_DEVICE}' to '${OPENSLX_SYS_MOUNT}' failed." - return 1 - fi - return 0 - -} -# -# generic helper to format the given partition with the given filesystem or -# from the prefdefined list of xfs, ext4, ... -# Usage: format_disk -# e.g. format_disk /dev/sda1 xfs -format_disk () { - local TARGET_DEVICE="$1" - local fslist="xfs ext4" - # if we have a second arguments, its the filesystem of choice - local fs - [ $# -ge 2 ] && fslist="$2" - for fs in $fslist ; do - unset found - local MKFS="$(busybox which mkfs.$fs)" - if [ -n $MKFS ]; then - found=yes - case "mkfs.$fs" in - mkfs.xfs) fopt="-fq" ;; - mkfs.ext4) fopt="-Fq" ;; - esac - info "($$) Formatting $TARGET_DEVICE as $fs" - return $(${MKFS} ${fopt} "${TARGET_DEVICE}") - fi - [ -n "$found" ] && break - done - # still here? then we didn't find a proper formatter... - warn "($$) Could not format $PART_DEV as $fs." - return 1 -} - -# -# END FUNCTION DEFINITIONS -############################################################################### - -############################################################################### -# MAIN CODE -# - -command -v warn >/dev/null || . /lib/dracut-lib.sh - -# let check the arguments -if [ "$#" -ne 2 ]; then - warn "($$) '$0' need 2 arguments: '$0 [OPENSLX_SYS|OPENSLX_TMP] '" - exit 1 -fi -# $1 sane? -if [ "x$1" != "xOPENSLX_SYS" ] && [ "x$1" != "xOPENSLX_TMP" ]; then - warn "($$) First arg needs to be either 'OPENSLX_SYS' or 'OPENSLX_TMP', given: $1" - exit 1 -fi -# $2 sane? -if [ ! -b "/dev/$2" ]; then - warn "($$) Second arg appears not to be a block device!" - exit 1 -fi - -# ok all seems well, set the arguments -PART_TYPE="$1" -PART_DEV="/dev/$2" - -unset OPENSLX_TMP_DEVICE -unset OPENSLX_SYS_DEVICE - -# lets check if we are already running -INSTANCES="$(grep "$PART_TYPE" "$OPENSLX_DISK_FLAG" | busybox wc -l)" -if [ "$INSTANCES" -ge 1 ]; then - # uhoh we are not alone! Need to check - # if the other instance actually did its job - warn "($$) '$0' already running for $PART_TYPE on $PART_DEV... checking state." - # here two/three cases depending on which PART_TYPE we are - # currently processing. - for timeout in 1 1 2; do - # always give the other instance time to finish - # but only check 3 times overall - sleep $timeout - case "$PART_TYPE" in - OPENSLX_TMP) - # was the tmp partition marker created with a device? - if [ ! -f "${OPENSLX_TMP_MARKER}" ]; then - info "($$) Invalid state: no marker for $PART_TYPE" - continue - fi - # it was, is it a valid block device? - OPENSLX_TMP_DEVICE="$(cat ${OPENSLX_TMP_MARKER})" - if [ -z $OPENSLX_TMP_DEVICE -o ! -b $OPENSLX_TMP_DEVICE ]; then - info "($$) Invalid state: no for device $OPENSLX_TMP_DEVICE" - continue - fi - # its detected, its a block device and as mounting is - # done later, we can not check for more at this point - info "($$) Valid state for $OPENSLX_TMP_DEVICE as $PART_TYPE" - exit 0 - ;; - OPENSLX_SYS) - # was the system partition marker created with a device? - if [ ! -f "${OPENSLX_SYS_MARKER}" ]; then - info "($$) Invalid state: no marker for $PART_TYPE" - continue - fi - # it was, is it a valid block device? - OPENSLX_SYS_DEVICE="$(cat ${OPENSLX_SYS_MARKER})" - if [ -z $OPENSLX_SYS_DEVICE -o ! -b $OPENSLX_SYS_DEVICE ]; then - info "($$) Invalid state: no for device $OPENSLX_SYS_DEVICE" - continue - fi - # its detected, its a block device, is it mounted? - if mount | grep -qE "^$OPENSLX_SYS_DEVICE\ on $OPENSLX_SYS_MOUNT"; then - info "($$) Valid state for $OPENSLX_SYS_DEVICE as $PART_TYPE" - exit 0 - fi - # if its not mounted, we want to keep on, so no exit! - ;; - *) - # weird case which should never happen - warn "($$) If you see this, then $0 was called with a bad PART_TYPE: $@" - continue - ;; - esac - done - warn "($$) Timeout reached!" - warn "($$) '$PART_TYPE' was found but not device was associated to it!" -fi - -# We write our pid to $OPENSLX_DISK_FLAG in order to make sure -# we are the only instance of this script running. -info "($$) Processing: $PART_TYPE -> $PART_DEV ($$)" -echo "$PART_TYPE.$$" >> "$OPENSLX_DISK_FLAG" - -# if we are still here, then we can go on and process the partition -if [ "$PART_TYPE" = "OPENSLX_TMP" ]; then - # always format /tmp partition - if ! format_disk "${PART_DEV}" xfs; then - # error while formatting, cleanup - warn "($$) Error formatting $PART_DEV ... removing $$" - sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" - exit 1 - fi - info "($$) Using '$PART_DEV' as '$PART_TYPE'" - # mark it for later: in pre-pivot we will check this file - # and mount it as $NEWROOT/tmp - echo "$PART_DEV" > "$OPENSLX_TMP_MARKER" - # remove our pid from OPENSLX_DISK_FLAG - sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" - exit 0 -fi -if [ "$PART_TYPE" = "OPENSLX_SYS" ]; then - # TODO make the formatting of the system partition configurable - if ! format_disk "${PART_DEV}" xfs; then - # error while formatting, cleanup - warn "($$) Error formatting $PART_DEV ... removing $$" - sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" - exit 1 - fi - # mark it - # mount it now, since qemu-nbd needs it asap! - if mount_sys_part "$PART_DEV"; then - # mount worked, mark it as done - info "($$) Using '$PART_DEV' as '$PART_TYPE'" - echo "$PART_DEV" > "$OPENSLX_SYS_MARKER" - sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" - exit 0 - else - warn "($$) 'mount_sys_part' failed in $0" - sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" - exit 1 - fi -fi - -# -# END MAIN CODE -############################################################################### diff --git a/dracut/dnbd3-qcow2-rootfs/scripts/setup-qcow2 b/dracut/dnbd3-qcow2-rootfs/scripts/setup-qcow2 deleted file mode 100755 index 70babc17..00000000 --- a/dracut/dnbd3-qcow2-rootfs/scripts/setup-qcow2 +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/bash - -# dracut-lib to use debugging functions -command -v warn >/dev/null || . /lib/dracut-lib.sh -command -v emergency_shell >/dev/null || . /lib/dracut-lib.sh - -############################################################################### -# GLOBALS -# -# TODO make this configurable -[ -f /opt/openslx/config ] && . /opt/openslx/config -[ -z $SLX_DNBD3_SERVER ] && SLX_DNBD3_SERVER="132.230.4.1" -[ -z $SLX_STAGE4 ] && SLX_STAGE4="stage4/joe/centos7" -[ -z $SLX_STAGE4_RID ] && SLX_STAGE4_RID="4" -declare -rg DNBD3_SERVER="$SLX_DNBD3_SERVER" -declare -rg DNBD3_IMAGE="$SLX_STAGE4" -declare -rg DNBD3_RID="$SLX_STAGE4_RID" -declare -rg DNBD3_DEVICE="/dev/dnbd0" -declare -rg QCOW_CONTAINER="/opt/openslx/system/system.qcow2" -# -# END GLOBALS -############################################################################### - -############################################################################### -# FUNCTION DEFINITIONS -# -# helper to do some sanity checks -check_dnbd3() { - if [ ! command -v "dnbd3-client" >/dev/null ]; then - warn "No 'dnbd3-client' found. Was the initramfs built correctly?" - emergency_shell -n "Error in $0" - return 1 - fi - return 0 -} - -# helper to connect to the dnbd3-server -connect_dnbd3() { - # check if it already connected - local current_image_name="$(cat /sys/block/${DNBD3_DEVICE#/dev/}/net/image_name)" - [ "x${current_image_name}" != "x(null)" ] && return 0 - - # not connected yet, do it - if ! dnbd3-client -h "${DNBD3_SERVER}" \ - -i "${DNBD3_IMAGE}" \ - -r "${DNBD3_RID}" \ - -d "${DNBD3_DEVICE}" ; then - warn "Failed to mount $DNBD3_IMAGE from $DNBD3_SERVER to $DNBD3_DEVICE" - emergency_shell -n "Error in $0" - return 1 - fi - return 0 -} - -# helper to create the qcow2 container file using -# DNBD3_DEVICE as the base of the filesystem -# QCOW_CONTAINER as the writable file -# (our future rootfs) -create_qcow() { - # check if we already created the qcow2-container - [ -e "$QCOW_CONTAINER" ] && return 0 - - # check if we have our target directory, if not create it - [ ! -d "$(busybox dirname $QCOW_CONTAINER)" ] && \ - mkdir -p "$(busybox dirname $QCOW_CONTAINER)" - - # we did not, let's create it - if ! qemu-img create -f qcow2 -o \ - backing_file="$DNBD3_DEVICE",backing_fmt=qcow2 "$QCOW_CONTAINER"; then - warn "Failed to create qcow2-Container from $DNBD3_DEVICE" - emergency_shell -n "Error in $0" - rm -f -- "$QCOW_CONTAINER" - return 1 - fi - return 0 -} -# helper to start qemu-nbd on localhost:2000 -# use our wrapper to set argv[0][0] to '@' -# this keeps qemu-nbd running after switching root -export_qcow() { - # check if we already have a qemu-nbd - if [ -e /tmp/qemu-nbd.pid ]; then - kill -0 $(cat /tmp/qemu-nbd.pid) && return 0 - fi - # since we use the wrapper, we need a little more logic to see if it runs - /usr/bin/systemd-preserve-process-marker \ - /usr/bin/qemu-nbd -t -p 2000 "$QCOW_CONTAINER" & - # the wrapper returns 255 if the qemu-nbd binary is missing - local qemu_nbd_pid="$!" - for i in 0.5 1 2; do - sleep $i - if ! kill -0 $qemu_nbd_pid; then - # not running - wait $qemu_nbd_pid - local ret_wrapper="$?" - if [ "${ret_wrapper}" -eq 127 ]; then - # wrapper was not found by bash - warn "No such file or directory: /usr/bin/systemd-preserve-process-marker" - elif [ "${ret_wrapper}" -eq 255 ]; then - # qemu-nbd was not found - warn "No such file or directory: /usr/bin/qemu-nbd" - fi - emergency_shell -n "Error in $0" - return 1 - else - # all good, qemu-nbd is running, remember its pid - echo $qemu_nbd_pid > /tmp/qemu-nbd.pid - return 0 - fi - done - # fallback - return 1 -} -# helper to mount the qcow2-container per nbd -connect_qcow() { - # try to mount the locally exported qcow2-container using nbd-client - if /usr/bin/systemd-preserve-process-marker \ - nbd-client --persist 127.0.0.1 2000 /dev/nbd0; then - # it worked, lets set the symlink to /dev/root as dracut needs it - # later on to mount that device to the future root (/sysroot) - ln -sf /dev/nbd0 /dev/root - return 0 - else - # this is pretty bad, dracut would spawn an emergency later on - # since there is no /dev/root to mount. - # For debugging purposes, we drop an emergency shell ourselves - # if the mount fails. - warn "Could not mount /dev/nbd0 from 127.0.0.1:2000." - emergency_shell -n "Error in $0" - return 1 - fi -} -# -# END FUNCTION DEFINITIONS -############################################################################### - -# No main, use functions! diff --git a/dracut/dnbd3-qcow2-rootfs/systemd-preserve-process-marker.c b/dracut/dnbd3-qcow2-rootfs/systemd-preserve-process-marker.c deleted file mode 100644 index 8f0fc108..00000000 --- a/dracut/dnbd3-qcow2-rootfs/systemd-preserve-process-marker.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include - -void print_array(int argc, char *argv[]) { - // Helper function to print given array with given length. - int i = 0; - int j = 0; - for (i = 0; i < argc; i ++) { - j = 0; - while(argv[i][j] != '\0') - printf("%c", argv[i][j++]); - printf(" "); - } - printf("\n"); -} -int main(int argc, char *argv[]) { - int count; - // Last item acts as null pointer. - char **copy = calloc(sizeof(char *), argc); - // Slice first given command line argument. - for (count = 0; count < argc - 1; count++) - copy[count] = strdup(argv[count + 1]); - // Adding systemd indicator to preserve wrapped process during changing - // root filesystem. We mark wrapper and child process. - argv[0][0] = '@'; - copy[0][0] = '@'; - if (-1 == execvp(argv[1], copy)) { - perror("Executing child process failed."); - return -1; - } -} diff --git a/dracut/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules b/dracut/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules deleted file mode 100644 index 3f5e382f..00000000 --- a/dracut/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules +++ /dev/null @@ -1,8 +0,0 @@ -# GPT rules -KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="gpt" ENV{ID_PART_ENTRY_NAME}=="OPENSLX_TMP" RUN+="/sbin/prepare-disks %E{ID_PART_ENTRY_NAME} %k" -KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="gpt" ENV{ID_PART_ENTRY_NAME}=="OPENSLX_SYS" RUN+="/sbin/prepare-disks %E{ID_PART_ENTRY_NAME} %k" - -# MBR rules -KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="dos" ENV{ID_PART_ENTRY_TYPE}=="0x44" RUN+="/sbin/prepare-disks OPENSLX_TMP %k" -KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="dos" ENV{ID_PART_ENTRY_TYPE}=="0x46" RUN+="/sbin/prepare-disks OPENSLX_SYS %k" - diff --git a/mltk-ng b/mltk-ng deleted file mode 100755 index 74503307..00000000 --- a/mltk-ng +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -# ------------------------------------------------------------------------------ -# -# Mini-Linux Toolkit Next Gen -# -# ------------------------------------------------------------------------------ - -declare -rg ARG0="$0" -declare -rg SELF="$(readlink -f "$ARG0")" -declare -rg ROOT_DIR="$(dirname "${SELF}")" -declare -rg MLTK_PID="$$" - -banner() { - echo -e "\033[38;5;202m\t __ __ __ " - echo -e "\033[38;5;202m\t.--------.| | | |_| |--." - echo -e "\033[38;5;208m\t| || |_| _| < " - echo -e "\033[38;5;214m\t|__|__|__||____|____|__|__|" - echo -e "\033[38;5;214m\t " - echo -e "\033[38;5;220m\t ** OpenSLX Project // 2015 **" - echo -e "\033[38;5;226m\t http://lab.openslx.org/" - echo -e "\033[00m" -} - - -pinfo() { - echo -e "\033[38;5;10m[info]\033[0m $@" -} - -perror() { - echo -e "\033[38;5;9m[error]\033[0m $@" - kill "$MLTK_PID" - exit 1 -} - -print_usage() { - perror "./mltk-ng " -} - -# root check -if [ "$(id -u)" -ne 0 ]; then - perror "ERROR: You need to be root to use this toolkit." -else - banner -fi - -# do we even have tools? -for TOOL in qemu-img qemu-nbd mkfs.ext4; do - which $TOOL &>/dev/null || perror "Could not find '$TOOL'." -done - -# let's keep it simple for now, just source our main functions file -. ${ROOT_DIR}/mltk-ng.functions || perror "Could not source functions." - -# ok, now check that we have 3 args -[ $# -ne 3 ] && print_usage - -# even though functions check their parameter, we also do it to be safe. -valid_ip "$1" || perror "'$1' is not a valid IP adress, aborting..." -[ ! -d "$2" ] || perror "'$2' already exists, aborting..." -[ ! -f "$3" ] || perror "'$3' already exists, aborting..." - -# all good, let's start -pinfo " ## RUNNING ##" -clone_stage4 $1 $2 -export_qcow2 $2 $3 -pinfo " ## COMPLETE ##" diff --git a/mltk-ng.functions b/mltk-ng.functions deleted file mode 100755 index 363c16d8..00000000 --- a/mltk-ng.functions +++ /dev/null @@ -1,138 +0,0 @@ -# ------------------------------------------------------------------------------ -# -# Functions for MLTK-NG -# -# ------------------------------------------------------------------------------ -# -# check if we have mltk-ng environement variables to check -# if we actually got sourced by it. -if [ -z "${MLTK_PID}" -o -z "${ROOT_DIR}" ]; then - # not using perror, since we probably don't have it. - echo "Neither MLTK_PID nor ROOT_DIR is set. Was this included by mltk-ng?" - exit 1 -fi - -# Helper to generate a stage4 export for a remote machine per rsync. -clone_stage4() { - [ $# -ne 2 ] && perror "$0 " - local REMOTE_HOST="$1" - local TARGET_DIR="$2" - local BUILD_DIR="${ROOT_DIR}/builds/$REMOTE_HOST" - mkdir -p "$TARGET_DIR" - mkdir -p "$BUILD_DIR" - - local EXCLUDE="$BUILD_DIR/exclude-stage4" - local INCLUDE="$BUILD_DIR/include-stage4" - - pinfo "Building rsync exclude-file for building stage 4...." - echo "## Exclude file for stage4 of $REMOTE_HOST" > "$EXCLUDE" - echo "## Include file for stage4 of $REMOTE_HOST" > "$INCLUDE" - for FILE in $(find "$ROOT_DIR"/blacklists/*/ -type f); do - echo "## From $FILE" >> "$EXCLUDE" - echo "## From $FILE" >> "$INCLUDE" - grep '^-' "$FILE" >> "$EXCLUDE" - grep '^+' "$FILE" >> "$INCLUDE" - done - pinfo "Done." - - # prepare rsync's options - local RSYNC_SOURCE="root@$REMOTE_HOST:/" - local RSYNC_OPTS="-e ssh -c arcfour -oStrictHostKeyChecking=no" - - # run rsync with the exclude/include lists created earlier - pinfo "Cloning via rsync..." - cat "$INCLUDE" "$EXCLUDE" | \ - rsync --verbose \ - --archive \ - --delete \ - --delete-excluded \ - --numeric-ids \ - --exclude-from=- \ - "${RSYNC_OPTS}" \ - "${RSYNC_SOURCE}" \ - "${TARGET_DIR}" \ - || perror "rsync from '${RSYNC_SOURCE}' to '${TARGET_DIR}' failed." - pinfo "Cloning '${REMOTE_HOST}' to '${TARGET_DIR}' succeeded." - return 0 -} -# helper to build a qcow2 container from a stage4 sync directory. -# required tools: qemu-img, qemu-nbd, nbd, mkfs.ext4 -export_qcow2() { - # enough args? - [ $# -ne 2 ] && perror "Usage: $0 " - # $1 valid? - [ ! -d $1 ] && perror "First argument not a directory!" - # $2 should not be a dir or strange things will happen... - [ -d $2 ] && perror "Target file can not be a directory!" - - # $1 is dir, strip trailing slash if there is one - local STAGE4_DIR="${1%/}" - local TARGET_FILE="$2" - if [ -e $TARGET_FILE ]; then - pinfo "Removing old target: $TARGET_FILE" - rm $target || perror "Could not remove '$TARGET_FILE'" - fi - - # so far so good - pinfo "Creating empty qcow2-container ..." - qemu-img create -f qcow2 $TARGET_FILE 10G \ - || perror "qemu-img create failed with: $?" - pinfo "Done." - - # find usable nbd device - pinfo "Looking for usable nbd device..." - local NBD_ID="$(find_free_nbd)" - local NBD_DEV="/dev/nbd${NBD_ID}" - [ -b "$NBD_DEV" ] || perror "'$NBD_DEV' is not a block device!" - pinfo "Exporting '${TARGET_FILE}' using '${NBD_DEV}'..." - qemu-nbd -c ${NBD_DEV} ${TARGET_FILE} || perror "qemu-nbd failed with: $?" - pinfo "Done." - - pinfo "Creating ext4 filesystem on '${TARGET_FILE}'..." - mkfs.ext4 "${NBD_DEV}" || perror "mkfs failed with: $?" - pinfo "Done." - - # mount NBD_DEV - mkdir ${BUILD_DIR}/mnt - pinfo "Mounting '${NBD_DEV}' to '${BUILD_DIR}/mnt'..." - mount ${NBD_DEV} ${BUILD_DIR}/mnt || perror "Mount failed with: $?" - pinfo "Done." - - # copy files from the stage4 directory to the mounted qcow2-container - pinfo "Copying '${STAGE4_DIR}' to '${BUILD_DIR}/mnt'..." - cp -ra "${STAGE4_DIR}"/* "${BUILD_DIR}"/mnt || perror "Copying failed with: $?" - pinfo "Done." - - pinfo "Cleaning up..." - umount "${BUILD_DIR}/mnt" || perror "Could not unmount '${BUILD_DIR}/mnt'." - qemu-nbd -d /dev/nbd${nbd_id} || perror "Could not disconnect '${NBD_DEV}'." - pinfo "Exporting '${STAGE4_DIR}' to '${TARGET_FILE}' completed." -} - -# helper to find an unused nbd device -find_free_nbd() { - local nbd_size=0 - for nbd_id in {0..15}; do - [ -b "/dev/nbd${nbd_id}" ] || continue - [ ! -e "/sys/block/nbd${nbd_id}/size" ] || continue - nbd_size=$(cat /sys/block/nbd${nbd_id}/size) - [ $nbd_size -eq 0 ] && break - done - return ${nbd_id} -} -# helper to validate an ip -valid_ip() { - local ip=$1 - local stat=1 - - if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - OIFS=$IFS - IFS='.' - ip=($ip) - IFS=$OIFS - [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ - && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] - stat=$? - fi - return $stat -} diff --git a/packager/blacklists/README b/packager/blacklists/README new file mode 100644 index 00000000..ed3fe459 --- /dev/null +++ b/packager/blacklists/README @@ -0,0 +1,15 @@ +This directory contains blacklists of files and directories that +should be excluded when cloning stage4 of a remote system. The +blacklists are split into groups, represented by sub-directories. +They contain one or more text files representing blacklists in rsync +"--exclude-from" format. + +There is a group called "essential", containg blacklists for essential +files and dirs that you always want to exclude from being cloned. +Other directories are create for specific software packages, like +gnome, or kde. + +For inclusion of desktop environments like Gnome or KDE a substructure +(subdirectory) called desktop-sessions was introduced. The files / +directories in there should describe only includes ("+ ....") to provide +files needed for a desktop environment. diff --git a/packager/blacklists/essential/fontcache b/packager/blacklists/essential/fontcache new file mode 100644 index 00000000..13d60d44 --- /dev/null +++ b/packager/blacklists/essential/fontcache @@ -0,0 +1,3 @@ ++ /var/cache/fontconfig ++ /var/cache/fontconfig/* + diff --git a/packager/blacklists/essential/linux-base b/packager/blacklists/essential/linux-base new file mode 100644 index 00000000..c3d023d7 --- /dev/null +++ b/packager/blacklists/essential/linux-base @@ -0,0 +1,80 @@ +- /cdrom/* +- /dev/* +- /adm/* +- /afs/* +- /bfg/* +- /clustersw/* +- /cvmfs/* +- /gridsw/* +- /storage/* + +# This is where the bind-mount of mltk resides... +- /export/* +- /etc/*ppp* +- /etc/*pptp* +- /etc/dhcp* +- /etc/exports* +- /etc/fstab +#- /etc/group +- /etc/group- +- /etc/gshadow +- /etc/gshadow- +- /etc/hostname +- /etc/hosts +#- /etc/inputrc +- /etc/issue.net +# Always include ldconfig/cache of full system: ++ /etc/ld.so.** +#- /etc/localtime +#- /etc/login.defs +#- /etc/mtab +#- /etc/mtab.* ++ /etc/sysconfig/network-scripts/ifcfg-lo +- /etc/sysconfig/network-scripts/ifcfg-* +- /etc/networks +#- /etc/passwd +- /etc/passwd- +#- /etc/resolv.conf +#- /etc/resolvconf/ +#- /etc/shadow +- /etc/shadow- +#- /lib/modules/ +- /lost+found/ +- /media/* +- /mnt/* +- /opt/openslx +- /proc/* +- /run/* +#- /srv/ +- /sys/* +- /tmp/* +#- /usr/src/ ++ /var/backup/**/ +- /var/backup/** ++ /var/cache/**/ +- /var/cache/** ++ /var/crash/**/ +- /var/crash/** ++ /var/empty/**/ +- /var/empty/** ++ /var/lock/**/ +- /var/lock/** ++ /var/log/**/ +- /var/log/** ++ /var/mail/**/ +- /var/mail/** +#+ /var/spool/**/ +#- /var/spool/** ++ /var/spool/torque/* +- /var/tmp/* +- /var/lib/nova/instances/* +- /var/lib/libvirt + + + +## Interfering binaries/links +#- /sbin/shutdown +#- /sbin/reboot +#- /sbin/poweroff +#- /sbin/halt +##- /bin/sh diff --git a/packager/blacklists/essential/linux-extended b/packager/blacklists/essential/linux-extended new file mode 100644 index 00000000..3d81000a --- /dev/null +++ b/packager/blacklists/essential/linux-extended @@ -0,0 +1,5 @@ +- /home/* +- /root/* ++ /root/.bash* ++ /root/.ssh +- /etc/cups diff --git a/packager/blacklists/essential/other-files b/packager/blacklists/essential/other-files new file mode 100644 index 00000000..d35a5736 --- /dev/null +++ b/packager/blacklists/essential/other-files @@ -0,0 +1,3 @@ +- .svn +- .git +- *.gvfs diff --git a/packager/blacklists/essential/policykit b/packager/blacklists/essential/policykit new file mode 100644 index 00000000..2f42c0e0 --- /dev/null +++ b/packager/blacklists/essential/policykit @@ -0,0 +1,2 @@ +#- /usr/share/pol*/actions/org.freedesktop.upower.* + diff --git a/packager/blacklists/essential/temp-files b/packager/blacklists/essential/temp-files new file mode 100644 index 00000000..50955d08 --- /dev/null +++ b/packager/blacklists/essential/temp-files @@ -0,0 +1,5 @@ +- *~ +- *.bak +- *.old +- *.pid +- *.tmp diff --git a/packager/blacklists/essential/tm-scripts b/packager/blacklists/essential/tm-scripts new file mode 100644 index 00000000..393effea --- /dev/null +++ b/packager/blacklists/essential/tm-scripts @@ -0,0 +1 @@ +- **/tm-scripts diff --git a/packager/blacklists/package-managers/apt b/packager/blacklists/package-managers/apt new file mode 100644 index 00000000..5e019138 --- /dev/null +++ b/packager/blacklists/package-managers/apt @@ -0,0 +1,2 @@ ++ /var/cache/apt/archives/partial/** + diff --git a/packager/blacklists/package-managers/rpm b/packager/blacklists/package-managers/rpm new file mode 100644 index 00000000..0527ee75 --- /dev/null +++ b/packager/blacklists/package-managers/rpm @@ -0,0 +1,5 @@ +- *.rpmnew +- *.rpmsave +- /etc/*rpmnew +- /etc/*rpmorig +- /etc/*rpmsave diff --git a/packager/blacklists/package-managers/yast b/packager/blacklists/package-managers/yast new file mode 100644 index 00000000..9de1ec05 --- /dev/null +++ b/packager/blacklists/package-managers/yast @@ -0,0 +1,5 @@ +- /var/lib/YaST2/you/mnt/* +- /var/lib/YaST2/backup_boot_sectors +- /etc/*YaST2save +- *.YaST2save + diff --git a/packager/blacklists/package-managers/yum b/packager/blacklists/package-managers/yum new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/packager/blacklists/package-managers/yum @@ -0,0 +1 @@ + diff --git a/packager/blacklists/package-managers/zypper b/packager/blacklists/package-managers/zypper new file mode 100644 index 00000000..fbab85d7 --- /dev/null +++ b/packager/blacklists/package-managers/zypper @@ -0,0 +1,2 @@ +- /var/lib/zypp + diff --git a/packager/openslx b/packager/openslx new file mode 100755 index 00000000..6a75fc47 --- /dev/null +++ b/packager/openslx @@ -0,0 +1,68 @@ +#!/bin/bash +# ------------------------------------------------------------------------------ +# +# OpenSLX Toolkit Next Gen +# +# ------------------------------------------------------------------------------ +# +# The next generation toolkit to build a stateless linux system bootable +# over the network. Composed of dracut-built initramfs and a full system clone. +# +# ------------------------------------------------------------------------------ +# +# OpenSLX-NG Functions +# +# ------------------------------------------------------------------------------ +pinfo() { + echo -e "\033[38;5;10m[info]\033[0m $@" +} + +perror() { + echo -e "\033[38;5;9m[error]\033[0m $@" + kill "$SELF_PID" + exit 1 +} + +print_usage() { + perror "$ARG0 " +} + +# ------------------------------------------------------------------------------ +# +# OpenSLX-NG Main Code +# +# ------------------------------------------------------------------------------ + +declare -rg ARG0="$0" +declare -rg SELF="$(readlink -f "$ARG0")" +declare -rg ROOT_DIR="$(dirname "${SELF}")" +declare -rg SELF_PID="$$" + +# root check +if [ "$(id -u)" -ne 0 ]; then + perror "ERROR: You need to be root to use this toolkit." +else + pinfo "" +fi + +# do we even have tools? +for TOOL in qemu-img qemu-nbd mkfs.ext4; do + which $TOOL &>/dev/null || perror "Could not find '$TOOL'." +done + +# let's keep it simple for now, just source our main functions file +. "${ROOT_DIR}/$ARG0".functions || perror "Could not source functions." + +# ok, now check that we have 3 args +[ $# -ne 3 ] && print_usage + +# even though functions check their parameter, we also do it to be safe. +valid_ip "$1" || perror "'$1' is not a valid IP adress, aborting..." +[ ! -d "$2" ] || perror "'$2' already exists, aborting..." +[ ! -f "$3" ] || perror "'$3' already exists, aborting..." + +# all good, let's start +pinfo " ## RUNNING ##" +clone_stage4 $1 $2 || perror "Failed to clone stage4 with: $1 $2" +export_qcow2 $2 $3 || perror "Failed to export stage4 with: $2 $3" +pinfo " ## COMPLETE ##" diff --git a/packager/openslx.functions b/packager/openslx.functions new file mode 100755 index 00000000..5fabdbe0 --- /dev/null +++ b/packager/openslx.functions @@ -0,0 +1,138 @@ +# ------------------------------------------------------------------------------ +# +# Functions for OpenSLX-NG +# +# ------------------------------------------------------------------------------ +# +# check if we have our environement variables to check +# if we actually got sourced by the main script +if [ -z "${SELF_PID}" -o -z "${ROOT_DIR}" ]; then + # not using perror, since we probably don't have it. + echo "Neither SELF_PID nor ROOT_DIR is set. Was this included by OpenSLX-NG?" + exit 1 +fi + +# Helper to generate a stage4 export for a remote machine per rsync. +clone_stage4() { + [ $# -ne 2 ] && perror "$0 " + local REMOTE_HOST="$1" + local TARGET_DIR="$2" + local BUILD_DIR="${ROOT_DIR}/builds/$REMOTE_HOST" + mkdir -p "$TARGET_DIR" + mkdir -p "$BUILD_DIR" + + local EXCLUDE="$BUILD_DIR/exclude-stage4" + local INCLUDE="$BUILD_DIR/include-stage4" + + pinfo "Building rsync exclude-file for building stage 4...." + echo "## Exclude file for stage4 of $REMOTE_HOST" > "$EXCLUDE" + echo "## Include file for stage4 of $REMOTE_HOST" > "$INCLUDE" + for FILE in $(find "$ROOT_DIR"/blacklists/*/ -type f); do + echo "## From $FILE" >> "$EXCLUDE" + echo "## From $FILE" >> "$INCLUDE" + grep '^-' "$FILE" >> "$EXCLUDE" + grep '^+' "$FILE" >> "$INCLUDE" + done + pinfo "Done." + + # prepare rsync's options + local RSYNC_SOURCE="root@$REMOTE_HOST:/" + local RSYNC_OPTS="-e ssh -c arcfour -oStrictHostKeyChecking=no" + + # run rsync with the exclude/include lists created earlier + pinfo "Cloning via rsync..." + cat "$INCLUDE" "$EXCLUDE" | \ + rsync --verbose \ + --archive \ + --delete \ + --delete-excluded \ + --numeric-ids \ + --exclude-from=- \ + "${RSYNC_OPTS}" \ + "${RSYNC_SOURCE}" \ + "${TARGET_DIR}" \ + || perror "rsync from '${RSYNC_SOURCE}' to '${TARGET_DIR}' failed." + pinfo "Cloning '${REMOTE_HOST}' to '${TARGET_DIR}' succeeded." + return 0 +} +# helper to build a qcow2 container from a stage4 sync directory. +# required tools: qemu-img, qemu-nbd, nbd, mkfs.ext4 +export_qcow2() { + # enough args? + [ $# -ne 2 ] && perror "Usage: $0 " + # $1 valid? + [ ! -d $1 ] && perror "First argument not a directory!" + # $2 should not be a dir or strange things will happen... + [ -d $2 ] && perror "Target file can not be a directory!" + + # $1 is dir, strip trailing slash if there is one + local STAGE4_DIR="${1%/}" + local TARGET_FILE="$2" + if [ -e $TARGET_FILE ]; then + pinfo "Removing old target: $TARGET_FILE" + rm $target || perror "Could not remove '$TARGET_FILE'" + fi + + # so far so good + pinfo "Creating empty qcow2-container ..." + qemu-img create -f qcow2 $TARGET_FILE 10G \ + || perror "qemu-img create failed with: $?" + pinfo "Done." + + # find usable nbd device + pinfo "Looking for usable nbd device..." + local NBD_ID="$(find_free_nbd)" + local NBD_DEV="/dev/nbd${NBD_ID}" + [ -b "$NBD_DEV" ] || perror "'$NBD_DEV' is not a block device!" + pinfo "Exporting '${TARGET_FILE}' using '${NBD_DEV}'..." + qemu-nbd -c ${NBD_DEV} ${TARGET_FILE} || perror "qemu-nbd failed with: $?" + pinfo "Done." + + pinfo "Creating ext4 filesystem on '${TARGET_FILE}'..." + mkfs.ext4 "${NBD_DEV}" || perror "mkfs failed with: $?" + pinfo "Done." + + # mount NBD_DEV + mkdir ${BUILD_DIR}/mnt + pinfo "Mounting '${NBD_DEV}' to '${BUILD_DIR}/mnt'..." + mount ${NBD_DEV} ${BUILD_DIR}/mnt || perror "Mount failed with: $?" + pinfo "Done." + + # copy files from the stage4 directory to the mounted qcow2-container + pinfo "Copying '${STAGE4_DIR}' to '${BUILD_DIR}/mnt'..." + cp -ra "${STAGE4_DIR}"/* "${BUILD_DIR}"/mnt || perror "Copying failed with: $?" + pinfo "Done." + + pinfo "Cleaning up..." + umount "${BUILD_DIR}/mnt" || perror "Could not unmount '${BUILD_DIR}/mnt'." + qemu-nbd -d /dev/nbd${nbd_id} || perror "Could not disconnect '${NBD_DEV}'." + pinfo "Exporting '${STAGE4_DIR}' to '${TARGET_FILE}' completed." +} + +# helper to find an unused nbd device +find_free_nbd() { + local nbd_size=0 + for nbd_id in {0..15}; do + [ -b "/dev/nbd${nbd_id}" ] || continue + [ ! -e "/sys/block/nbd${nbd_id}/size" ] || continue + nbd_size=$(cat /sys/block/nbd${nbd_id}/size) + [ $nbd_size -eq 0 ] && break + done + return ${nbd_id} +} +# helper to validate an ip +valid_ip() { + local ip=$1 + local stat=1 + + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + OIFS=$IFS + IFS='.' + ip=($ip) + IFS=$OIFS + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ + && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + stat=$? + fi + return $stat +} -- cgit v1.2.3-55-g7522