forked from ostreedev/ostree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
0bcc68d
commit 7236536
Showing
6 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version='1.0'?> <!--*-nxml-*--> | ||
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" | ||
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | ||
|
||
<!-- | ||
Copyright 2019 Red Hat, Inc. | ||
SPDX-License-Identifier: LGPL-2.0+ | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the | ||
Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
Boston, MA 02111-1307, USA. | ||
--> | ||
|
||
<refentry id="ostree"> | ||
|
||
<refentryinfo> | ||
<title>ostree admin esp-upgrade</title> | ||
<productname>OSTree</productname> | ||
|
||
<authorgroup> | ||
<author> | ||
<contrib>Developer</contrib> | ||
<firstname>Javier</firstname> | ||
<surname>Martinez Canillas</surname> | ||
<email>[email protected]</email> | ||
</author> | ||
</authorgroup> | ||
</refentryinfo> | ||
|
||
<refmeta> | ||
<refentrytitle>ostree admin esp-upgrade</refentrytitle> | ||
<manvolnum>1</manvolnum> | ||
</refmeta> | ||
|
||
<refnamediv> | ||
<refname>ostree-admin-esp-upgrade</refname> | ||
<refpurpose>Upgrade the EFI System Partition (ESP) with files from the current deployment</refpurpose> | ||
</refnamediv> | ||
|
||
<refsynopsisdiv> | ||
<cmdsynopsis> | ||
<command>ostree admin esp-upgrade</command> | ||
</cmdsynopsis> | ||
</refsynopsisdiv> | ||
|
||
<refsect1> | ||
<title>Description</title> | ||
|
||
<para> | ||
Upgrade the EFI System Partition (ESP) with the files in the /usr/lib/ostree-boot/efi/ directory of the current deployment. | ||
</para> | ||
</refsect1> | ||
|
||
<refsect1> | ||
<title>Example</title> | ||
<para><command>$ ostree admin esp-upgrade</command></para> | ||
</refsect1> | ||
</refentry> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (C) 2019 Red Hat, Inc. | ||
* | ||
* SPDX-License-Identifier: LGPL-2.0+ | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the | ||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
* Boston, MA 02111-1307, USA. | ||
* | ||
* Author: Javier Martinez Canillas <[email protected]> | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "ostree-sysroot-private.h" | ||
#include "ot-main.h" | ||
#include "ot-admin-builtins.h" | ||
#include "ot-admin-functions.h" | ||
#include "otutil.h" | ||
|
||
static GOptionEntry options[] = { | ||
{ NULL } | ||
}; | ||
|
||
gboolean | ||
ot_admin_builtin_esp_upgrade (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) | ||
{ | ||
g_autoptr(GOptionContext) context = g_option_context_new (""); | ||
|
||
g_autoptr(OstreeSysroot) sysroot = NULL; | ||
if (!ostree_admin_option_context_parse (context, options, &argc, &argv, | ||
OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, | ||
invocation, &sysroot, cancellable, error)) | ||
return FALSE; | ||
|
||
g_autoptr(OstreeRepo) repo = NULL; | ||
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error)) | ||
return FALSE; | ||
|
||
g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); | ||
OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); | ||
|
||
g_autoptr(OstreeDeployment) pending_deployment = NULL; | ||
g_autoptr(OstreeDeployment) rollback_deployment = NULL; | ||
if (booted_deployment) | ||
ostree_sysroot_query_deployments_for (sysroot, NULL, &pending_deployment, | ||
&rollback_deployment); | ||
|
||
if (deployments->len == 0) | ||
{ | ||
g_print ("No deployments.\n"); | ||
return TRUE; | ||
} | ||
|
||
struct stat stbuf; | ||
|
||
if (!glnx_fstatat_allow_noent (sysroot->sysroot_fd, "/sys/firmware/efi", &stbuf, AT_SYMLINK_NOFOLLOW, error)) | ||
return FALSE; | ||
|
||
if (errno == ENOENT) | ||
{ | ||
g_print ("Not an EFI installation.\n"); | ||
return TRUE; | ||
} | ||
|
||
g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (sysroot, booted_deployment); | ||
g_autofree char *new_esp_path = g_strdup_printf ("%s/usr/lib/ostree-boot", deployment_path); | ||
|
||
GLNX_AUTO_PREFIX_ERROR ("During copy files to the ESP", error); | ||
glnx_autofd int old_esp_fd = -1; | ||
if (!glnx_opendirat (sysroot->sysroot_fd, "/boot", TRUE, &old_esp_fd, error)) | ||
return FALSE; | ||
|
||
glnx_autofd int new_esp_fd = -1; | ||
if (!glnx_opendirat (sysroot->sysroot_fd, new_esp_path, TRUE, &new_esp_fd, error)) | ||
return FALSE; | ||
|
||
/* The ESP filesystem is vfat so don't attempt to copy ownership, mode, and xattrs */ | ||
const OstreeSysrootDebugFlags flags = sysroot->debug_flags | OSTREE_SYSROOT_DEBUG_NO_XATTRS; | ||
|
||
if (!ot_copy_dir_recurse (new_esp_fd, old_esp_fd, "efi", flags , cancellable, error)) | ||
return FALSE; | ||
|
||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters