Skip to content

Commit 548f2d7

Browse files
committed
Split snap-bootstrap for install mode
1 parent cebf8d6 commit 548f2d7

15 files changed

+110
-51
lines changed

debian/rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ override_dh_auto_install:
262262
cp -a $(CURDIR)/debian/tmp/usr/lib/systemd/libsystemd-shared* $(TEMPLIBDIR)
263263
set -e; \
264264
for f in \
265+
/usr/bin/systemd-escape \
265266
/lib/$(DEB_HOST_MULTIARCH)/libnss_files.so.* \
266267
/lib/$(DEB_HOST_MULTIARCH)/libnss_compat.so.* \
267268
/lib/$(DEB_HOST_MULTIARCH)/libgcc_s.so.1 \

factory/usr/lib/systemd/system-generators/snap-mounts

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,68 @@
22

33
set -eu
44

5-
if [ "$(/usr/libexec/core/get-arg snapd_recovery_mode || true)" != run ]; then
6-
exit 0
7-
fi
8-
9-
mkdir -p "${1}"
5+
normaldir="${1}"
6+
mkdir -p "${normaldir}"
107

11-
cat <<EOF >"${1}/run-mnt-data.mount"
12-
[Unit]
13-
BindsTo=dev-ubuntu-data.device
14-
After=dev-ubuntu-data.device
8+
generate_unit() {
9+
where="${1}"
10+
fs="${2}"
11+
device="${3}"
12+
shift 2
1513

16-
[Mount]
17-
Type=ext4
18-
What=/dev/ubuntu/data
19-
Where=/run/mnt/data
20-
EOF
14+
mount_unit="$(systemd-escape --suffix=mount -p "${where}")"
2115

22-
cat <<EOF >"${1}/run-mnt-ubuntu\\x2dsave.mount"
16+
case "${fs}" in
17+
tmpfs)
18+
cat <<EOF >"${normaldir}/${mount_unit}"
2319
[Unit]
24-
BindsTo=dev-ubuntu-save.device
25-
After=dev-ubuntu-save.device
2620
2721
[Mount]
28-
Type=ext4
29-
What=/dev/ubuntu/save
30-
Where=/run/mnt/ubuntu-save
22+
Type=${fs}
23+
What=${device}
24+
Where=${where}
25+
Options=nosuid,private
3126
EOF
32-
33-
cat <<EOF >"${1}/run-mnt-ubuntu\\x2dseed.mount"
27+
;;
28+
*)
29+
device_escaped="$(systemd-escape -p "${device}")"
30+
cat <<EOF >"${normaldir}/${mount_unit}"
3431
[Unit]
35-
BindsTo=dev-ubuntu-seed.device
36-
After=dev-ubuntu-seed.device
32+
BindsTo=${device_escaped}.device
33+
After=${device_escaped}.device
34+
Requires=systemd-fsck@${device_escaped}.service
35+
After=systemd-fsck@${device_escaped}.service
3736
3837
[Mount]
39-
Type=vfat
40-
What=/dev/ubuntu/seed
41-
Where=/run/mnt/ubuntu-seed
38+
Type=${fs}
39+
What=${device}
40+
Where=${where}
41+
Options=private
4242
EOF
43+
;;
44+
esac
4345

44-
cat <<EOF >"${1}/run-mnt-ubuntu\\x2dboot.mount"
45-
[Unit]
46-
BindsTo=dev-ubuntu-boot.device
47-
After=dev-ubuntu-boot.device
4846

49-
[Mount]
50-
Type=ext4
51-
What=/dev/ubuntu/boot
52-
Where=/run/mnt/ubuntu-boot
53-
EOF
47+
for target; do
48+
mkdir -p "${normaldir}/${target}"
49+
ln -s "../${mount_unit}" "${normaldir}/${target}/${mount_unit}"
50+
done
51+
}
5452

