diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 6199b5144f..3d78555f79 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -55,6 +55,7 @@ jobs: "13", "14", "15", + "16", "17", "20", "21", diff --git a/test/TEST-16-DMSQUASH/create-root.sh b/test/TEST-16-DMSQUASH/create-root.sh new file mode 100755 index 0000000000..9bc1aa5dc8 --- /dev/null +++ b/test/TEST-16-DMSQUASH/create-root.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +trap 'poweroff -f' EXIT + +# don't let udev and this script step on eachother's toes +for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do + : > "/etc/udev/rules.d/$x" +done +rm -f -- /etc/lvm/lvm.conf +udevadm control --reload +set -e + +udevadm settle +mkfs.ext4 -q -L dracut /dev/disk/by-id/ata-disk_root +mkdir -p /root +mount /dev/disk/by-id/ata-disk_root /root +mkdir -p /root/run /root/testdir +echo "Creating squashfs" +mksquashfs /source /root/testdir/rootfs.img -quiet +umount /root +echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker +poweroff -f diff --git a/test/TEST-16-DMSQUASH/create.py b/test/TEST-16-DMSQUASH/create.py deleted file mode 100644 index 00e92da0cd..0000000000 --- a/test/TEST-16-DMSQUASH/create.py +++ /dev/null @@ -1,197 +0,0 @@ -#!/usr/bin/python3 -tt -# -# livecd-creator : Creates Live CD based for Fedora. -# -# Copyright 2007, Red Hat Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Library General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -import os -import os.path -import sys -import time -import optparse -import logging -import shutil -from distutils.dir_util import copy_tree - -import imgcreate -from imgcreate.fs import makedirs - -class myLiveImageCreator(imgcreate.x86LiveImageCreator): - def __init__(self, ks, name, fslabel=None, releasever=None, tmpdir="/tmp", - title="Linux", product="Linux"): - - imgcreate.x86LiveImageCreator.__init__(self, ks, name, - fslabel=fslabel, - releasever=releasever, - tmpdir=tmpdir) - - #self._outdir=os.getenv("TESTDIR", ".") - - def install(self, repo_urls = {}): - copy_tree(os.environ.get("TESTDIR", ".") + "/root-source", self._instroot) - - def configure(self): - self._create_bootconfig() - - def _get_kernel_versions(self): - ret = {} - version=os.uname() - version=version[2] - ret["kernel-" + version] = [version] - return ret - - def __sanity_check(self): - pass - -class Usage(Exception): - def __init__(self, msg = None, no_error = False): - Exception.__init__(self, msg, no_error) - -def parse_options(args): - parser = optparse.OptionParser() - - imgopt = optparse.OptionGroup(parser, "Image options", - "These options define the created image.") - imgopt.add_option("-c", "--config", type="string", dest="kscfg", - help="Path or url to kickstart config file") - imgopt.add_option("-b", "--base-on", type="string", dest="base_on", - help="Add packages to an existing live CD iso9660 image.") - imgopt.add_option("-f", "--fslabel", type="string", dest="fslabel", - help="File system label (default based on config name)") - # Provided for img-create compatibility - imgopt.add_option("-n", "--name", type="string", dest="fslabel", - help=optparse.SUPPRESS_HELP) - imgopt.add_option("", "--image-type", type="string", dest="image_type", - help=optparse.SUPPRESS_HELP) - imgopt.add_option("", "--compression-type", type="string", dest="compress_type", - help="Compression type recognized by mksquashfs " - "(default xz needs a 2.6.38+ kernel, gzip works " - "with all kernels, lzo needs a 2.6.36+ kernel, lzma " - "needs custom kernel.) Set to 'None' to force read " - "from base_on.", - default="xz") - imgopt.add_option("", "--releasever", type="string", dest="releasever", - default=None, - help="Value to substitute for $releasever in kickstart repo urls") - parser.add_option_group(imgopt) - - # options related to the config of your system - sysopt = optparse.OptionGroup(parser, "System directory options", - "These options define directories used on your system for creating the live image") - sysopt.add_option("-t", "--tmpdir", type="string", - dest="tmpdir", default="/var/tmp", - help="Temporary directory to use (default: /var/tmp)") - sysopt.add_option("", "--cache", type="string", - dest="cachedir", default=None, - help="Cache directory to use (default: private cache") - parser.add_option_group(sysopt) - - imgcreate.setup_logging(parser) - - # debug options not recommended for "production" images - # Start a shell in the chroot for post-configuration. - parser.add_option("-l", "--shell", action="store_true", dest="give_shell", - help=optparse.SUPPRESS_HELP) - # Don't compress the image. - parser.add_option("-s", "--skip-compression", action="store_true", dest="skip_compression", - help=optparse.SUPPRESS_HELP) - parser.add_option("", "--skip-minimize", action="store_true", dest="skip_minimize", - help=optparse.SUPPRESS_HELP) - - (options, args) = parser.parse_args() - - # Pretend to be a image-creator if called with that name - options.image_type = 'livecd' - if options.image_type not in ('livecd', 'image'): - raise Usage("'%s' is a recognized image type" % options.image_type) - - # image-create compatibility: Last argument is kickstart file - if len(args) == 1: - options.kscfg = args.pop() - if len(args): - raise Usage("Extra arguments given") - - if options.base_on and not os.path.isfile(options.base_on): - raise Usage("Image file '%s' does not exist" %(options.base_on,)) - if options.image_type == 'livecd': - if options.fslabel and len(options.fslabel) > imgcreate.FSLABEL_MAXLEN: - raise Usage("CD labels are limited to 32 characters") - if options.fslabel and options.fslabel.find(" ") != -1: - raise Usage("CD labels cannot contain spaces.") - - return options - -def main(): - try: - options = parse_options(sys.argv[1:]) - except Usage as e: - msg, no_error = e.args - if no_error: - out = sys.stdout - ret = 0 - else: - out = sys.stderr - ret = 2 - if msg: - print >> out, msg - return ret - - if os.geteuid () != 0: - print >> sys.stderr, "You must run %s as root" % sys.argv[0] - return 1 - - if options.fslabel: - fslabel = options.fslabel - name = fslabel - else: - name = "livecd" - - fslabel = "LiveCD" - logging.info("Using label '%s' and name '%s'" % (fslabel, name)) - - ks = imgcreate.read_kickstart(options.kscfg) - - creator = myLiveImageCreator(ks, name, - fslabel=fslabel, - releasever=options.releasever, - tmpdir=os.path.abspath(options.tmpdir)) - - creator.compress_type = options.compress_type - creator.skip_compression = options.skip_compression - creator.skip_minimize = options.skip_minimize - if options.cachedir: - options.cachedir = os.path.abspath(options.cachedir) - - try: - creator.mount(options.base_on, options.cachedir) - creator.install() - creator.configure() - if options.give_shell: - print("Launching shell. Exit to continue.") - print("----------------------------------") - creator.launch_shell() - creator.unmount() - creator.package(os.environ.get("TESTDIR", ".")) - except imgcreate.CreatorError as e: - logging.error(u"Error creating Live CD : %s" % e) - return 1 - finally: - creator.cleanup() - - return 0 - -if __name__ == "__main__": - sys.exit(main()) diff --git a/test/TEST-16-DMSQUASH/livecd-fedora-minimal.ks b/test/TEST-16-DMSQUASH/livecd-fedora-minimal.ks deleted file mode 100644 index 6310f78d9c..0000000000 --- a/test/TEST-16-DMSQUASH/livecd-fedora-minimal.ks +++ /dev/null @@ -1,22 +0,0 @@ -lang en_US.UTF-8 -keyboard us -timezone US/Eastern -auth --useshadow --enablemd5 -selinux --enforcing -firewall --disabled -part / --size 1024 - -repo --name=fedora --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$version&arch=$basearch - -%packages -@core -anaconda-runtime -bash -kernel -passwd -policycoreutils -chkconfig -authconfig -rootfiles - -%end diff --git a/test/TEST-16-DMSQUASH/test.sh b/test/TEST-16-DMSQUASH/test.sh index 2a68f3051b..cf433489a1 100755 --- a/test/TEST-16-DMSQUASH/test.sh +++ b/test/TEST-16-DMSQUASH/test.sh @@ -1,23 +1,12 @@ #!/bin/bash + # shellcheck disable=SC2034 -TEST_DESCRIPTION="root filesystem on a LiveCD dmsquash filesystem" +TEST_DESCRIPTION="live root on a squash filesystem" KVERSION="${KVERSION-$(uname -r)}" # Uncomment this to debug failures -#DEBUGFAIL="rd.shell rd.break rd.debug systemd.log_level=debug systemd.log_target=console" - -test_check() { - for pdir in $(python3 -c "import site; print(site.getsitepackages())" | sed -e 's/\[\(.*\)\]/\1/' -e "s/', /' /g"); do - # shellcheck disable=SC2001 - pdir1=$(echo "$pdir" | sed "s/^'\(.*\)'$/\1/") - if [[ -d $pdir1/imgcreate ]]; then - return 0 - fi - done - echo "python-imgcreate not installed" - return 1 -} +# DEBUGFAIL="rd.shell rd.debug loglevel=7" test_run() { dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1 @@ -25,51 +14,24 @@ test_run() { # shellcheck disable=SC2034 declare -i disk_index=0 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker - qemu_add_drive_args disk_index disk_args "$TESTDIR"/livecd.iso livecd 1 + qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root "$testdir"/run-qemu \ "${disk_args[@]}" \ -boot order=d \ - -append "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot root=live:CDLABEL=LiveCD live rw quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.shell=0 $DEBUGFAIL" \ + -append "rd.live.image rd.live.overlay.overlayfs=1 rd.live.dir=testdir root=LABEL=dracut console=ttyS0,115200n81 quiet selinux=0 rd.info rd.shell=0 panic=1 oops=panic softlockup_panic=1 $DEBUGFAIL" \ -initrd "$TESTDIR"/initramfs.testing - # mediacheck test with qemu GUI - # "$testdir"/run-qemu \ - # -drive format=raw,bps=1000000,index=0,media=disk,file="$TESTDIR"/livecd.iso \ - # -drive format=raw,index=1,media=disk,file="$TESTDIR"/root.img \ - # -m 512M -smp 2 \ - # -net none \ - # -append "root=live:CDLABEL=LiveCD live quiet rhgb selinux=0 rd.live.check" \ - # -initrd "$TESTDIR"/initramfs.testing - grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success -- "$TESTDIR"/marker.img || return 1 } test_setup() { - mkdir -p -- "$TESTDIR"/overlay - ( - # shellcheck disable=SC2030 - export initdir="$TESTDIR"/overlay - # shellcheck disable=SC1090 - . "$basedir"/dracut-init.sh - inst_multiple poweroff shutdown - inst_hook shutdown-emergency 000 ./hard-off.sh - inst_hook emergency 000 ./hard-off.sh - ) - - "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \ - -a "debug dmsquash-live qemu" \ - -o "rngd" \ - -d "piix ide-gd_mod ata_piix ext3 sd_mod" \ - --no-hostonly-cmdline -N \ - -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1 - - mkdir -p -- "$TESTDIR"/root-source - kernel="$KVERSION" + mkdir -p -- "$TESTDIR"/overlay/source # Create what will eventually be our root filesystem onto an overlay ( + # shellcheck disable=SC2030 # shellcheck disable=SC2031 - export initdir="$TESTDIR"/root-source + export initdir="$TESTDIR"/overlay/source # shellcheck disable=SC1090 . "$basedir"/dracut-init.sh ( @@ -77,46 +39,81 @@ test_setup() { mkdir -p -- dev sys proc etc var/run tmp mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin ) - inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip \ - mount dmesg dhclient mkdir cp ping dhclient \ - umount strace less dd sync - for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do - [[ -f ${_terminfodir}/l/linux ]] && break - done - inst_multiple -o "${_terminfodir}"/l/linux - inst "$basedir/modules.d/35network-legacy/dhclient-script.sh" "/sbin/dhclient-script" - inst "$basedir/modules.d/35network-legacy/ifup.sh" "/sbin/ifup" + inst_simple /etc/os-release + [[ -f /etc/machine-id ]] && read -r MACHINE_ID < /etc/machine-id + inst ./test-init.sh /sbin/init inst_simple "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh" inst_simple "${basedir}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh" inst_binary "${basedir}/dracut-util" "/usr/bin/dracut-util" ln -s dracut-util "${initdir}/usr/bin/dracut-getarg" ln -s dracut-util "${initdir}/usr/bin/dracut-getargs" - inst_multiple grep syslinux isohybrid - for f in /usr/share/syslinux/*; do - inst_simple "$f" - done - inst_simple /etc/os-release - inst ./test-init.sh /sbin/init - inst "$TESTDIR"/initramfs.testing "/boot/initramfs-$KVERSION.img" - [[ -f /etc/machine-id ]] && read -r MACHINE_ID < /etc/machine-id - - VMLINUZ="/lib/modules/${KVERSION}/vmlinuz" - if ! [[ -e $VMLINUZ ]]; then - if [[ $MACHINE_ID ]] && { [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]]; }; then - VMLINUZ="/boot/${MACHINE_ID}/$KVERSION/linux" - fi - fi - [[ -e $VMLINUZ ]] || VMLINUZ="/boot/vmlinuz-${KVERSION}" + inst_multiple mkdir ln dd stty mount poweroff - inst "$VMLINUZ" "/boot/vmlinuz-${KVERSION}" - find_binary plymouth > /dev/null && inst_multiple plymouth cp -a -- /etc/ld.so.conf* "$initdir"/etc ldconfig -r "$initdir" ) - python3 create.py -d -c livecd-fedora-minimal.ks - return 0 + + # second, install the files needed to make the root filesystem + ( + # shellcheck disable=SC2030 + # shellcheck disable=SC2031 + export initdir=$TESTDIR/overlay + # shellcheck disable=SC1090 + . "$basedir"/dracut-init.sh + inst_multiple sfdisk poweroff cp umount sync dd mkfs.ext4 mksquashfs + inst_hook initqueue 01 ./create-root.sh + inst_hook initqueue/finished 01 ./finished-false.sh + ) + + # create an initramfs that will create the target root filesystem. + # We do it this way so that we do not risk trashing the host mdraid + # devices, volume groups, encrypted partitions, etc. + "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \ + --modules "rootfs-block qemu" \ + --no-hostonly --no-hostonly-cmdline --no-early-microcode --nofscks --nomdadmconf --nohardlink --nostrip \ + --force "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1 + rm -rf -- "$TESTDIR"/overlay + + # Create the blank file to use as a root filesystem + dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1 + dd if=/dev/zero of="$TESTDIR"/root.img bs=1MiB count=160 + declare -a disk_args=() + # shellcheck disable=SC2034 + declare -i disk_index=0 + qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker + qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root + + # Invoke KVM and/or QEMU to actually create the target filesystem. + "$testdir"/run-qemu \ + "${disk_args[@]}" \ + -append "root=/dev/dracut/root rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \ + -initrd "$TESTDIR"/initramfs.makeroot || return 1 + + if ! grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img; then + echo "Could not create root filesystem" + return 1 + fi + + ( + # shellcheck disable=SC2030 + # shellcheck disable=SC2031 + export initdir="$TESTDIR"/overlay + # shellcheck disable=SC1090 + . "$basedir"/dracut-init.sh + inst_multiple poweroff shutdown mkfs.ext4 find + inst_hook shutdown-emergency 000 ./hard-off.sh + inst_hook emergency 000 ./hard-off.sh + ) + "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \ + --modules "dmsquash-live qemu" \ + --omit "rngd" \ + --no-hostonly --no-hostonly-cmdline \ + --force "$TESTDIR"/initramfs.testing "$KVERSION" || return 1 + + ls -sh "$TESTDIR"/initramfs.testing + rm -rf -- "$TESTDIR"/overlay } test_cleanup() { diff --git a/test/container/Dockerfile-Fedora-latest b/test/container/Dockerfile-Fedora-latest index 3fc4a37025..87c749f9a4 100644 --- a/test/container/Dockerfile-Fedora-latest +++ b/test/container/Dockerfile-Fedora-latest @@ -45,7 +45,7 @@ RUN dnf -y install --setopt=install_weak_deps=False \ dbus-daemon \ kbd \ NetworkManager \ - python3-imgcreate \ + squashfs-tools \ which \ ShellCheck \ shfmt \