Blame SOURCES/coidracut3.patch

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