Skip to content

Conversation

@kageurufu
Copy link
Contributor

@kageurufu kageurufu commented Apr 29, 2025

Description

This allows changing the default root subvolume from @ to any user
defined subvolume name

We currently ship an image using @root/[revision], which allows us to ship offline updates using btrfs send/receive. It would be easy enough to just add our root subvolume in btrfs_root_add_subvolumes, however the subsequent "Remounting rootfs" mount call specifies the subvolume by name instead of relying on the previously set default. To work around this for our needs, I would have to abuse btrfs_root_add_subvolumes_fstab to umount/mount to change the volume name there as well.

To this end, I've changed the remounting rootfs call to not explicitly pass a subvolume, mounting the current default. This allows users to customize subvolumes further in btrfs_root_add_subvolumes (for example, creating a/b rootfs subvolumes).

Documentation summary for feature / change

  • Add BTRFS_ROOT_SUBVOLUME switch
  • This allows customizing the name of the root subvolume when using ROOTFS_TYPE=btrfs

How Has This Been Tested?

A test extension was used to create a nested custom root subvolumes

function btrfs_root_add_subvolumes__nested_root() {
	display_alert "Extension $EXTENSION: Creating custom versioned root subvolume"
	run_host_command_logged btrfs subvolume create $MOUNT/$BTRFS_ROOT_SUBVOLUME/0
	run_host_command_logged btrfs subvolume set-default $MOUNT/$BTRFS_ROOT_SUBVOLUME/0
}

Then I mounted the output images and verified the changed default was used during remounting and image build

  • bash compile.sh BOARD=uefi-x86 BUILD_MINIMAL=yes RELEASE=trixie BRANCH=current KERNEL_CONFIGURE=no ROOTFS_TYPE=btrfs BTRFS_ROOT_SUBVOLUME=@root ENABLE_EXTENSIONS=test-btrfs-subvol

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings

This allows changing the default root subvolume from @ to any user
 defined subvolume name
This allows changes to the default subvolume in `btrfs_root_add_subvolumes`
 to propagate as needed into the final image.
This simplifies the code, removing the need to grep/cut the output of btrfs subvolume list
@kageurufu kageurufu requested a review from a team as a code owner April 29, 2025 16:20
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 29, 2025

Walkthrough

This change updates the logic for handling btrfs root subvolumes in the lib/functions/image/partitioning.sh script. A new variable, btrfs_root_subvolume, is introduced and set from the BTRFS_ROOT_SUBVOLUME environment variable or defaults to "@" if not specified. The script now uses this variable for both the creation of the btrfs subvolume and when setting the default subvolume, replacing previously hardcoded references to "@". The command for setting the default subvolume is simplified to use the subvolume path directly, removing the need to extract the subvolume ID via a pipeline. Additionally, the remount command for the root filesystem no longer explicitly includes the subvol=@ mount option, streamlining the mounting process. These changes are localized to the internal logic within the existing prepare_partitions function.

Possibly related PRs

Suggested labels

ready to merge

✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added 05 Milestone: Second quarter release Needs review Seeking for review Framework Framework components size/small PR with less then 50 lines labels Apr 29, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label Apr 29, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/functions/image/partitioning.sh (1)

355-355: Optional: Quote variables and use explicit -o syntax in remount.

The remount line drops the explicit subvol=@, which is great, but for improved robustness:

-run_host_command_logged mount -odefaults,${mountopts[$ROOTFS_TYPE]} $rootdevice $MOUNT/
+run_host_command_logged mount -o "defaults,${mountopts[$ROOTFS_TYPE]}" "$rootdevice" "$MOUNT/"

This change avoids word-splitting issues and makes the -o usage clearer.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7e55d5 and 7a8b5d4.

📒 Files selected for processing (1)
  • lib/functions/image/partitioning.sh (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
lib/functions/image/partitioning.sh (1)
lib/functions/logging/runners.sh (1)
  • run_host_command_logged (192-194)
🔇 Additional comments (1)
lib/functions/image/partitioning.sh (1)

333-339:

❓ Verification inconclusive

Parameterize and robustify BTRFS root subvolume creation and default setting.

You’ve centralized the subvolume name via btrfs_root_subvolume="${BTRFS_ROOT_SUBVOLUME:-@}" and simplified default‐setting with btrfs subvolume set-default. To support nested subvolumes (e.g., "a/b") and avoid path or whitespace issues, please:

  1. Ensure parent directories are created before btrfs subvolume create, e.g.:
    +run_host_command_logged mkdir -p "$(dirname "$MOUNT/$btrfs_root_subvolume")"
    -run_host_command_logged btrfs subvolume create $MOUNT/$btrfs_root_subvolume
    +run_host_command_logged btrfs subvolume create "$MOUNT/$btrfs_root_subvolume"
  2. Quote all variable expansions for safety, including in set-default:
    -run_host_command_logged "btrfs subvolume set-default $MOUNT/$btrfs_root_subvolume"
    +run_host_command_logged btrfs subvolume set-default "$MOUNT/$btrfs_root_subvolume"
  3. Verify that the installed btrfs-progs version on target systems supports passing a path directly to set-default (older versions expect a numeric ID).

Would you like me to help with these adjustments?


To be sure we address all quoting and directory‐creation issues, let’s first pinpoint how these commands are used in the script:


🏁 Script executed:

#!/bin/bash
set -e

echo "## btrfs subvolume create lines"
rg -n "btrfs subvolume create" lib/functions/image/partitioning.sh

echo "## btrfs subvolume set-default lines"
rg -n "btrfs subvolume set-default" lib/functions/image/partitioning.sh

echo "## mkdir calls"
rg -n "mkdir" lib/functions/image/partitioning.sh

Length of output: 1260


Parameterize and Robustify BTRFS Subvolume Creation (lib/functions/image/partitioning.sh)

Please update the BTRFS subvolume creation and default‐setting to handle nested names and whitespace safely, and ensure parent directories exist:

  • Quote all path expansions in both create and set-default calls.
  • Pre-create the parent directory of each subvolume before calling btrfs subvolume create.
  • Apply the same quoting to the other hardcoded subvolume creates at lines 346–350.
  • Verify that your target systems’ btrfs-progs version supports passing a path to btrfs subvolume set-default (older versions may require a numeric subvolume ID).

Suggested diff:

--- a/lib/functions/image/partitioning.sh
+++ b/lib/functions/image/partitioning.sh
@@ -333,7 +333,9 @@
 			btrfs_root_subvolume="${BTRFS_ROOT_SUBVOLUME:-@}"
 			mountopts[$ROOTFS_TYPE]='commit=120'
-			run_host_command_logged btrfs subvolume create $MOUNT/$btrfs_root_subvolume
+			run_host_command_logged mkdir -p "$(dirname "$MOUNT/$btrfs_root_subvolume")"
+			run_host_command_logged btrfs subvolume create "$MOUNT/$btrfs_root_subvolume"
+
 			# getting the subvolume id of the newly created volume @ to install it
 			# as the default volume for mounting without explicit reference
@@ -339,7 +341,7 @@
-			run_host_command_logged "btrfs subvolume set-default $MOUNT/$btrfs_root_subvolume"
+			run_host_command_logged btrfs subvolume set-default "$MOUNT/$btrfs_root_subvolume"

Applicable locations:
• lib/functions/image/partitioning.sh: lines 335 (root subvol), 346–350 (other subvol creates), 339 (set-default)

coderabbitai bot added a commit that referenced this pull request Apr 30, 2025
Docstrings generation was requested by @iav.

* #8144 (comment)

The following files were modified:

* `lib/functions/image/partitioning.sh`
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 30, 2025

Note

Generated docstrings for this pull request at #8145

Copy link
Contributor

@iav iav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to build jammy, noble, plucky.
It works.

@igorpecovnik igorpecovnik added the Needs Documentation New feature needs documentation entry label May 1, 2025
@igorpecovnik
Copy link
Member

Please add (copy/paste + AI) to https://docs.armbian.com/Developer-Guide_Build-Switches/

@igorpecovnik igorpecovnik merged commit 4a8199b into armbian:main May 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second quarter release Framework Framework components Needs Documentation New feature needs documentation entry Needs review Seeking for review Ready to merge Reviewed, tested and ready for merge size/small PR with less then 50 lines

Development

Successfully merging this pull request may close these issues.

3 participants