The “btrfs” file system and linux rescues

Thus far, I have been mainly using “ext4” as a file system, and avoiding “btrfs”.  But there is one exception.  I have “btrfs” on an opensuse Tumbleweed install.  This was mostly to get some experience with “btrfs”.

I’ll give my overall opinion, based on that experience, in another post in the next few days.

Rescues

I have not actually needed to rescue my “btrfs” system.  But it is sometimes useful to be able to access it from a different partition.  And it can be useful to know how to rescue, just in case.

I have previously discussed linux rescues.  However, “btrfs” is a little tricky, and some extra steps are needed.  The problem is that you cannot just mount the “btrfs” file system.  Typically, the file system is organized into subvolumes.  And you need to also mount those subvolumes.

Here’s a small script that I have been using:

MOUNTWHERE=/mnt
ROOTDEV=/dev/mapper/system-root

mount $ROOTDEV $MOUNTWHERE
SUBVOL=`sed -n 's/.*subvol=\([^,       ]*\).*/\1/p' $MOUNTWHERE/etc/fstab`
for sv in $SUBVOL
do
        mount -o subvol=$sv $ROOTDEV $MOUNTWHERE/$sv
done

In the above script, MOUNTWHERE is where I mount the file system.  And ROOTDEV is the device name.  In this case, it is for a volume that is part of an encrypted LVM.

The first step is to mount the root volume.  I then use “sed” to extract a list of the subvolumes from “/etc/fstab” (under that mount point).  Then a shell “for” loop is used to mount the subvolumes.

In addition to this, you will need to mount any other needed file system (such as “/boot” or “/home” and you will need the same “–bind” mounts as I describe in that earlier discussion of rescues.

After those mounts, you should be able to handle rescues as usual.

If you want to unmount them all, then use

umount -R $MOUNTWHERE

or just reboot and allow normal shutdown to take care of that.

Advertisements

About Neil Rickert

Mathematician and computer scientist who dabbles in cognitive science.

Trackbacks / Pingbacks

  1. My assessment of “btrfs” | Thoughts on computing - 2016/04/15

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: