Skip to content

Commit

Permalink
sysroot: Support /boot on / for syslinux and uboot
Browse files Browse the repository at this point in the history
People making smaller operating systems, particularly things like
cloud images, don't need to have /boot as a separate partition.
  • Loading branch information
cgwalters authored and wmanley committed Jan 17, 2018
1 parent 41df96d commit 0578449
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 19 deletions.
1 change: 1 addition & 0 deletions Makefile-tests.am
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ _installed_or_uninstalled_test_scripts = \
tests/test-admin-upgrade-unconfigured.sh \
tests/test-admin-upgrade-endoflife.sh \
tests/test-admin-deploy-syslinux.sh \
tests/test-admin-deploy-syslinux-bootonslash.sh \
tests/test-admin-deploy-2.sh \
tests/test-admin-deploy-karg.sh \
tests/test-admin-deploy-switch.sh \
Expand Down
1 change: 1 addition & 0 deletions src/libostree/ostree-bootloader-grub2.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ grub2_child_setup (gpointer user_data)
static gboolean
_ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
int bootversion,
const char *boot_path_on_disk,
GCancellable *cancellable,
GError **error)
{
Expand Down
14 changes: 9 additions & 5 deletions src/libostree/ostree-bootloader-syslinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static gboolean
append_config_from_loader_entries (OstreeBootloaderSyslinux *self,
gboolean regenerate_default,
int bootversion,
const char *boot_path_on_disk,
GPtrArray *new_lines,
GCancellable *cancellable,
GError **error)
Expand All @@ -89,15 +90,15 @@ append_config_from_loader_entries (OstreeBootloaderSyslinux *self,
val = ostree_bootconfig_parser_get (config, "linux");
if (!val)
return glnx_throw (error, "No \"linux\" key in bootloader config");
g_ptr_array_add (new_lines, g_strdup_printf ("\tKERNEL %s", val));
g_ptr_array_add (new_lines, g_strdup_printf ("\tKERNEL %s%s", boot_path_on_disk, val));

val = ostree_bootconfig_parser_get (config, "initrd");
if (val)
g_ptr_array_add (new_lines, g_strdup_printf ("\tINITRD %s", val));
g_ptr_array_add (new_lines, g_strdup_printf ("\tINITRD %s%s", boot_path_on_disk, val));

val = ostree_bootconfig_parser_get (config, "devicetree");
if (val)
g_ptr_array_add (new_lines, g_strdup_printf ("\tDEVICETREE %s", val));
g_ptr_array_add (new_lines, g_strdup_printf ("\tDEVICETREE %s%s", boot_path_on_disk, val));

val = ostree_bootconfig_parser_get (config, "options");
if (val)
Expand All @@ -110,6 +111,7 @@ append_config_from_loader_entries (OstreeBootloaderSyslinux *self,
static gboolean
_ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
int bootversion,
const char *boot_path_on_disk,
GCancellable *cancellable,
GError **error)
{
Expand Down Expand Up @@ -141,6 +143,7 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
{
const char *line = *iter;
gboolean skip = FALSE;
g_autofree char *nonostree_prefix = g_build_path ("/", boot_path_on_disk, "/ostree/", NULL);

if (parsing_label &&
(line == NULL || !g_str_has_prefix (line, "\t")))
Expand All @@ -152,7 +155,7 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
/* If this is a non-ostree kernel, just emit the lines
* we saw.
*/
if (!g_str_has_prefix (kernel_arg, "/ostree/"))
if (!g_str_has_prefix (kernel_arg, nonostree_prefix))
{
for (guint i = 0; i < tmp_lines->len; i++)
{
Expand Down Expand Up @@ -209,7 +212,8 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
regenerate_default = TRUE;

if (!append_config_from_loader_entries (self, regenerate_default,
bootversion, new_lines,
bootversion, boot_path_on_disk,
new_lines,
cancellable, error))
return FALSE;

Expand Down
22 changes: 12 additions & 10 deletions src/libostree/ostree-bootloader-uboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ append_system_uenv (OstreeBootloaderUboot *self,

static gboolean
create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,
int bootversion,
GPtrArray *new_lines,
GCancellable *cancellable,
GError **error)
int bootversion,
const char *boot_path_on_disk,
GPtrArray *new_lines,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GPtrArray) boot_loader_configs = NULL;
OstreeBootconfigParser *config;
Expand All @@ -134,11 +135,11 @@ create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,
"No \"linux\" key in bootloader config");
return FALSE;
}
g_ptr_array_add (new_lines, g_strdup_printf ("kernel_image%s=%s", index_suffix, val));
g_ptr_array_add (new_lines, g_strdup_printf ("kernel_image%s=%s%s", index_suffix, boot_path_on_disk, val));

val = ostree_bootconfig_parser_get (config, "initrd");
if (val)
g_ptr_array_add (new_lines, g_strdup_printf ("ramdisk_image%s=%s", index_suffix, val));
g_ptr_array_add (new_lines, g_strdup_printf ("ramdisk_image%s=%s%s", index_suffix, boot_path_on_disk, val));

val = ostree_bootconfig_parser_get (config, "options");
if (val)
Expand All @@ -155,9 +156,10 @@ create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,

static gboolean
_ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader,
int bootversion,
GCancellable *cancellable,
GError **error)
int bootversion,
const char *boot_path_on_disk,
GCancellable *cancellable,
GError **error)
{
OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader);

Expand All @@ -169,7 +171,7 @@ _ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader,
return FALSE;

g_autoptr(GPtrArray) new_lines = g_ptr_array_new_with_free_func (g_free);
if (!create_config_from_boot_loader_entries (self, bootversion, new_lines,
if (!create_config_from_boot_loader_entries (self, bootversion, boot_path_on_disk, new_lines,
cancellable, error))
return FALSE;

Expand Down
10 changes: 6 additions & 4 deletions src/libostree/ostree-bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ _ostree_bootloader_get_name (OstreeBootloader *self)

gboolean
_ostree_bootloader_write_config (OstreeBootloader *self,
int bootversion,
GCancellable *cancellable,
GError **error)
int bootversion,
const char *boot_path_on_disk,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (OSTREE_IS_BOOTLOADER (self), FALSE);

return OSTREE_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion,
cancellable, error);
boot_path_on_disk,
cancellable, error);
}