55-
mkdir -p "${1}/initrd-root-fs.target.wants"
56-
mkdir -p "${1}/initrd-root-fs.target.requires"
57-
58-
ln -s "../run-mnt-ubuntu\\x2dseed.mount" "${1}/initrd-root-fs.target.wants/run-mnt-ubuntu\\x2dseed.mount"
59-
ln -s "../run-mnt-ubuntu\\x2dboot.mount" "${1}/initrd-root-fs.target.requires/run-mnt-ubuntu\\x2dboot.mount"
60-
ln -s "../run-mnt-data.mount" "${1}/initrd-root-fs.target.requires/run-mnt-data.mount"
61-
ln -s "../run-mnt-ubuntu\\x2dsave.mount" "${1}/initrd-root-fs.target.wants/run-mnt-ubuntu\\x2dsave.mount"
53+
if mode="$(/usr/libexec/core/get-arg snapd_recovery_mode)"; then
54+
case "${mode}" in
55+
run)
56+
generate_unit /run/mnt/data ext4 /dev/ubuntu/data initrd-root-fs.target.requires
57+
generate_unit /run/mnt/ubuntu-seed vfat /dev/ubuntu/seed initrd-root-fs.target.wants
58+
generate_unit /run/mnt/ubuntu-boot ext4 /dev/ubuntu/boot initrd-root-fs.target.requires model-available.target.requires
59+
generate_unit /run/mnt/ubuntu-save ext4 /dev/ubuntu/save initrd-root-fs.target.wants
60+
;;
61+
install)
62+
generate_unit /run/mnt/ubuntu-seed vfat /dev/ubuntu/seed initrd-root-fs.target.requires model-available.target.requires
63+
generate_unit /run/mnt/data tmpfs tmpfs initrd-root-fs.target.requires
64+
;;
65+
*)
66+
exit 0
67+
;;
68+
esac
69+
fi

factory/usr/lib/systemd/system/detect-classic-sysroot.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[Unit]
22
ConditionKernelCommandLine=!snapd_recovery_mode=run
3+
ConditionKernelCommandLine=!snapd_recovery_mode=install
34
Description=Detect Ubuntu classic sysroot
45
DefaultDependencies=no
56
Before=initrd-root-device.target

factory/usr/lib/systemd/system/detect-uc-sysroot.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[Unit]
22
ConditionKernelCommandLine=!snapd_recovery_mode=run
3+
ConditionKernelCommandLine=!snapd_recovery_mode=install
34
Description=Detect Ubuntu Core sysroot
45
DefaultDependencies=no
56
Before=initrd-root-device.target

factory/usr/lib/systemd/system/initrd-root-device.target.wants/populate-writable.service renamed to factory/usr/lib/systemd/system/initrd-root-fs.target.requires/populate-writable.service

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../snap-configure-gadget.service
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../snap-ephemeral-modeenv.service
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Unit]
2+
Description=Model available

factory/usr/lib/systemd/system/populate-writable.service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Requires=sysroot.mount
1111
Requires=sysroot-writable.mount
1212
Wants=snap-initramfs-mounts.service
1313
After=snap-initramfs-mounts.service
14+
Wants=snap-configure-gadget.service
15+
After=snap-configure-gadget.service
1416

1517
ConditionPathIsMountPoint=/run/mnt/base
1618

factory/usr/lib/systemd/system/reload-model.service

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[Unit]
2-
ConditionKernelCommandLine=snapd_recovery_mode=run
2+
ConditionKernelCommandLine=|snapd_recovery_mode=run
3+
ConditionKernelCommandLine=|snapd_recovery_mode=install
34
Description=Reload model
45

56
OnFailure=emergency.target
@@ -9,10 +10,10 @@ DefaultDependencies=no
910

1011
Requires=run-mnt-data.mount
1112
After=run-mnt-data.mount
12-
Requires=run-mnt-ubuntu\x2dboot.mount
13-
After=run-mnt-ubuntu\x2dboot.mount
1413

15-
After=run-mnt-ubuntu\x2dseed.mount
14+
After=model-available.target
15+
Requires=model-available.target
16+
1617
After=sysinit.target
1718
After=tmp.mount
1819

0 commit comments

Comments
 (0)