Blame SOURCES/coidracut3.patch

302623
diff --git a/dracut/50rdcore/module-setup.sh b/dracut/50rdcore/module-setup.sh
302623
index c065851..2d689d9 100755
302623
--- a/dracut/50rdcore/module-setup.sh
302623
+++ b/dracut/50rdcore/module-setup.sh
302623
@@ -14,6 +14,48 @@ install() {
302623
     inst_multiple gpg-agent
302623
     inst_multiple gpg-connect-agent
302623
 
302623
+     inst_multiple \
302623
+        realpath \
302623
+        basename   \
302623
+        blkid      \
302623
+        cat        \
302623
+        dirname    \
302623
+        findmnt    \
302623
+        growpart   \
302623
+        realpath   \
302623
+        resize2fs  \
302623
+        tail       \
302623
+        tune2fs    \
302623
+        touch      \
302623
+        xfs_admin  \
302623
+        xfs_growfs \
302623
+        wc         \
302623
+        lsblk      \
302623
+        wipefs
302623
+
302623
+    inst_multiple \
302623
+        awk       \
302623
+        cat       \
302623
+        dd        \
302623
+        grep      \
302623
+        mktemp    \
302623
+        partx     \
302623
+        rm        \
302623
+        sed       \
302623
+        sfdisk    \
302623
+        sgdisk    \
302623
+        find
302623
+        
302623
+    inst_multiple -o \
302623
+        clevis-encrypt-sss \
302623
+        clevis-encrypt-tang \
302623
+        clevis-encrypt-tpm2 \
302623
+        clevis-luks-bind \
302623
+        clevis-luks-common-functions \
302623
+        clevis-luks-unlock \
302623
+        pwmake \
302623
+        tpm2_create
302623
+
302623
     inst_simple "$moddir/rdcore" "/usr/bin/rdcore"
302623
 
302623
     inst_simple "$moddir/coreos-installer" "/usr/bin/coreos-installer"
302623
@@ -33,19 +75,8 @@ install() {
302623
     install_and_enable_unit "coreos-installer-reboot.service" \
302623
         "default.target" 
302623
 
302623
-#    install_and_enable_unit "coreos-installer-noreboot.service" \
302623
-#        "basic.target" 
302623
-#    inst_simple "$moddir/coreos-installer-reboot.service" \
302623
-#        "$systemdsystemunitdir/coreos-installer-reboot.service"
302623
-#    inst_simple "$moddir/coreos-installer-noreboot.service" \
302623
-#        "$systemdsystemunitdir/coreos-installer-noreboot.service"
302623
-#
302623
-#    inst_simple "$moddir/coreos-installer.target" \
302623
-#        "$systemdsystemunitdir/coreos-installer.target"
302623
-#
302623
-#    inst_simple "$moddir/coreos-installer-pre.target" \
302623
-#        "$systemdsystemunitdir/coreos-installer-pre.target"
302623
-#
302623
-#    inst_simple "$moddir/coreos-installer-post.target" \
302623
-#        "$systemdsystemunitdir/coreos-installer-post.target"
302623
+    install_and_enable_unit "growfs.service" \
302623
+        "default.target"
302623
+    inst_script "$moddir/growfs" \
302623
+        /usr/sbin/growfs
302623
 }
302623
diff --git a/scripts/growfs b/scripts/growfs
302623
new file mode 100644
302623
index 0000000..45c495c
302623
--- /dev/null
302623
+++ b/scripts/growfs
302623
@@ -0,0 +1,100 @@
302623
+#!/bin/bash
302623
+set -euo pipefail
302623
+
302623
+# This script grows the root
302623
+
302623
+sleep 5
302623
+udevadm settle
302623
+TYPE=$(lsblk --output FSTYPE /dev/disk/by-label/root | tail -n1)
302623
+echo ${TYPE}
302623
+dev=$(realpath /dev/disk/by-label/root)
302623
+
302623
+mount -t ${TYPE} /dev/disk/by-label/root /sysroot
302623
+
302623
+# We run after the rootfs is mounted at /sysroot
302623
+path=/sysroot
302623
+
302623
+# The use of tail is to avoid errors from duplicate mounts;
302623
+# this shouldn't happen for us but we're being conservative.
302623
+src=$(findmnt -nvr -o SOURCE "$path" | tail -n1)
302623
+
302623
+partition=$(realpath /dev/disk/by-label/root)
302623
+
302623
+# Go through each blockdev in the hierarchy and verify we know how to grow them
302623
+lsblk -no TYPE "${partition}" | while read dev; do
302623
+    case "${dev}" in
302623
+        part|crypt) ;;
302623
+        *) echo "error: Unsupported blockdev type ${dev}" 1>&2; exit 1 ;;
302623
+    esac
302623
+done
302623
+
302623
+# Get the filesystem type before extending the partition.  This matters
302623
+# because the partition, once extended, might include leftover superblocks
302623
+# from the previous contents of the disk (notably ZFS), causing blkid to
302623
+eval $(blkid -o export "${src}")
302623
+
302623
+ROOTFS_TYPE=${TYPE:-}
302623
+case "${ROOTFS_TYPE}" in
302623
+    xfs|ext4|btrfs) ;;
302623
+    *) echo "error: Unsupported filesystem for ${path}: '${ROOTFS_TYPE}'" 1>&2; exit 1 ;;
302623
+esac
302623
+
302623
+# Now, go through the hierarchy, growing everything. Note we go one device at a
302623
+# time using --nodeps, because ordering is buggy in el8:
302623
+# https://bugzilla.redhat.com/show_bug.cgi?id=1940607
302623
+current_blkdev=${partition}
302623
+while true; do
302623
+    eval "$(lsblk --paths --nodeps --pairs -o NAME,TYPE,PKNAME "${current_blkdev}")"
302623
+    MAJMIN=$(echo $(lsblk -dno MAJ:MIN "${NAME}"))
302623
+    case "${TYPE}" in
302623
+        part)
302623
+            eval $(udevadm info --query property --export "${current_blkdev}" | grep ^DM_ || :)
302623
+            if [ -n "${DM_MPATH:-}" ]; then
302623
+                # Since growpart does not understand device mapper, we have to use sfdisk.
302623
+                echo ", +" | sfdisk --no-reread --no-tell-kernel --force -N "${DM_PART}" "/dev/mapper/${DM_MPATH}"
302623
+                udevadm settle # Wait for udev-triggered kpartx to update mappings
302623
+            else
302623
+                partnum=$(cat "/sys/dev/block/${MAJMIN}/partition")
302623
+                # XXX: ideally this'd be idempotent and we wouldn't `|| :`
302623
+                growpart "${PKNAME}" "${partnum}" || :
302623
+            fi
302623
+            ;;
302623
+        crypt)
302623
+            # XXX: yuck... we need to expose this sanely in clevis
302623
+            (. /usr/bin/clevis-luks-common-functions
302623
+             eval $(udevadm info --query=property --export "${NAME}")
302623
+             # lsblk doesn't print PKNAME of crypt devices with --nodeps
302623
+             PKNAME=/dev/$(ls "/sys/dev/block/${MAJMIN}/slaves")
302623
+             clevis_luks_unlock_device "${PKNAME}" | cryptsetup resize -d- "${DM_NAME}"
302623
+            )
302623
+            ;;
302623
+        # already checked
302623
+        *) echo "unreachable" 1>&2; exit 1 ;;
302623
+    esac
302623
+    holders="/sys/dev/block/${MAJMIN}/holders"
302623
+    [ -d "${holders}" ] || break
302623
+    nholders="$(ls "${holders}" | wc -l)"
302623
+    if [ "${nholders}" -eq 0 ]; then
302623
+        break
302623
+    elif [ "${nholders}" -gt 1 ]; then
302623
+        # this shouldn't happen since we've checked the partition types already
302623
+        echo "error: Unsupported block device with multiple children: ${NAME}" 1>&2
302623
+        exit 1
302623
+    fi
302623
+    current_blkdev=/dev/$(ls "${holders}")
302623
+done
302623
+
302623
+# Wipe any filesystem signatures from the extended partition that don't
302623
+# correspond to the FS type we detected earlier.
302623
+wipefs -af -t "no${ROOTFS_TYPE}" "${src}"
302623
+
302623
+# TODO: Add XFS to https://github.com/systemd/systemd/blob/master/src/partition/growfs.c
302623
+# and use it instead.
302623
+case "${ROOTFS_TYPE}" in
302623
+    xfs) xfs_growfs "${path}" ;;
302623
+    ext4) resize2fs "${src}" ;;
302623
+    btrfs) btrfs filesystem resize max ${path} ;;
302623
+esac
302623
+
302623
+# this is useful for tests
302623
+touch /run/growfs.stamp
302623
\ No newline at end of file
302623
diff --git a/src/blockdev.rs b/src/blockdev.rs
302623
index f9701b9..2fdd6f0 100644
302623
--- a/src/blockdev.rs
302623
+++ b/src/blockdev.rs
302623
@@ -970,7 +970,7 @@ pub fn udev_settle() -> Result<()> {
302623
     // udevd hasn't yet received updates from the kernel, settle will return
302623
     // immediately, and lsblk won't pick up partition labels.  Try to sleep
302623
     // our way out of this.
302623
-    sleep(Duration::from_millis(200));
302623
+    sleep(Duration::from_millis(500));
302623
 
302623
     runcmd!("udevadm", "settle")?;
302623
     Ok(())
302623
diff --git a/systemd/coreos-installer-reboot.service b/systemd/coreos-installer-reboot.service
302623
index ad79614..f9ba80e 100644
302623
--- a/systemd/coreos-installer-reboot.service
302623
+++ b/systemd/coreos-installer-reboot.service
302623
@@ -1,6 +1,5 @@
302623
 [Unit]
302623
 Description=Reboot after CoreOS Installer
302623
-#Requires=coreos-installer.target
302623
 After=coreos-installer.service
302623
 OnFailure=emergency.target
302623
 OnFailureJobMode=replace-irreversibly
302623
diff --git a/systemd/coreos-installer.service b/systemd/coreos-installer.service
302623
index 716b783..e8199a9 100644
302623
--- a/systemd/coreos-installer.service
302623
+++ b/systemd/coreos-installer.service
302623
@@ -1,13 +1,5 @@
302623
 [Unit]
302623
 Description=CoreOS Installer
302623
-#Before=coreos-installer.target
302623
-#After=nm-run.service
302623
-#After=network-online.target
302623
-#Wants=network-online.target
302623
-# Until we retry HTTP requests let's wait here until
302623
-# systemd-resolved comes up if enabled.
302623
-# https://github.com/coreos/coreos-installer/issues/283
302623
-#After=systemd-resolved.service
302623
 
302623
 After=basic.target
302623
 # Network is enabled here
302623
diff --git a/systemd/growfs.service b/systemd/growfs.service
302623
new file mode 100644
302623
index 0000000..6d77aaa
302623
--- /dev/null
302623
+++ b/systemd/growfs.service
302623
@@ -0,0 +1,13 @@
302623
+[Unit]
302623
+Description=Grow root filesystem
302623
+DefaultDependencies=false
302623
+
302623
+After=coreos-installer.service
302623
+Before=coreos-installer-reboot.service
302623
+Requires=dev-disk-by\x2dlabel-root.device
302623
+After=dev-disk-by\x2dlabel-root.device
302623
+
302623
+[Service]
302623
+Type=oneshot
302623
+ExecStart=/usr/sbin/growfs
302623
+RemainAfterExit=yes
302623
\ No newline at end of file