gboolean
Expand Down
2 changes: 2 additions & 0 deletions src/libostree/ostree-bootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct _OstreeBootloaderInterface
const char * (* get_name) (OstreeBootloader *self);
gboolean (* write_config) (OstreeBootloader *self,
int bootversion,
const char *boot_path_on_disk,
GCancellable *cancellable,
GError **error);
gboolean (* is_atomic) (OstreeBootloader *self);
Expand All @@ -61,6 +62,7 @@ const char *_ostree_bootloader_get_name (OstreeBootloader *self);

gboolean _ostree_bootloader_write_config (OstreeBootloader *self,
int bootversion,
const char *boot_path_on_disk,
GCancellable *cancellable,
GError **error);

Expand Down
47 changes: 47 additions & 0 deletions src/libostree/ostree-sysroot-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,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 at ""
*/
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 "
"whether /boot is its own partition. Assuming yes\n");
*path_out = g_strdup("");
return TRUE;
#endif /* HAVE_LIBMOUNT */
}

/**
* ostree_sysroot_write_deployments_with_options:
* @self: Sysroot
Expand Down Expand Up @@ -2239,7 +2282,11 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,

if (bootloader)
{
g_autofree char *boot_path_on_disk = NULL;
if (!boot_find_path_on_disk (&boot_path_on_disk, error))
goto out;
if (!_ostree_bootloader_write_config (bootloader, new_bootversion,
boot_path_on_disk,
cancellable, error))
{
g_prefix_error (error, "Bootloader write config: ");
Expand Down
2 changes: 2 additions & 0 deletions tests/admin-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ assert_ostree_deployment_refs() {
diff -u ostree-refs{-expected,}.txt
}

export OSTREE_DEBUG_MOUNTINFO_FILE=${test_srcdir}/boot_partition.mountinfo

orig_mtime=$(stat -c '%.Y' sysroot/ostree/deploy)
${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmaster/x86_64-runtime
rev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
Expand Down
27 changes: 27 additions & 0 deletions tests/boot_on_root_bind_mount.mountinfo
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
28 changes: 28 additions & 0 deletions tests/boot_on_root_no_bind.mountinfo
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
Loading

0 comments on commit 0578449

Please sign in to comment.