Skip to content

Commit

Permalink
Add support for Btrfs subvolumes
Browse files Browse the repository at this point in the history
  • Loading branch information
silkeh committed Jul 8, 2020
1 parent 74dd463 commit e0506fe
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ ccompiler = meson.get_compiler('c')
dep_blkid = dependency('blkid')
dep_check = dependency('check', version: '>= 0.9')

# other deps
dep_btrfs = ccompiler.find_library('btrfsutil')
if not ccompiler.has_header('btrfsutil.h')
error('Cannot find btrfsutil.h. Is btrfs-progs-dev(el) installed?')
endif

# Grab necessary paths
path_prefix = get_option('prefix')
path_bindir = join_paths(path_prefix, get_option('bindir'))
Expand Down
5 changes: 5 additions & 0 deletions src/bootloaders/grub2.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ bool grub2_write_kernel(const Grub2Config *config, const Kernel *kernel)
"rd.luks.uuid=%s ",
config->root_dev->luks_uuid);
}
if (config->root_dev->btrfs_sub) {
cbm_writer_append_printf(config->writer,
"rootflags=subvol=%s ",
config->root_dev->btrfs_sub);
}

/* Finish it off with the command line options */
cbm_writer_append_printf(config->writer, "%s\"\n", kernel->meta.cmdline);
Expand Down
4 changes: 4 additions & 0 deletions src/bootloaders/syslinux-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ bool syslinux_common_set_default_kernel(const BootManager *manager, const Kernel
if (root_dev->luks_uuid) {
cbm_writer_append_printf(writer, "rd.luks.uuid=%s ", root_dev->luks_uuid);
}
/* Add Btrfs information if relevant */
if (root_dev->btrfs_sub) {
cbm_writer_append_printf(writer, "rootflags=subvol=%s ", root_dev->btrfs_sub);
}

/* Write out the cmdline */
cbm_writer_append_printf(writer, "%s\n", k->meta.cmdline);
Expand Down
4 changes: 4 additions & 0 deletions src/bootloaders/systemd-class.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ bool sd_class_install_kernel(const BootManager *manager, const Kernel *kernel)
if (root_dev->luks_uuid) {
cbm_writer_append_printf(writer, "rd.luks.uuid=%s ", root_dev->luks_uuid);
}
/* Add Btrfs information if relevant */
if (root_dev->btrfs_sub) {
cbm_writer_append_printf(writer, "rootflags=subvol=%s ", root_dev->btrfs_sub);
}

/* Finish it off with the command line options */
cbm_writer_append_printf(writer, "%s\n", kernel->meta.cmdline);
Expand Down
11 changes: 11 additions & 0 deletions src/lib/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h>
#include <btrfsutil.h>

#include "blkid_stub.h"
#include "files.h"
Expand Down Expand Up @@ -255,6 +256,16 @@ CbmDeviceProbe *cbm_probe_path(const char *path)
LOG_ERROR("Unable to find UUID for %s: %s", devnode, strerror(errno));
}

/* Check if its a Btrfs device */
if (btrfs_util_is_subvolume(path) == BTRFS_UTIL_OK) {
LOG_DEBUG("Root device is a Btrfs subvolume");
enum btrfs_util_error err = btrfs_util_subvolume_path(path, 0, &probe.btrfs_sub);
if (err != BTRFS_UTIL_OK) {
LOG_ERROR("Failed to get subvolume of Btrfs filesystem %s: %s",
path, btrfs_util_strerror(err));
}
}

/* Check if its a software raid device */
basenom = basename(devnode);
if (strncmp(basenom, "md", 2) == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct CbmDeviceProbe {
char *uuid; /**< UUID for all partition types */
char *part_uuid; /**< PartUUID for GPT partitions */
char *luks_uuid; /**< Parent LUKS UUID for the partition */
char *btrfs_sub; /**< Btrfs subvolume of the rootfs */
bool gpt; /**<Whether this device belongs to a GPT disk */
} CbmDeviceProbe;

Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ libcbm_includes = [
libcbm_dependencies = [
link_libnica,
dep_blkid,
dep_btrfs,
]

# Special constraints for efi functionality
Expand Down

0 comments on commit e0506fe

Please sign in to comment.