Skip to content

Commit

Permalink
update frzr-initramfs for new boot mount type
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Apr 8, 2024
1 parent e7228c6 commit 5745c85
Showing 1 changed file with 43 additions and 28 deletions.
71 changes: 43 additions & 28 deletions frzr-initramfs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#! /bin/bash

set -e

if [ $EUID -ne 0 ]; then
echo "$(basename $0) must be run as root"
exit 1
fi

# Check if script is being ran frmo the install media
if [ -d /tmp/frzr_root ]; then

if [ -d "${SUBVOL}" ]; then

cd ${SUBVOL}
# Mount necessary file systems
mount -t proc /proc proc/
mount -t sysfs /sys sys/
mount --rbind /dev dev/

# Set R/W permissions
btrfs property set -fts ${SUBVOL} ro false
chroot ${SUBVOL} /bin/bash <<EOF
chroot ${SUBVOL} /bin/bash <<EOF
# Commands to be ran in chroot
### Create distro mkinitcpio preset
Expand All @@ -37,11 +39,11 @@ mkinitcpio -p \${NAME%%-*}
EOF
# Set back to R/O permissions
btrfs property set -fts ${SUBVOL} ro true
# unmount filesystems
umount -l ${SUBVOL}/proc
umount -l ${SUBVOL}/sys
mount --make-rslave ${SUBVOL}/dev
umount -l ${SUBVOL}/dev
# unmount filesystems
umount -l ${SUBVOL}/proc
umount -l ${SUBVOL}/sys
mount --make-rslave ${SUBVOL}/dev
umount -l ${SUBVOL}/dev
else
echo "No deployment directory found"
exit 1
Expand All @@ -50,7 +52,6 @@ else
echo "We don't appear to be running from an arch install media"
fi


# Build initramfs from within a deployed system
if [ -d /frzr_root ]; then

Expand All @@ -68,7 +69,7 @@ if [ -d /frzr_root ]; then

BUILD="$ID"-"$VERSIONID"_"$BUILDID"
DEPLOYMENT_PATH="/frzr_root/deployments/$BUILD"

# Get locked state
RELOCK=0
LOCK_STATE=$(btrfs property get -fts "$DEPLOYMENT_PATH")
Expand All @@ -78,20 +79,20 @@ if [ -d /frzr_root ]; then
else
echo "Filesystem appears to be unlocked"
fi

echo "Generating configuration for $BUILD"

### Rebuild Initramfs with custom preset

if [ -n "$SUBVOL" ]; then
cd ${SUBVOL}
# Mount necessary file systems
mount -t proc /proc proc/
mount -t sysfs /sys sys/
mount --rbind /dev dev/

# We have to chroot for new images or else the kernel version can cause initramfs building to fail
chroot ${SUBVOL} /bin/bash <<EOF
# We have to chroot for new images or else the kernel version can cause initramfs building to fail
chroot ${SUBVOL} /bin/bash <<EOF
# Commands to be ran in chroot
### Create distro mkinitcpio preset
echo '
Expand All @@ -107,28 +108,42 @@ default_image="/boot/initramfs-linux.img"
### Rebuild Initramfs with custom preset
mkinitcpio -p \${NAME%%-*}
EOF
umount -l ${SUBVOL}/proc
umount -l ${SUBVOL}/sys
mount --make-rslave ${SUBVOL}/dev
umount -l ${SUBVOL}/dev
umount -l ${SUBVOL}/proc
umount -l ${SUBVOL}/sys
mount --make-rslave ${SUBVOL}/dev
umount -l ${SUBVOL}/dev
elif grep -q "HOOKS=.*systemd" /etc/mkinitcpio.conf; then
echo '
ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-linux"
ALL_microcode=(/boot/*-ucode.img)
PRESETS="default"
default_image="/boot/initramfs-linux.img"
' >/etc/mkinitcpio.d/$ID.preset
# If we are not doing a deployment then this will be used for local installs to rebuild initramfs
mkinitcpio -p $ID
else
echo '
echo '
ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/'$BUILD'/vmlinuz-linux"
ALL_microcode=(/boot/'$BUILD'/*-ucode.img)
PRESETS="default"
default_image="/boot/'$BUILD'/initramfs-linux.img"
' > /etc/mkinitcpio.d/$ID.preset
# If we are not doing a deployment then this will be used for local installs to rebuild initramfs
mkinitcpio -p $ID
' >/etc/mkinitcpio.d/$ID.preset
# If we are not doing a deployment then this will be used for local installs to rebuild initramfs
mkinitcpio -p $ID
fi

if [[ $RELOCK == 1 ]]; then
btrfs property set -fts ${DEPLOYMENT_PATH} ro true
btrfs property set -fts ${DEPLOYMENT_PATH} ro true
else
# Move rebuilt images to the unlocked location if system was unlocked prior
cp /boot/$BUILD/* /boot
# Move rebuilt images to the unlocked location if system was unlocked prior
if [[ -d /boot/$BUILD ]]; then
cp /boot/$BUILD/* /boot
fi
fi
fi

0 comments on commit 5745c85

Please sign in to comment.