Skip to content

Commit 7236536

Browse files
admin: Add an esp-upgrade subcommand
The files in the EFI System Partition (ESP) are never updated by OSTree so users will always have the same ESP that was created during installation. This happens because the ESP uses a vfat filesystem, which doesn't support symbolic links so the update can't be atomic and part of the transaction. But since the ESP contains the bootloader components (shim, grub, etc) and other important EFI binaries like the ones needed for firmware updates, it should be a way to update the ESP with the latest version of the binaries. These components are stored in the /usr/lib/ostree-boot/efi directory of a deployment due rpm-ostree replacing the /boot path to /usr/lib/ostree-boot. Add a ostree-admin-esp-upgrade subcommand, that just copies the content of /usr/lib/ostree-boot/efi to /boot/efi, so users can update the ESP and get the latest version of the files that are present in the booted deployment. Closes: ostreedev#1649
1 parent 0bcc68d commit 7236536

6 files changed

+172
-1
lines changed

Makefile-man.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ostree-admin-config-diff.1 ostree-admin-deploy.1 \
2626
ostree-admin-init-fs.1 ostree-admin-instutil.1 ostree-admin-os-init.1 \
2727
ostree-admin-status.1 ostree-admin-set-origin.1 ostree-admin-switch.1 \
2828
ostree-admin-undeploy.1 ostree-admin-upgrade.1 ostree-admin-unlock.1 \
29-
ostree-admin-pin.1 \
29+
ostree-admin-pin.1 ostree-admin-esp-upgrade.1 \
3030
ostree-admin.1 ostree-cat.1 ostree-checkout.1 ostree-checksum.1 \
3131
ostree-commit.1 ostree-create-usb.1 ostree-export.1 ostree-gpg-sign.1 \
3232
ostree-config.1 ostree-diff.1 ostree-find-remotes.1 ostree-fsck.1 \

Makefile-ostree.am

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ ostree_SOURCES += \
7979
src/ostree/ot-admin-builtin-status.c \
8080
src/ostree/ot-admin-builtin-switch.c \
8181
src/ostree/ot-admin-builtin-pin.c \
82+
src/ostree/ot-admin-builtin-esp-upgrade.c \
8283
src/ostree/ot-admin-builtin-upgrade.c \
8384
src/ostree/ot-admin-builtin-unlock.c \
8485
src/ostree/ot-admin-builtins.h \

