Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Btrfs subvolumes #239

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Prepare
run: |
sudo apt-get update
sudo apt-get install libefiboot-dev check grep ninja-build meson gcc libblkid-dev lcov valgrind gnu-efi libefivar-dev ruby ruby-dev
sudo apt-get install libefiboot-dev check grep ninja-build meson gcc libblkid-dev lcov valgrind gnu-efi libefivar-dev libbtrfsutil-dev ruby ruby-dev
sudo gem install coveralls-lcov
- name: "Run Test: stock"
env:
Expand Down
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 @@ -241,6 +241,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 @@ -189,6 +189,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 @@ -284,6 +284,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 @@ -263,6 +264,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 */
dev_t dev; /**< The device itself */
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