Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 45748ff

Browse files
committed
Add support for Btrfs subvolumes
1 parent 53ff798 commit 45748ff

File tree

7 files changed

+32
-0
lines changed

7 files changed

+32
-0
lines changed

meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ ccompiler = meson.get_compiler('c')
4444
dep_blkid = dependency('blkid')
4545
dep_check = dependency('check', version: '>= 0.9')
4646

47+
# other deps
48+
dep_btrfs = ccompiler.find_library('btrfsutil')
49+
if not ccompiler.has_header('btrfsutil.h')
50+
error('Cannot find btrfsutil.h. Is btrfs-progs-dev(el) installed?')
51+
endif
52+
4753
# Grab necessary paths
4854
path_prefix = get_option('prefix')
4955
path_bindir = join_paths(path_prefix, get_option('bindir'))

src/bootloaders/grub2.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ bool grub2_write_kernel(const Grub2Config *config, const Kernel *kernel)
240240
"rd.luks.uuid=%s ",
241241
config->root_dev->luks_uuid);
242242
}
243+
if (config->root_dev->btrfs_sub) {
244+
cbm_writer_append_printf(config->writer,
245+
"rootflags=subvol=%s ",
246+
config->root_dev->btrfs_sub);
247+
}
243248

244249
/* Finish it off with the command line options */
245250
cbm_writer_append_printf(config->writer, "%s\"\n", kernel->meta.cmdline);

src/bootloaders/syslinux-common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ bool syslinux_common_set_default_kernel(const BootManager *manager, const Kernel
175175
if (root_dev->luks_uuid) {
176176
cbm_writer_append_printf(writer, "rd.luks.uuid=%s ", root_dev->luks_uuid);
177177
}
178+
/* Add Btrfs information if relevant */
179+
if (root_dev->btrfs_sub) {
180+
cbm_writer_append_printf(writer, "rootflags=subvol=%s ", root_dev->btrfs_sub);
181+
}
178182

179183
/* Write out the cmdline */
180184
cbm_writer_append_printf(writer, "%s\n", k->meta.cmdline);

src/bootloaders/systemd-class.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ bool sd_class_install_kernel(const BootManager *manager, const Kernel *kernel)
269269
if (root_dev->luks_uuid) {
270270
cbm_writer_append_printf(writer, "rd.luks.uuid=%s ", root_dev->luks_uuid);
271271
}
272+
/* Add Btrfs information if relevant */
273+
if (root_dev->btrfs_sub) {
274+
cbm_writer_append_printf(writer, "rootflags=subvol=%s ", root_dev->btrfs_sub);
275+
}
272276

273277
/* Finish it off with the command line options */
274278
cbm_writer_append_printf(writer, "%s\n", kernel->meta.cmdline);

src/lib/probe.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sys/stat.h>
2222
#include <sys/sysmacros.h>
2323
#include <unistd.h>
24+
#include <btrfsutil.h>
2425

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

259+
/* Check if its a Btrfs device */
260+
if (btrfs_util_is_subvolume(path) == BTRFS_UTIL_OK) {
261+
LOG_DEBUG("Root device is a Btrfs subvolume");
262+
enum btrfs_util_error err = btrfs_util_subvolume_path(path, 0, &probe.btrfs_sub);
263+
if (err != BTRFS_UTIL_OK) {
264+
LOG_ERROR("Failed to get subvolume of Btrfs filesystem %s: %s",
265+
path, btrfs_util_strerror(err));
266+
}
267+
}
268+
258269
/* Check if its a software raid device */
259270
basenom = basename(devnode);
260271
if (strncmp(basenom, "md", 2) == 0) {

src/lib/probe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct CbmDeviceProbe {
2626
char *uuid; /**< UUID for all partition types */
2727
char *part_uuid; /**< PartUUID for GPT partitions */
2828
char *luks_uuid; /**< Parent LUKS UUID for the partition */
29+
char *btrfs_sub; /**< Btrfs subvolume of the rootfs */
2930
bool gpt; /**<Whether this device belongs to a GPT disk */
3031
} CbmDeviceProbe;
3132

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ libcbm_includes = [
6868
libcbm_dependencies = [
6969
link_libnica,
7070
dep_blkid,
71+
dep_btrfs,
7172
]
7273

7374
# Special constraints for efi functionality

0 commit comments

Comments
 (0)