diff --git a/Makefile-tests.am b/Makefile-tests.am index 9198eb3183..350209dedb 100644 --- a/Makefile-tests.am +++ b/Makefile-tests.am @@ -116,6 +116,7 @@ _installed_or_uninstalled_test_scripts = \ tests/test-pull-mirrorlist.sh \ tests/test-summary-update.sh \ tests/test-summary-view.sh \ + tests/test-no-initramfs.sh \ $(NULL) experimental_test_scripts = \ diff --git a/src/boot/grub2/ostree-grub-generator b/src/boot/grub2/ostree-grub-generator index ad8c2b8301..97ef4d69fb 100644 --- a/src/boot/grub2/ostree-grub-generator +++ b/src/boot/grub2/ostree-grub-generator @@ -1,7 +1,6 @@ #!/bin/sh -# To use a custom script for generating grub.cfg, set the --with-grub2-mkconfig=no -# configure switch when configuring and building OSTree. +# The builtin grub.cfg generator. # # This script is called by ostree/src/libostree/ostree-bootloader-grub2.c whenever # boot loader configuration file needs to be updated. It can be used as a template @@ -28,7 +27,7 @@ entries_path=$(dirname $new_grub2_cfg)/entries read_config() { - config_file=${entries_path}/${1} + config_file=${1} title="" initrd="" options="" @@ -67,11 +66,13 @@ populate_menu() else boot_prefix="${OSTREE_BOOT_PARTITION}" fi - for config in $(ls ${entries_path}); do + for config in $(ls $entries_path/*.conf); do read_config ${config} menu="${menu}menuentry '${title}' {\n" menu="${menu}\t linux ${boot_prefix}${linux} ${options}\n" - menu="${menu}\t initrd ${boot_prefix}${initrd}\n" + if [ -n "${initrd}" ] ; then + menu="${menu}\t initrd ${boot_prefix}${initrd}\n" + fi menu="${menu}}\n\n" done # The printf command seems to be more reliable across shells for special character (\n, \t) evaluation diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 29c90ea7f5..5dc5bde074 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1700,21 +1700,29 @@ install_deployment_kernel (OstreeSysroot *sysroot, g_autofree char * boot_relpath = g_strconcat ("/", bootcsumdir, "/", kernel_layout->kernel_namever, NULL); ostree_bootconfig_parser_set (bootconfig, "linux", boot_relpath); + val = ostree_bootconfig_parser_get (bootconfig, "options"); + g_autoptr(OstreeKernelArgs) kargs = _ostree_kernel_args_from_string (val); + if (kernel_layout->initramfs_namever) { g_autofree char * boot_relpath = g_strconcat ("/", bootcsumdir, "/", kernel_layout->initramfs_namever, NULL); ostree_bootconfig_parser_set (bootconfig, "initrd", boot_relpath); } - - val = ostree_bootconfig_parser_get (bootconfig, "options"); + else + { + g_autofree char *prepare_root_arg = NULL; + prepare_root_arg = g_strdup_printf ("init=/ostree/boot.%d/%s/%s/%d/usr/lib/ostree/ostree-prepare-root", + new_bootversion, osname, bootcsum, + ostree_deployment_get_bootserial (deployment)); + _ostree_kernel_args_replace_take (kargs, g_steal_pointer (&prepare_root_arg)); + } /* Note this is parsed in ostree-impl-system-generator.c */ g_autofree char *ostree_kernel_arg = g_strdup_printf ("ostree=/ostree/boot.%d/%s/%s/%d", new_bootversion, osname, bootcsum, ostree_deployment_get_bootserial (deployment)); - g_autoptr(OstreeKernelArgs) kargs = _ostree_kernel_args_from_string (val); - _ostree_kernel_args_replace_take (kargs, ostree_kernel_arg); - ostree_kernel_arg = NULL; + _ostree_kernel_args_replace_take (kargs, g_steal_pointer (&ostree_kernel_arg)); + g_autofree char *options_key = _ostree_kernel_args_to_string (kargs); ostree_bootconfig_parser_set (bootconfig, "options", options_key); diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c index 83550331d4..8da9dbc3eb 100644 --- a/src/ostree/ot-admin-builtin-deploy.c +++ b/src/ostree/ot-admin-builtin-deploy.c @@ -40,6 +40,7 @@ static char **opt_kernel_argv_append; static gboolean opt_kernel_proc_cmdline; static char *opt_osname; static char *opt_origin_path; +static gboolean opt_kernel_arg_none; /* ATTENTION: * Please remember to update the bash-completion script (bash/ostree) and @@ -56,6 +57,7 @@ static GOptionEntry options[] = { { "karg-proc-cmdline", 0, 0, G_OPTION_ARG_NONE, &opt_kernel_proc_cmdline, "Import current /proc/cmdline", NULL }, { "karg", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv, "Set kernel argument, like root=/dev/sda1; this overrides any earlier argument with the same name", "NAME=VALUE" }, { "karg-append", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv_append, "Append kernel argument; useful with e.g. console= that can be used multiple times", "NAME=VALUE" }, + { "karg-none", 0, 0, G_OPTION_ARG_NONE, &opt_kernel_arg_none, "Do not import kernel arguments", NULL }, { NULL } }; @@ -79,6 +81,12 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat return FALSE; } + if (opt_kernel_proc_cmdline && opt_kernel_arg_none) + { + ot_util_usage_error (context, "Can't specify both --karg-proc-cmdline and --karg-none", error); + return FALSE; + } + const char *refspec = argv[1]; OstreeRepo *repo = ostree_sysroot_repo (sysroot); @@ -130,7 +138,7 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat if (!_ostree_kernel_args_append_proc_cmdline (kargs, cancellable, error)) return FALSE; } - else if (merge_deployment) + else if (merge_deployment && !opt_kernel_arg_none) { OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (merge_deployment); g_auto(GStrv) previous_args = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index 9b8c33818e..43e15fcc3d 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -102,10 +102,16 @@ main(int argc, char *argv[]) struct stat stbuf; int we_mounted_proc = 0; - if (argc < 2) - root_arg = "/"; + if (getpid() == 1) + { + root_arg = "/"; + } else - root_arg = argv[1]; + { + if (argc < 2) + err (EXIT_FAILURE, "usage: ostree-prepare-root SYSROOT"); + root_arg = argv[1]; + } if (stat ("/proc/cmdline", &stbuf) < 0) { diff --git a/tests/test-no-initramfs.sh b/tests/test-no-initramfs.sh new file mode 100755 index 0000000000..7c23a3e754 --- /dev/null +++ b/tests/test-no-initramfs.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +. $(dirname $0)/libtest.sh + +echo "1..7" + +setup_os_repository "archive-z2" "uboot" + +cd ${test_tmpdir} + +${CMD_PREFIX} ostree --repo=sysroot/ostree/repo remote add --set=gpg-verify=false testos $(cat httpd-address)/ostree/testos-repo +${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull testos testos/buildmaster/x86_64-runtime +${CMD_PREFIX} ostree admin deploy --karg=root=LABEL=rootfs --os=testos testos:testos/buildmaster/x86_64-runtime + +assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'root=LABEL=rootfs' +assert_not_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'init=' + +echo "ok deployment with initramfs" + +pull_test_tree() { + kernel_contents=$1 + initramfs_contents=$2 + + printf "TEST SETUP:\n kernel: %s\n initramfs: %s\n layout: %s\n" \ + "$kernel_contents" "$initramfs_contents" "$layout" + + rm -rf ${test_tmpdir}/osdata/usr/lib/modules/3.6.0/{initramfs.img,vmlinuz} \ + ${test_tmpdir}/osdata/usr/lib/ostree-boot \ + ${test_tmpdir}/osdata/boot + if [ "$layout" = "/usr/lib/modules" ]; then + # Fedora compatible layout + cd ${test_tmpdir}/osdata/usr/lib/modules/3.6.0 + echo -n "$kernel_contents" > vmlinuz + [ -n "$initramfs_contents" ] && echo -n "$initramfs_contents" > initramfs.img + elif [ "$layout" = "/usr/lib/ostree-boot" ] || [ "$layout" = "/boot" ]; then + # "Legacy" layout + mkdir -p "${test_tmpdir}/osdata/$layout" + cd "${test_tmpdir}/osdata/$layout" + bootcsum=$(echo -n "$kernel_contents$initramfs_contents" \ + | sha256sum | cut -f 1 -d ' ') + echo -n "$kernel_contents" > vmlinuz-${bootcsum} + [ -n "$initramfs_contents" ] && echo -n "$initramfs_contents" > initramfs-${bootcsum} + else + exit 1 + fi + cd - + ${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit --tree=dir=osdata/ -b testos/buildmaster/x86_64-runtime + ${CMD_PREFIX} ostree pull testos:testos/buildmaster/x86_64-runtime +} + +get_key_from_bootloader_conf() { + conffile=$1 + key=$2 + + assert_file_has_content "$conffile" "^$key" + awk "/^$key/ { print \$2 }" "$conffile" +} + +for layout in /usr/lib/modules /usr/lib/ostree-boot /boot; +do + pull_test_tree "the kernel only" + ${CMD_PREFIX} ostree admin deploy --os=testos --karg=root=/dev/sda2 --karg=rootwait testos:testos/buildmaster/x86_64-runtime + assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'rootwait' + assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'init=' + assert_not_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'initrd' + + echo "ok switching to bootdir with no initramfs layout=$layout" + + pull_test_tree "the kernel" "initramfs to assist the kernel" + ${CMD_PREFIX} ostree admin deploy --os=testos --karg-none --karg=root=LABEL=rootfs testos:testos/buildmaster/x86_64-runtime + assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'initrd' + assert_file_has_content sysroot/boot/$(get_key_from_bootloader_conf sysroot/boot/loader/entries/ostree-testos-0.conf "initrd") "initramfs to assist the kernel" + assert_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'root=LABEL=rootfs' + assert_not_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'rootwait' + assert_not_file_has_content sysroot/boot/loader/entries/ostree-testos-0.conf 'init=' + + echo "ok switching from no initramfs to initramfs enabled sysroot layout=$layout" +done