man/ostree-admin-esp-upgrade.xml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version='1.0'?> <!--*-nxml-*-->
2+
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3+
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4+
5+
<!--
6+
Copyright 2019 Red Hat, Inc.
7+
8+
SPDX-License-Identifier: LGPL-2.0+
9+
10+
This library is free software; you can redistribute it and/or
11+
modify it under the terms of the GNU Lesser General Public
12+
License as published by the Free Software Foundation; either
13+
version 2 of the License, or (at your option) any later version.
14+
15+
This library is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
Lesser General Public License for more details.
19+
20+
You should have received a copy of the GNU Lesser General Public
21+
License along with this library; if not, write to the
22+
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23+
Boston, MA 02111-1307, USA.
24+
-->
25+
26+
<refentry id="ostree">
27+
28+
<refentryinfo>
29+
<title>ostree admin esp-upgrade</title>
30+
<productname>OSTree</productname>
31+
32+
<authorgroup>
33+
<author>
34+
<contrib>Developer</contrib>
35+
<firstname>Javier</firstname>
36+
<surname>Martinez Canillas</surname>
37+
<email>javierm@redhat.com</email>
38+
</author>
39+
</authorgroup>
40+
</refentryinfo>
41+
42+
<refmeta>
43+
<refentrytitle>ostree admin esp-upgrade</refentrytitle>
44+
<manvolnum>1</manvolnum>
45+
</refmeta>
46+
47+
<refnamediv>
48+
<refname>ostree-admin-esp-upgrade</refname>
49+
<refpurpose>Upgrade the EFI System Partition (ESP) with files from the current deployment</refpurpose>
50+
</refnamediv>
51+
52+
<refsynopsisdiv>
53+
<cmdsynopsis>
54+
<command>ostree admin esp-upgrade</command>
55+
</cmdsynopsis>
56+
</refsynopsisdiv>
57+
58+
<refsect1>
59+
<title>Description</title>
60+
61+
<para>
62+
Upgrade the EFI System Partition (ESP) with the files in the /usr/lib/ostree-boot/efi/ directory of the current deployment.
63+
</para>
64+
</refsect1>
65+
66+
<refsect1>
67+
<title>Example</title>
68+
<para><command>$ ostree admin esp-upgrade</command></para>
69+
</refsect1>
70+
</refentry>
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (C) 2019 Red Hat, Inc.
3+
*
4+
* SPDX-License-Identifier: LGPL-2.0+
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2 of the License, or (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with this library; if not, write to the
18+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19+
* Boston, MA 02111-1307, USA.
20+
*
21+
* Author: Javier Martinez Canillas <javierm@redhat.com>
22+
*/
23+
24+
#include "config.h"
25+
26+
#include "ostree-sysroot-private.h"
27+
#include "ot-main.h"
28+
#include "ot-admin-builtins.h"
29+
#include "ot-admin-functions.h"
30+
#include "otutil.h"
31+
32+
static GOptionEntry options[] = {
33+
{ NULL }
34+
};
35+
36+
gboolean
37+
ot_admin_builtin_esp_upgrade (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
38+
{
39+
g_autoptr(GOptionContext) context = g_option_context_new ("");
40+
41+
g_autoptr(OstreeSysroot) sysroot = NULL;
42+
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
43+
OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
44+
invocation, &sysroot, cancellable, error))
45+
return FALSE;
46+
47+
g_autoptr(OstreeRepo) repo = NULL;
48+
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
49+
return FALSE;
50+
51+
g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot);
52+
OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
53+
54+
g_autoptr(OstreeDeployment) pending_deployment = NULL;
55+
g_autoptr(OstreeDeployment) rollback_deployment = NULL;
56+
if (booted_deployment)
57+
ostree_sysroot_query_deployments_for (sysroot, NULL, &pending_deployment,
58+
&rollback_deployment);
59+
60+
if (deployments->len == 0)
61+
{
62+
g_print ("No deployments.\n");
63+
return TRUE;
64+
}
65+
66+
struct stat stbuf;
67+
68+
if (!glnx_fstatat_allow_noent (sysroot->sysroot_fd, "/sys/firmware/efi", &stbuf, AT_SYMLINK_NOFOLLOW, error))
69+
return FALSE;
70+
71+
if (errno == ENOENT)
72+
{
73+
g_print ("Not an EFI installation.\n");
74+
return TRUE;
75+
}
76+
77+
g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (sysroot, booted_deployment);
78+
g_autofree char *new_esp_path = g_strdup_printf ("%s/usr/lib/ostree-boot", deployment_path);
79+
80+
GLNX_AUTO_PREFIX_ERROR ("During copy files to the ESP", error);
81+
glnx_autofd int old_esp_fd = -1;
82+
if (!glnx_opendirat (sysroot->sysroot_fd, "/boot", TRUE, &old_esp_fd, error))
83+
return FALSE;
84+
85+
glnx_autofd int new_esp_fd = -1;
86+
if (!glnx_opendirat (sysroot->sysroot_fd, new_esp_path, TRUE, &new_esp_fd, error))
87+
return FALSE;
88+
89+
/* The ESP filesystem is vfat so don't attempt to copy ownership, mode, and xattrs */
90+
const OstreeSysrootDebugFlags flags = sysroot->debug_flags | OSTREE_SYSROOT_DEBUG_NO_XATTRS;
91+
92+
if (!ot_copy_dir_recurse (new_esp_fd, old_esp_fd, "efi", flags , cancellable, error))
93+
return FALSE;
94+
95+
return TRUE;
96+
}

src/ostree/ot-admin-builtins.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ BUILTINPROTO(undeploy);
4040
BUILTINPROTO(deploy);
4141
BUILTINPROTO(cleanup);
4242
BUILTINPROTO(pin);
43+
BUILTINPROTO(esp_upgrade);
4344
BUILTINPROTO(finalize_staged);
4445
BUILTINPROTO(unlock);
4546
BUILTINPROTO(status);

src/ostree/ot-builtin-admin.c

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ static OstreeCommand admin_subcommands[] = {
5757
{ "pin", OSTREE_BUILTIN_FLAG_NO_REPO,
5858
ot_admin_builtin_pin,
5959
"Change the \"pinning\" state of a deployment" },
60+
{ "esp-upgrade", OSTREE_BUILTIN_FLAG_NO_REPO,
61+
ot_admin_builtin_esp_upgrade,
62+
"Upgrade the ESP with the files on the current deployment" },
6063
{ "set-origin", OSTREE_BUILTIN_FLAG_NO_REPO,
6164
ot_admin_builtin_set_origin,
6265
"Set Origin and create a new origin file" },

0 commit comments

Comments
 (0)