Skip to content

Commit

Permalink
WIP experimental btrfs setup
Browse files Browse the repository at this point in the history
Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Oct 20, 2023
1 parent fd92278 commit db4a18b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
3 changes: 3 additions & 0 deletions examples/green/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ RUN ARCH=$(uname -m); \
less \
sudo \
curl \
btrfsprogs \
snapper \
tukit \
sed

# Just add the elemental cli
Expand Down
36 changes: 13 additions & 23 deletions pkg/features/embedded/grub-config/etc/cos/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,30 @@ insmod all_video
insmod gfxterm
insmod loopback
insmod squash4
insmod btrfs

set loopdev="loop0"
set btrfs_relative_path="y"

menuentry "${display_name}" --id cos {
# label is kept around for backward compatibility
set label=${active_label}
set img=/cOS/active.img
loopback $loopdev /$img
source ($loopdev)/etc/cos/bootargs.cfg
linux ($loopdev)$kernel $kernelcmd ${extra_cmdline} ${extra_active_cmdline}
initrd ($loopdev)$initramfs
loopback -d $loopdev
btrfs-mount-subvol ($root) / ${active_snapshot}
set img=${active_snapshot}
source /etc/cos/bootargs.cfg
linux $kernel $kernelcmd ${extra_cmdline} ${extra_active_cmdline}
initrd $initramfs
}

menuentry "${display_name} (fallback)" --id fallback {
# label is kept around for backward compatibility
set label=${passive_label}
set img=/cOS/passive.img
loopback $loopdev /$img
source ($loopdev)/etc/cos/bootargs.cfg
linux ($loopdev)$kernel $kernelcmd ${extra_cmdline} ${extra_passive_cmdline}
initrd ($loopdev)$initramfs
loopback -d $loopdev
btrfs-mount-subvol ($root) / ${passive_snapshot}
set img=${passive_snapshot}
source /etc/cos/bootargs.cfg
linux $kernel $kernelcmd ${extra_cmdline} ${extra_passive_cmdline}
initrd $initramfs
}

menuentry "${display_name} recovery" --id recovery {
# label and recoverylabel are kept around for backward compatibility
if [ -n "${system_label}" ]; then
set label=${system_label}
else
set recoverylabel=${recovery_label}
fi
set img=/cOS/recovery.img
search --no-floppy --label --set=root $recovery_label
set img=/cOS/recovery.img
loopback $loopdev /$img
source ($loopdev)/etc/cos/bootargs.cfg
linux ($loopdev)$kernel $kernelcmd ${extra_cmdline} ${extra_recovery_cmdline}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ set kernel=/boot/vmlinuz
if [ "${img}" == "/cOS/recovery.img" ]; then
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$recovery_label cos-img/filename=$img security=selinux selinux=0 rd.neednet=1 rd.cos.oemlabel=$oem_label rd.cos.mount=LABEL=$oem_label:/oem"
else
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$state_label cos-img/filename=$img panic=5 security=selinux selinux=1 rd.neednet=1 rd.cos.oemlabel=$oem_label rd.cos.mount=LABEL=$oem_label:/oem rd.cos.mount=LABEL=$persistent_label:/usr/local fsck.mode=force fsck.repair=yes"
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$state_label cos-img/filename=$img panic=5 security=selinux selinux=1 rd.neednet=1 rd.cos.oemlabel=$oem_label rd.cos.mount=LABEL=$oem_label:/oem rd.cos.mount=LABEL=$persistent_label:/usr/local"
fi
set initramfs=/boot/initrd
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ mkdir -p "$GENERATOR_DIR/$dev.device.d"
echo "RequiresMountsFor=${root_part_mnt}"
echo "[Mount]"
echo "Where=/sysroot"
echo "What=${root_part_mnt}/${cos_img#/}"
echo "Options=${cos_root_perm},suid,dev,exec,auto,nouser,async"
echo "What=${root}"
echo "Options=${cos_root_perm},subvol=${cos_img},suid,dev,exec,auto,nouser,async"
} > "$GENERATOR_DIR"/sysroot.mount

if [ ! -e "$GENERATOR_DIR/initrd-root-fs.target.requires/sysroot.mount" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,18 @@ readLayoutConfig

[ -z "${cos_overlay}" ] && exit 0

# Hack to get the root device and its mounted subvolume
snapshot=${root##*[}
snapshot=${snapshot%%]}
root=${root%%[*}

# If sysroot is already an overlay do not prepare the rw overlay
if [ "${root_fstype}" != "overlay" ]; then
if [ -f "${base_part}" ]; then
fstab="${base_part} /run/initramfs/cos-state auto ${cos_root_perm} 0 0\n"
fi
fstab+="${root} / auto ${cos_root_perm} 0 0\n"

fstab+="${root} / auto ${cos_root_perm},subvol=${snapshot} 0 0\n"
fstab+=$(mountOverlayBase)
fi

Expand Down
8 changes: 6 additions & 2 deletions pkg/utils/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ const (
grubCfgFile = "grub.cfg"

grubEFICfgTmpl = `
insmod btrfs
set btrfs_relative_path="y"
search --no-floppy --label --set=root %s
set prefix=($root)/` + grubConfDir + `
configfile ($root)/` + grubConfDir + `/%s
configfile ${prefix}/` + grubCfgFile + `
`
)

Expand Down Expand Up @@ -254,7 +258,7 @@ func (g Grub) InstallEFI(rootDir, bootDir, efiDir, deviceLabel string) (string,
// Add grub.cfg in EFI that chainloads the grub.cfg in recovery
// Notice that we set the config to /grub2/grub.cfg which means the above we need to copy the file from
// the installation source into that dir
grubCfgContent := []byte(fmt.Sprintf(grubEFICfgTmpl, deviceLabel, grubCfgFile))
grubCfgContent := []byte(fmt.Sprintf(grubEFICfgTmpl, deviceLabel))
// Fallback
err = g.config.Fs.WriteFile(filepath.Join(efiDir, fallbackEFIPath, grubCfgFile), grubCfgContent, cnst.FilePerm)
if err != nil {
Expand Down

0 comments on commit db4a18b

Please sign in to comment.