-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sysroot: Support /boot on / for syslinux and uboot #1404
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,22 @@ | |
#include "ostree-linuxfsutil.h" | ||
#include "libglnx.h" | ||
|
||
#ifdef HAVE_LIBMOUNT | ||
typedef struct libmnt_table libmnt_table; | ||
typedef struct libmnt_fs libmnt_fs; | ||
typedef struct libmnt_cache libmnt_cache; | ||
|
||
#ifdef HAVE_MNT_UNREF_CACHE | ||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (libmnt_table, mnt_unref_table); | ||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (libmnt_fs, mnt_unref_fs); | ||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (libmnt_cache, mnt_unref_cache); | ||
#else | ||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (libmnt_table, mnt_free_table); | ||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (libmnt_fs, mnt_free_fs); | ||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (libmnt_cache, mnt_free_cache); | ||
#endif | ||
#endif /* HAVE_LIBMOUNT */ | ||
|
||
#ifdef HAVE_LIBSYSTEMD | ||
#define OSTREE_VARRELABEL_ID SD_ID128_MAKE(da,67,9b,08,ac,d3,45,04,b7,89,d9,6f,81,8e,a7,81) | ||
#define OSTREE_CONFIGMERGE_ID SD_ID128_MAKE(d3,86,3b,ae,c1,3e,44,49,ab,03,84,68,4a,8a,f3,a7) | ||
|
@@ -2185,35 +2201,25 @@ is_ro_mount (const char *path) | |
* Systemd has a totally different implementation in | ||
* src/basic/mount-util.c. | ||
*/ | ||
struct libmnt_table *tb = mnt_new_table_from_file ("/proc/self/mountinfo"); | ||
struct libmnt_fs *fs; | ||
struct libmnt_cache *cache; | ||
gboolean is_mount = FALSE; | ||
struct statvfs stvfsbuf; | ||
g_autoptr(libmnt_table) tb = mnt_new_table_from_file ("/proc/self/mountinfo"); | ||
|
||
if (!tb) | ||
return FALSE; | ||
|
||
/* to canonicalize all necessary paths */ | ||
cache = mnt_new_cache (); | ||
/* to canonicalize all necessary paths */ | ||
g_autoptr(libmnt_cache) cache = mnt_new_cache (); | ||
mnt_table_set_cache (tb, cache); | ||
|
||
fs = mnt_table_find_target(tb, path, MNT_ITER_BACKWARD); | ||
is_mount = fs && mnt_fs_get_target (fs); | ||
#ifdef HAVE_MNT_UNREF_CACHE | ||
mnt_unref_table (tb); | ||
mnt_unref_cache (cache); | ||
#else | ||
mnt_free_table (tb); | ||
mnt_free_cache (cache); | ||
#endif | ||
g_autoptr(libmnt_fs) fs = mnt_table_find_target(tb, path, MNT_ITER_BACKWARD); | ||
gboolean is_mount = fs && mnt_fs_get_target (fs); | ||
|
||
if (!is_mount) | ||
return FALSE; | ||
|
||
/* We *could* parse the options, but it seems more reliable to | ||
* introspect the actual mount at runtime. | ||
*/ | ||
struct statvfs stvfsbuf; | ||
if (statvfs (path, &stvfsbuf) == 0) | ||
return (stvfsbuf.f_flag & ST_RDONLY) != 0; | ||
|
||
|
@@ -2242,6 +2248,49 @@ ostree_sysroot_write_deployments (OstreeSysroot *self, | |
cancellable, error); | ||
} | ||
|
||
/* Finds the path to /boot on the filesystem that /boot is actually stored on. | ||
* If you have a dedicated boot partition this will probably be "". If it's | ||
* stored on the root partition it will be "/boot". | ||
* | ||
* The path_out won't end with a "/". That means that "/" is represented as "" | ||
*/ | ||
static gboolean | ||
boot_find_path_on_disk(char** path_out, GError **error) | ||
{ | ||
#ifdef HAVE_LIBMOUNT | ||
g_autoptr(libmnt_table) tb = mnt_new_table(); | ||
g_assert (tb); | ||
if (mnt_table_parse_mtab(tb, getenv("OSTREE_DEBUG_MOUNTINFO_FILE")) < 0) | ||
return glnx_throw (error, "Failed to parse /proc/self/mountinfo"); | ||
|
||
const char *suffix = NULL; | ||
struct libmnt_fs *fs = mnt_table_find_target(tb, "/boot", MNT_ITER_BACKWARD); | ||
if (fs) | ||
suffix = ""; | ||
else | ||
{ | ||
suffix = "boot"; | ||
fs = mnt_table_find_target(tb, "/", MNT_ITER_BACKWARD); | ||
if (!fs) | ||
return glnx_throw (error, "libmount error: Can't find /"); | ||
} | ||
g_autofree char *path = g_build_path ("/", mnt_fs_get_root (fs), suffix, NULL); | ||
if (strcmp(path, "/") == 0) | ||
{ | ||
g_free (g_steal_pointer(&path)); | ||
path = g_strdup(""); | ||
} | ||
|
||
*path_out = g_steal_pointer(&path); | ||
return TRUE; | ||
#else /* !HAVE_LIBMOUNT */ | ||
g_printerr ("warning: ostree compiled without libmount so we can't determine " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. It feels like we should make libmount a hard dependency but also add a Or alternatively just make it a hard dependency across the board, I can't really think of a case where someone would have an issue shipping libmount. |
||
"whether /boot is its own partition. Assuming yes\n"); | ||
*path_out = g_strdup(""); | ||
return TRUE; | ||
#endif /* HAVE_LIBMOUNT */ | ||
} | ||
|
||
/* Handle writing out a new bootloader config. One reason this needs to be a | ||
* helper function is to handle wrapping it with temporarily remounting /boot | ||
* rw. | ||
|
@@ -2308,9 +2357,12 @@ write_deployments_bootswap (OstreeSysroot *self, | |
|
||
if (bootloader) | ||
{ | ||
g_autofree char *boot_path_on_disk = NULL; | ||
if (!boot_find_path_on_disk (&boot_path_on_disk, error)) | ||
return glnx_prefix_error (error, "Bootloader find /boot path"); | ||
if (!_ostree_bootloader_write_config (bootloader, new_bootversion, | ||
new_deployments, cancellable, | ||
error)) | ||
new_deployments, boot_path_on_disk, | ||
cancellable, error)) | ||
return glnx_prefix_error (error, "Bootloader write config"); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
13 14 179:1 / /sysroot rw,relatime shared:5 - ext4 /dev/root rw,data=ordered | ||
14 1 179:1 /ostree/deploy/linux/deploy/61892bc01f9afdef900d7a7904fe934ac7fc8caf9befddc1faf0f6b4f179bf35.0 / rw,relatime shared:1 - ext4 /dev/root rw,data=ordered | ||
15 14 179:1 /ostree/deploy/linux/var /var rw,relatime shared:2 - ext4 /dev/root rw,data=ordered | ||
16 14 179:1 /boot /boot rw,relatime shared:3 - ext4 /dev/root rw,data=ordered | ||
17 14 179:1 /ostree/deploy/linux/deploy/61892bc01f9afdef900d7a7904fe934ac7fc8caf9befddc1faf0f6b4f179bf35.0/usr /usr ro,relatime shared:4 - ext4 /dev/root rw,data=ordered | ||
18 14 0:12 / /sys rw,nosuid,nodev,noexec,relatime shared:6 - sysfs sysfs rw | ||
19 14 0:3 / /proc rw,nosuid,nodev,noexec,relatime shared:10 - proc proc rw | ||
20 14 0:5 / /dev rw,nosuid shared:11 - devtmpfs devtmpfs rw,size=958480k,nr_inodes=181514,mode=755 | ||
21 20 0:13 / /dev/shm rw,nosuid,nodev shared:12 - tmpfs tmpfs rw | ||
22 20 0:10 / /dev/pts rw,nosuid,noexec,relatime shared:13 - devpts devpts rw,gid=5,mode=620,ptmxmode=000 | ||
23 14 0:14 / /run rw,nosuid,nodev shared:14 - tmpfs tmpfs rw,mode=755 | ||
24 23 0:15 / /run/lock rw,nosuid,nodev,noexec,relatime shared:15 - tmpfs tmpfs rw,size=5120k | ||
25 18 0:16 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:7 - tmpfs tmpfs ro,mode=755 | ||
26 25 0:17 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd | ||
27 18 0:18 / /sys/fs/pstore rw,nosuid,nodev,noexec,relatime shared:9 - pstore pstore rw | ||
28 25 0:19 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:16 - cgroup cgroup rw,freezer | ||
29 25 0:20 / /sys/fs/cgroup/debug rw,nosuid,nodev,noexec,relatime shared:17 - cgroup cgroup rw,debug | ||
30 25 0:21 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:18 - cgroup cgroup rw,cpuset | ||
31 25 0:22 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:19 - cgroup cgroup rw,devices | ||
32 25 0:23 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:20 - cgroup cgroup rw,memory | ||
33 25 0:24 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:21 - cgroup cgroup rw,cpuacct,cpu | ||
34 25 0:25 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:22 - cgroup cgroup rw,perf_event | ||
35 19 0:26 / /proc/sys/fs/binfmt_misc rw,relatime shared:23 - autofs systemd-1 rw,fd=24,pgrp=1,timeout=0,minproto=5,maxproto=5,direct | ||
36 20 0:11 / /dev/mqueue rw,relatime shared:24 - mqueue mqueue rw | ||
37 14 0:27 / /tmp rw,nosuid,nodev shared:25 - tmpfs tmpfs rw | ||
38 18 0:6 / /sys/kernel/debug rw,relatime shared:26 - debugfs debugfs rw | ||
39 18 0:28 / /sys/fs/fuse/connections rw,relatime shared:27 - fusectl fusectl rw |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
19 25 0:18 / /sys rw,nosuid,nodev,noexec,relatime shared:7 - sysfs sysfs rw | ||
20 25 0:4 / /proc rw,nosuid,nodev,noexec,relatime shared:12 - proc proc rw | ||
21 25 0:6 / /dev rw,nosuid,relatime shared:2 - devtmpfs udev rw,size=3895676k,nr_inodes=973919,mode=755 | ||
22 21 0:14 / /dev/pts rw,nosuid,noexec,relatime shared:3 - devpts devpts rw,gid=5,mode=620,ptmxmode=000 | ||
23 25 0:19 / /run rw,nosuid,noexec,relatime shared:5 - tmpfs tmpfs rw,size=782788k,mode=755 | ||
25 0 8:1 / / rw,relatime shared:1 - ext4 /dev/sda1 rw,errors=remount-ro,data=ordered | ||
26 19 0:12 / /sys/kernel/security rw,nosuid,nodev,noexec,relatime shared:8 - securityfs securityfs rw | ||
27 21 0:21 / /dev/shm rw,nosuid,nodev shared:4 - tmpfs tmpfs rw | ||
28 23 0:22 / /run/lock rw,nosuid,nodev,noexec,relatime shared:6 - tmpfs tmpfs rw,size=5120k | ||
29 19 0:23 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:9 - tmpfs tmpfs ro,mode=755 | ||
30 29 0:24 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime shared:10 - cgroup cgroup rw,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd | ||
31 19 0:25 / /sys/fs/pstore rw,nosuid,nodev,noexec,relatime shared:11 - pstore pstore rw | ||
32 29 0:26 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:13 - cgroup cgroup rw,memory | ||
33 29 0:27 / /sys/fs/cgroup/net_cls,net_prio rw,nosuid,nodev,noexec,relatime shared:14 - cgroup cgroup rw,net_cls,net_prio | ||
34 29 0:28 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:15 - cgroup cgroup rw,blkio | ||
35 29 0:29 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:16 - cgroup cgroup rw,devices | ||
36 29 0:30 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:17 - cgroup cgroup rw,cpu,cpuacct | ||
37 29 0:31 / /sys/fs/cgroup/pids rw,nosuid,nodev,noexec,relatime shared:18 - cgroup cgroup rw,pids | ||
38 29 0:32 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:19 - cgroup cgroup rw,cpuset | ||
39 29 0:33 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:20 - cgroup cgroup rw,perf_event | ||
40 29 0:34 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:21 - cgroup cgroup rw,freezer | ||
41 29 0:35 / /sys/fs/cgroup/hugetlb rw,nosuid,nodev,noexec,relatime shared:22 - cgroup cgroup rw,hugetlb | ||
42 21 0:17 / /dev/mqueue rw,relatime shared:23 - mqueue mqueue rw | ||
43 19 0:7 / /sys/kernel/debug rw,relatime shared:24 - debugfs debugfs rw | ||
44 20 0:36 / /proc/sys/fs/binfmt_misc rw,relatime shared:25 - autofs systemd-1 rw,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct | ||
45 21 0:37 / /dev/hugepages rw,relatime shared:26 - hugetlbfs hugetlbfs rw | ||
46 19 0:38 / /sys/fs/fuse/connections rw,relatime shared:27 - fusectl fusectl rw | ||
47 44 0:39 / /proc/sys/fs/binfmt_misc rw,relatime shared:28 - binfmt_misc binfmt_misc rw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Check for interactions with #1767. This might confuse
/boot
as bind-mount with/boot
on own FS.Also: This currently won't work for
ostree admin deploy --sysroot=xxx
. Sometimes this is useful for embedded development where I'm deploying to an SD card and then plugging it into the embedded hardware for boot.I've got some ideas on how to fix this. I think I've implemented it in the past (in python), but I can't remember where. I'll have a look.