Skip to content

Commit

Permalink
Install in initrd
Browse files Browse the repository at this point in the history
  • Loading branch information
valentindavid committed Jun 15, 2023
1 parent 02c1ff6 commit 2f3051d
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 2 deletions.
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Build-Depends: debhelper-compat (= 12), dh-python, python3:any, dracut-core, qui
squashfs-tools,
snapd (>= 2.50+20.04),
systemd-bootchart,
cryptsetup-bin,
golang-go, indent, libapparmor-dev, libcap-dev, libfuse-dev, libglib2.0-dev, liblzma-dev, liblzo2-dev, libseccomp-dev, libudev-dev, openssh-client, pkg-config, python3, python3-docutils, python3-markdown, squashfs-tools, tzdata, udev, xfslibs-dev
Standards-Version: 4.4.1
Build-Conflicts: snapd (= 2.59.3+20.04)
Expand Down
7 changes: 6 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,18 @@ INSTALL_FILES_FROM_HOST= \
/lib/$(DEB_HOST_MULTIARCH)/libnss_files.so.* \
/lib/systemd/system/snapd.recovery-chooser-trigger.service \
/lib/systemd/systemd-bootchart \
/sbin/cryptsetup \
/sbin/dmsetup \
/sbin/e2fsck \
/sbin/fsck \
/sbin/fsck.vfat \
/sbin/sfdisk \
/usr/bin/partx \
/usr/bin/tar \
/usr/bin/unsquashfs \
/usr/lib/snapd/info \
/usr/lib/snapd/snap-bootstrap
/usr/lib/snapd/snap-bootstrap \
/usr/sbin/mkfs.ext4

override_dh_auto_install: TEMPLIBDIR := $(shell mktemp -d)
override_dh_auto_install:
Expand Down
2 changes: 2 additions & 0 deletions factory/usr/lib/modules-load.d/ubuntu-core-initramfs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ ahci
libahci
usb-storage
nls_iso8859-1
# For fsck.vfat
kmod-nls-cp437
sdhci
sdhci-pci
sdhci-acpi
Expand Down
4 changes: 3 additions & 1 deletion factory/usr/lib/the-modeenv
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ cp /sysroot/run/image.fstab /run/
# TODO:UC20: move this logic into snap-bootstrap to be incorporated with
# initramfs-mounts

mode="$(/usr/libexec/core/get-mode mode)" || mode="$(/usr/libexec/core/get-arg snapd_recovery_mode)" || mode="unknown"

# Always bind-mount all the host filesystems
mkdir -p /run/mnt/host
echo '/run/mnt/host /host none rbind 0 0' >> /run/image.fstab
if grep -q snapd_recovery_mode=run /proc/cmdline; then
if [ "${mode}" = "run" ]; then
# TODO:UC20: support other bootloaders too
if [ -f /run/mnt/ubuntu-boot/EFI/ubuntu/grub.cfg ]; then
echo '/run/mnt/ubuntu-boot/EFI/ubuntu /boot/grub none bind 0 0' >> /run/image.fstab
Expand Down
84 changes: 84 additions & 0 deletions factory/usr/libexec/core/get-arg
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/sh

# Usage:
# get-arg param-name
#
# get-arg will look for kernel parameter "param-name" or "param_name"
# and return 0 if found, 1 if not found. If the parameter as a value,
# e.g. "param-name=the-value", then the value "the-value" will be
# printed.

# For more information on how to parse kernel parameters, see function
# `next_arg` in
# https://github.com/torvalds/linux/blob/master/lib/cmdline.c

set -eu

if [ "$#" -ne 1 ]; then
echo "Expected kernel parameter name as argument" 1>&2
exit 1
fi

looking_for="$(echo "${1}" | sed 's/_/-/g')"

if [ "${SYSTEMD_PROC_CMDLINE:+set}" = set ]; then
# Using same debug variable as systemd for testing
cmdline="${SYSTEMD_PROC_CMDLINE}"
else
cmdline=$(cat /proc/cmdline)
fi

set --

# We cannot use ANSI-C quoting (e.g. $'\n') in busybox-initramfs
whitespaces="$(printf '\t\n\v\f\r \xA0')"
in_quote=no
param=
current="${cmdline}"
while [ -n "${current}" ]; do
# We cannot use subtring parameter expansion
# (e.g. ${cmdline:$i:1}) in busybox-initramfs
suffix="${current#?}"
char="${current%${suffix}}"
current="${suffix}"
case "${char}" in
["${whitespaces}"])
if [ "${in_quote}" = no ]; then
if [ -n "${param}" ]; then
set -- "$@" "${param}"
fi
param=
else
param="${param}${char}"
fi
;;
'"')
if [ "${in_quote}" = yes ]; then
in_quote=no
else
in_quote=yes
fi
;;
*)
param="${param}${char}"
;;
esac
done

if [ -n "${param}" ]; then
set -- "$@" "${param}"
fi

for param in "$@"; do
name="$(echo "${param%%=*}" | sed 's/_/-/g')"
if [ "${name}" = "${looking_for}" ]; then
case "${param}" in
*=*)
echo "${param#*=}"
;;
esac
exit 0
fi
done

exit 1
35 changes: 35 additions & 0 deletions factory/usr/libexec/core/get-mode
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

# Usage:
# get-mode entry-name /path/to/modeenv
#
# get-mode will look for entry-name in modeenv files and return 0 if
# found, 1 if not found. It will print the value to stdout.

set -eu

if [ "$#" -gt 2 ]; then
echo "Too many arguments" 1>&2
exit 1
fi

if [ "$#" -lt 1 ]; then
echo "Expected a name as argument" 1>&2
exit 1
fi

name="${1}"
modeenv="${2:-/run/mnt/ubuntu-data/system-data/var/lib/snapd/modeenv}"

while read -r line; do
case "${line}" in
"${name}"=*)
echo "${line#*=}"
exit 0
;;
*)
;;
esac
done <"${modeenv}"

exit 1

0 comments on commit 2f3051d

Please sign in to comment.