Skip to content

Commit

Permalink
Add orange btrfs support
Browse files Browse the repository at this point in the history
- remove btrfs default subvolume,
- save btrfs device in Btrfs structure,
- rework brtfs state mountpoint detection (uses btrfs device, got rid of rootSubvolID and snapshotsSubvolID constants),
- add 'active' relative symlink to active snapshot (updated in CloseTransaction() and read in getActiveSnapshot()),
- add grub 'active_snap' variable (could it be replaced by dracut resolving the 'active' link ?),
- add grub 'root_subpath' variable which allows to prefix kernel and initrd image with a subpath,
- handle grub modules packaging under /usr/lib/elemental/bootloader
- add RelativizeLink() to recursively make symbolic links relative,
- ensure kernel and initrd are relative links (allow grub to process without mounting subvolume)
- update orange Dockerfile
  • Loading branch information
rdesaintleger committed Oct 17, 2024
1 parent 0fc05a9 commit 85f7c54
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 74 deletions.
14 changes: 11 additions & 3 deletions examples/orange/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
locales \
kbd \
podman \
btrfs-progs \
btrfsmaintenance \
snapper \
xz-utils

# Hack to prevent systemd-firstboot failures while setting keymap, this is known
Expand All @@ -59,8 +62,10 @@ ARG KBD=2.6.4
RUN curl -L https://mirrors.edge.kernel.org/pub/linux/utils/kbd/kbd-${KBD}.tar.xz --output kbd-${KBD}.tar.xz && \
tar xaf kbd-${KBD}.tar.xz && mkdir -p /usr/share/keymaps && cp -Rp kbd-${KBD}/data/keymaps/* /usr/share/keymaps/

# Symlink grub2-editenv
RUN ln -sf /usr/bin/grub-editenv /usr/bin/grub2-editenv
# Symlink grub2-editenv and snapper global config
RUN mkdir -p /etc/sysconfig && \
ln -sf //etc/default/snapper /etc/sysconfig/snapper && \
ln -sf /usr/bin/grub-editenv /usr/bin/grub2-editenv

# Just add the elemental cli
COPY --from=toolkit /usr/bin/elemental /usr/bin/elemental
Expand All @@ -75,8 +80,11 @@ RUN cp /usr/share/systemd/tmp.mount /etc/systemd/system
# the default cloud-init
RUN locale-gen --lang en_US.UTF-8

# Add default snapshotter setup
ADD snapshotter.yaml /etc/elemental/config.d/snapshotter.yaml

# Generate initrd with required elemental services
RUN elemental --debug init -f
RUN elemental --debug init --force

# Update os-release file with some metadata
RUN echo IMAGE_REPO=\"${REPO}\" >> /etc/os-release && \
Expand Down
3 changes: 3 additions & 0 deletions examples/orange/snapshotter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
snapshotter:
type: btrfs
max-snaps: 4
14 changes: 13 additions & 1 deletion pkg/action/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func RunInit(cfg *types.RunConfig, spec *types.InitSpec) error {
cfg.Config.Logger.Errorf("failed creating kernel symlink")
return err
}

err = utils.RelativizeLink(cfg.Fs, constants.KernelPath)
if err != nil {
cfg.Config.Logger.Errorf("failed relativizing kernel symlink")
return err
}
}

cfg.Config.Logger.Info("Remove any pre-existing initrd")
Expand All @@ -89,7 +95,7 @@ func RunInit(cfg *types.RunConfig, spec *types.InitSpec) error {
cfg.Config.Logger.Errorf("dracut failed with output: %s", output)
}

cfg.Config.Logger.Debugf("darcut output: %s", output)
cfg.Config.Logger.Debugf("dracut output: %s", output)

initrd, err := utils.FindInitrd(cfg.Fs, "/")
if err != nil || !strings.HasPrefix(initrd, constants.ElementalInitrd) {
Expand All @@ -102,6 +108,12 @@ func RunInit(cfg *types.RunConfig, spec *types.InitSpec) error {
err = cfg.Fs.Symlink(initrd, constants.InitrdPath)
if err != nil {
cfg.Config.Logger.Errorf("failed creating initrd symlink")
return err
}

err = utils.RelativizeLink(cfg.Fs, constants.InitrdPath)
if err != nil {
cfg.Config.Logger.Errorf("failed relativizing initrd symlink")
}

return err
Expand Down
2 changes: 2 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const (
GrubDefEntry = "Elemental"
GrubFallback = "default_fallback"
GrubPassiveSnapshots = "passive_snaps"
GrubActiveSnapshot = "active_snap"
ElementalBootloaderBin = "/usr/lib/elemental/bootloader"

// Mountpoints or links to images and partitions
Expand Down Expand Up @@ -270,6 +271,7 @@ func GetDefaultGrubModules() []string {

func GetDefaultGrubModulesPatterns() []string {
return []string{
filepath.Join(ElementalBootloaderBin, "*-efi"),
"/boot/grub2/*-efi",
"/usr/share/grub*/*-efi",
"/usr/lib/grub*/*-efi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ if [ "${snapshotter}" == "btrfs" ]; then
rootvol_unit=$(systemd-escape -p --suffix=mount ${root_part_mnt})
case "${elemental_mode}" in
*active*)
opts="ro" ;;
if [ -z "${elemental_img}" ]; then
opts="ro"
else
opts="ro,subvol=${elemental_img}"
fi
;;
*passive*)
opts="ro,subvol=${elemental_img}" ;;
*)
Expand Down
17 changes: 10 additions & 7 deletions pkg/features/embedded/grub-config/etc/elemental/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,33 @@ function set_loopdevice {

## Sources bootargs from the current volume
function source_bootargs {
source (${volume})/etc/cos/bootargs.cfg
source (${volume})/etc/elemental/bootargs.cfg
source (${volume})/${root_subpath}etc/cos/bootargs.cfg
source (${volume})/${root_subpath}etc/elemental/bootargs.cfg
}

## Defines the volume and image to boot from for active or passive boots
function set_volume {
if [ "${snapshotter}" == "btrfs" ]; then
set btrfs_relative_path="y"
set volume="${root}"
if [ -n "${1}" ]; then
set img="@/.snapshots/${1}/snapshot"
btrfs-mount-subvol ($root) / ${img}
else
set img="@/.snapshots/${active_snap}/snapshot"
fi
set root_subpath="${img}/"
elif [ -z "${1}" ]; then
set root_subpath=""
set_loopdevice /.snapshots/active
else
set root_subpath=""
set img="/.snapshots/${1}/snapshot.img"
set_loopdevice ${img}
fi
}

menuentry "${display_name}" --id active {
set mode=active
search --no-floppy --label --set=root ${state_label}
search --no-floppy --set root --label ${state_label}
set_volume
source_bootargs
linux (${volume})${kernel} ${kernelcmd} ${extra_cmdline} ${extra_active_cmdline}
Expand All @@ -98,7 +101,7 @@ menuentry "${display_name}" --id active {
for passive_snap in ${passive_snaps}; do
menuentry "${display_name} (snapshot ${passive_snap})" --id passive${passive_snap} ${passive_snap} {
set mode=passive
search --no-floppy --label --set=root ${state_label}
search --no-floppy --set root --label ${state_label}
set_volume ${2}
source_bootargs
linux (${volume})${kernel} ${kernelcmd} ${extra_cmdline} ${extra_passive_cmdline}
Expand All @@ -108,7 +111,7 @@ done

menuentry "${display_name} recovery" --id recovery {
set mode=recovery
search --no-floppy --label --set=root ${recovery_label}
search --no-floppy --set root --label ${recovery_label}

# Check the presence of the image and fallback to legacy path if not present
set img=/boot/recovery.img
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ else
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=${state_label} ${img_arg} ${snap_arg} elemental.mode=${mode} elemental.oemlabel=${oem_label} panic=5 security=selinux fsck.mode=force fsck.repair=yes"
fi

set kernel=/boot/vmlinuz
set initramfs=/boot/initrd
set kernel=/${root_subpath}boot/vmlinuz
set initramfs=/${root_subpath}boot/initrd
Loading

0 comments on commit 85f7c54

Please sign in to comment.