How to mount a btrfs file system with the mount command?

I have a btrfs file system in a Sabrent USB connected NVMe case. The only way I’ve been able to successfully mount it is with a two command sequence. Is there some way to mount it with just one mount command? Here is the alternate fstab I tried to use with one command.


UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /                       btrfs  defaults                      0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /.snapshots             btrfs  subvol=/@/.snapshots          0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /var                    btrfs  subvol=/@/var                 0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /usr/local              btrfs  subvol=/@/usr/local           0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /srv                    btrfs  subvol=/@/srv                 0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /root                   btrfs  subvol=/@/root                0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /opt                    btrfs  subvol=/@/opt                 0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /home                   btrfs  subvol=/@/home                0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /boot/grub2/x86_64-efi  btrfs  subvol=/@/boot/grub2/x86_64-efi  0  0
UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2  /boot/grub2/i386-pc     btrfs  subvol=/@/boot/grub2/i386-pc  0  0
UUID=A720-6F0C                             /boot/efi               vfat   utf8                          0  2

That is the system generated /etc/fstab on that SSD. I copied it to the booted file system, then ran this command:


Mobile-PC:~ # mount --all --fstab /root/fstab --target-prefix /mnt/chroot
mount: /mnt/chroot/.snapshots: mount point does not exist.
mount: /mnt/chroot/var: mount point does not exist.
mount: /mnt/chroot/usr/local: mount point does not exist.
mount: /mnt/chroot/srv: mount point does not exist.
mount: /mnt/chroot/root: mount point does not exist.
mount: /mnt/chroot/opt: mount point does not exist.
mount: /mnt/chroot/home: mount point does not exist.
mount: /mnt/chroot/boot/grub2/x86_64-efi: mount point does not exist.
mount: /mnt/chroot/boot/grub2/i386-pc: mount point does not exist.
mount: /mnt/chroot/boot/efi: mount point does not exist.

However, this command sequence works as expected when the first line of /root/fstab is commented out:


Mobile-PC:~ # mount UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2 /mnt/chroot
Mobile-PC:~ # mount --all --fstab /root/fstab --target-prefix /mnt/chroot

Is there some way to edit the first line of /root/fstab that will mount the root sub-volume successfully? Then the other sub-volume mounts will succeed.

Thanks,
Gene

Use -o subvolid=5:

**erlangen:~ #** btrfs filesystem show  
Label: 'tumbleweed-nvme0n1p3'  uuid: e7ad401f-4f60-42ff-a07e-f54372bc1dbc 
        Total devices 1 FS bytes used 144.21GiB 
        devid    1 size 476.84GiB used 176.04GiB path /dev/nvme0n1p2 

Label: 'tw-new'  uuid: 10726d74-53da-41e8-a3ed-7af130722783 
        Total devices 1 FS bytes used 272.77GiB 
        devid    1 size 465.66GiB used 276.05GiB path /dev/sdb2 

Label: 'Fedora'  uuid: 95a1cc9a-3a30-455d-b3bc-764202e94522 
        Total devices 1 FS bytes used 7.91GiB 
        devid    1 size 29.30GiB used 11.52GiB path /dev/sda4 

Label: 'Leap-15.3'  uuid: 4f975ab4-e072-4590-a2cf-69efaa8fa43f 
        Total devices 1 FS bytes used 12.86GiB 
        devid    1 size 30.00GiB used 19.05GiB path /dev/sda2 

Label: 'TW-Btrfs'  uuid: 2b54b9ff-84c9-4db2-841b-aff657a64325 
        Total devices 1 FS bytes used 38.79GiB 
        devid    1 size 40.00GiB used 39.33GiB path /dev/sda3 

**erlangen:~ #** mount UUID=4f975ab4-e072-4590-a2cf-69efaa8fa43f -o subvolid=5 /mnt/                                     
**[FONT=monospace]**erlangen:~ #** ll /mnt/@/ 
.snapshots/ boot/       etc/        home/       opt/        root/       srv/        tmp/        usr/        var/         
**erlangen:~ #** ll /mnt/@/ 
total 0 
drwxr-x--- 1 root root  136 Apr 18 11:36 **.snapshots**
drwxr-xr-x 1 root root   10 May 30  2021 **boot**
drwxr-xr-x 1 root root   14 May 30  2021 **etc**
drwxr-xr-x 1 root root    8 May 30  2021 **home**
drwxr-xr-x 1 root root    0 Mar 15 12:35 **opt**
drwx------ 1 root root  254 Apr 18 11:37 **root**
drwxr-xr-x 1 root root   22 Mar 15 12:35 **srv**
drwxrwxrwt 1 root root 1284 Apr 18 11:37 tmp
drwxr-xr-x 1 root root   10 May 30  2021 **usr**
drwxr-xr-x 1 root root  120 Apr 16 06:58 **var**
erlangen:~ #**[/FONT] 

“mount --all” ignores root filesystem ("/"). May be it should allow it when --target-prefix is given. Consider opening an issue (or even better creating pull request) for util-linux upstream.

That doesn’t accomplish the same thing. Only the root and subvolumes are mounted. The two command sequence mounts the entire file system tree.


Mobile-PC:~ # mount UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2 /mnt/chroot
Mobile-PC:~ # mount --all --fstab /root/fstab --target-prefix /mnt/chroot
Mobile-PC:~ # ll /mnt/chroot
total 16
drwxr-x--- 1 root root   46 Jun  3 15:08 .snapshots
lrwxrwxrwx 1 root root    7 May 10 10:22 bin -> usr/bin
dr-xr-xr-x 1 root root  374 Jun  3 14:28 boot
drwxr-xr-x 1 root root    0 Jun  3 14:17 dev
drwxr-xr-x 1 root root 4328 Jun  3 15:07 etc
dr-xr-xr-x 1 root root    8 Jun  3 14:35 home
lrwxrwxrwx 1 root root    7 May 10 10:22 lib -> usr/lib
lrwxrwxrwx 1 root root    9 May 10 10:22 lib64 -> usr/lib64
dr-xr-xr-x 1 root root   14 Jun  3 15:41 mnt
dr-xr-xr-x 1 root root    0 Jun  3 14:17 opt
drwxr-xr-x 1 root root    0 Jun  3 14:17 proc
drwx------ 1 root root  102 Jun  3 15:44 root
drwxr-xr-x 1 root root    0 Jun  3 14:17 run
lrwxrwxrwx 1 root root    8 May 10 10:22 sbin -> usr/sbin
dr-xr-xr-x 1 root root   22 Jun  3 14:26 srv
drwxr-xr-x 1 root root    0 Jun  3 14:17 sys
drwxrwxrwt 1 root root    0 Jun  3 14:36 tmp
drwxr-xr-x 1 root root  124 May 10 10:22 usr
drwxr-xr-x 1 root root  110 Jun  3 14:36 var

Which is what I want do to be able to chroot into the file system.

Thanks,
Gene

I chroot into btrfs since ever: Grub – EFI – Btrfs | Karl Mistelberger

**erlangen:~ #** mount UUID=4f975ab4-e072-4590-a2cf-69efaa8fa43f /mnt 
**erlangen:~ #** ll /mnt/ 
total 0 
drwxr-xr-x 1 root root    0 May 30  2021 **.snapshots**
drwxr-xr-x 1 root root 1760 Apr 16 06:55 **bin**
drwxr-xr-x 1 root root 1252 Apr 16 06:58 **boot**
drwxr-xr-x 1 root root    0 May 30  2021 **dev**
drwxr-xr-x 1 root root 5382 Apr 18 10:51 **etc**
drwxr-xr-x 1 root root    0 May 30  2021 **home**
drwxr-xr-x 1 root root   84 Apr 16 06:54 **lib**
drwxr-xr-x 1 root root 3008 Apr 16 06:55 **lib64**
drwxr-xr-x 1 root root    0 Mar 15 12:35 **mnt**
drwxr-xr-x 1 root root    0 May 30  2021 **opt**
drwxr-xr-x 1 root root    0 May 30  2021 **proc**
drwxr-xr-x 1 root root    0 May 30  2021 **root**
drwxr-xr-x 1 root root    0 May 30  2021 **run**
drwxr-xr-x 1 root root 3666 Apr 18 10:51 **sbin**
drwxr-xr-x 1 root root    0 Mar 15 12:35 **selinux**
drwxr-xr-x 1 root root    0 May 30  2021 **srv**
drwxr-xr-x 1 root root    0 May 30  2021 **sys**
drwxr-xr-x 1 root root    0 May 30  2021 **tmp**
drwxr-xr-x 1 root root  110 Mar 15 12:35 **usr**
drwxr-xr-x 1 root root    0 May 30  2021 **var**
**erlangen:~ #**

That is my first command in my previous post. Notice that the sub-volumes aren’t mounted, until you do my second command:


Mobile-PC:~ # umount -R /mnt/chroot
Mobile-PC:~ # ll /mnt/chroot
total 0
Mobile-PC:~ # mount UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2 /mnt/chroot
Mobile-PC:~ # ll /mnt/chroot
total 16
drwxr-xr-x 1 root root    0 Jun  3 14:17 .snapshots
lrwxrwxrwx 1 root root    7 May 10 10:22 bin -> usr/bin
dr-xr-xr-x 1 root root  374 Jun  3 14:28 boot
drwxr-xr-x 1 root root    0 Jun  3 14:17 dev
drwxr-xr-x 1 root root 4328 Jun  3 15:07 etc
drwxr-xr-x 1 root root    0 Jun  3 14:17 home
lrwxrwxrwx 1 root root    7 May 10 10:22 lib -> usr/lib
lrwxrwxrwx 1 root root    9 May 10 10:22 lib64 -> usr/lib64
dr-xr-xr-x 1 root root   14 Jun  3 15:41 mnt
drwxr-xr-x 1 root root    0 Jun  3 14:17 opt
drwxr-xr-x 1 root root    0 Jun  3 14:17 proc
drwxr-xr-x 1 root root    0 Jun  3 14:17 root
drwxr-xr-x 1 root root    0 Jun  3 14:17 run
lrwxrwxrwx 1 root root    8 May 10 10:22 sbin -> usr/sbin
drwxr-xr-x 1 root root    0 Jun  3 14:17 srv
drwxr-xr-x 1 root root    0 Jun  3 14:17 sys
drwxrwxrwt 1 root root    0 Jun  3 14:36 tmp
drwxr-xr-x 1 root root  124 May 10 10:22 usr
drwxr-xr-x 1 root root    0 Jun  3 14:17 var
Mobile-PC:~ # mount --all --fstab /root/fstab --target-prefix /mnt/chroot
Mobile-PC:~ # ll /mnt/chroot
total 16
drwxr-x--- 1 root root   46 Jun  3 15:08 .snapshots
lrwxrwxrwx 1 root root    7 May 10 10:22 bin -> usr/bin
dr-xr-xr-x 1 root root  374 Jun  3 14:28 boot
drwxr-xr-x 1 root root    0 Jun  3 14:17 dev
drwxr-xr-x 1 root root 4328 Jun  3 15:07 etc
dr-xr-xr-x 1 root root    8 Jun  3 14:35 home
lrwxrwxrwx 1 root root    7 May 10 10:22 lib -> usr/lib
lrwxrwxrwx 1 root root    9 May 10 10:22 lib64 -> usr/lib64
dr-xr-xr-x 1 root root   14 Jun  3 15:41 mnt
dr-xr-xr-x 1 root root    0 Jun  3 14:17 opt
drwxr-xr-x 1 root root    0 Jun  3 14:17 proc
drwx------ 1 root root  102 Jun  3 15:44 root
drwxr-xr-x 1 root root    0 Jun  3 14:17 run
lrwxrwxrwx 1 root root    8 May 10 10:22 sbin -> usr/sbin
dr-xr-xr-x 1 root root   22 Jun  3 14:26 srv
drwxr-xr-x 1 root root    0 Jun  3 14:17 sys
drwxrwxrwt 1 root root    0 Jun  3 14:36 tmp
drwxr-xr-x 1 root root  124 May 10 10:22 usr
drwxr-xr-x 1 root root  110 Jun  3 14:36 var

Gene

The current behavior is useful, on second thought. This two command sequence avoids copying /etc/fstab between drives.


Mobile-PC:~ # mount UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2 /mnt/chroot
Mobile-PC:~ # mount --all --fstab /mnt/chroot/etc/fstab --target-prefix /mnt/chroot

Gene

You have two different drives with filesystems sharing the same UUID. I am reusing the old drive. When upgrading host erlangen I intentionally created new filesystems and thus avoided using ambiguous UUIDs: https://forums.opensuse.org/showthread.php/541321-Upgrading-the-Hardware?p=3086058#post3086058

The drives have different UUIDs, but both are bootable. One of the drives is an old NVMe drive in a Sabrent USB C enclosure. So I just mount one drive on the other when I need to do some repair work on an unbootable system.

Gene

I see. Got confused by unneeded copy of fstab in post #1: mount --all --fstab /root/fstab --target-prefix /mnt/chroot Providing this information in the top post would have helped a lot.

When upgrading both Tumbleweed and the hardware concurrently I was annoyed by the low performance of USB compared to NVME. I resized btrfs and added another instance on the freed space: https://forums.opensuse.org/showthread.php/570398-How-to-use-ext4-instead-of-btrfs?p=3129986#post3129986

Sorry about the confusion, I was still figuring out exactly what I wanted to do. After reading this guide, openSUSE:Expert Installation - openSUSE Wiki, I wrote this script to automate the process:


> cat /usr/local/bin/mntchroot

#! /usr/bin/bash

EX_OK=0
EX_USAGE=64
command_name=$(basename "${0}")
mntsource="${1}"
directory=$(dirname "${2}")/$(basename "${2}")

if  $# -ne 2 ]; then
    >&2 echo "Usage: ${command_name} <source> <directory>"
    exit ${EX_USAGE}
fi
mount "${mntsource}" "${directory}" || exit $? 
mount --all --fstab "${directory}/etc/fstab" --target-prefix "${directory}" || exit $?
mount --types proc /proc "${directory}/proc" || exit $?
mount --rbind /sys "${directory}/sys" || exit $?
mount --make-rslave "${directory}/sys" || exit $?
mount --rbind /dev "${directory}/dev" || exit $?
mount --make-rslave "${directory}/dev" || exit $?
mount --bind /run "${directory}/run" || exit $?
mount --make-slave "${directory}/run" || exit $?
if  "$(df --output=fstype /tmp | sed -e 1d)" = "tmpfs" ]; then
    mount --bind /tmp "${directory}/tmp" || exit #?
    mount --make-slave "${directory}/tmp" || exit #?
fi
exit ${EX_OK}

sudo mntchroot UUID=4c96a0c2-f72f-4827-b023-83ba000b2fd2 /mnt/chroot

gene@Mobile-PC:~> ll /mnt/chroot
total 16K
lrwxrwxrwx   1 root root    7 May 10 10:22 bin -> usr/bin
dr-xr-xr-x   1 root root  684 Jun  9 15:11 boot
drwxr-xr-x  21 root root 4.3K Jun 13 08:20 dev
drwxr-xr-x   1 root root 4.6K Jun 12 18:38 etc
dr-xr-xr-x   1 root root    8 Jun  3 14:35 home
lrwxrwxrwx   1 root root    7 May 10 10:22 lib -> usr/lib
lrwxrwxrwx   1 root root    9 May 10 10:22 lib64 -> usr/lib64
dr-xr-xr-x   1 root root   42 Jun  5 16:41 mnt
dr-xr-xr-x   1 root root   46 Jun 10 13:43 opt
dr-xr-xr-x 448 root root    0 Jun 13 08:21 proc
drwx------   1 root root  152 Jun 11 11:44 root
drwxr-xr-x  40 root root 1020 Jun 13 08:12 run
lrwxrwxrwx   1 root root    8 May 10 10:22 sbin -> usr/sbin
dr-xr-xr-x   1 root root   22 Jun  3 14:26 srv
dr-xr-xr-x  13 root root    0 Jun 13 08:12 sys
drwxrwxrwt  13 root root  300 Jun 13 08:19 tmp
drwxr-xr-x   1 root root  124 May 10 10:22 usr
drwxr-xr-x   1 root root  110 Jun  3 14:36 var

Gene

Hi

You have two different drives with filesystems sharing the same UUID. You need to change UUID with: tune2fs /dev/{device} -U {uuid}

Regards

Sorry for the confusion, but actually, I have two different drives with two different UUIDs.


lsblk -f

└─sdb2   btrfs                  4c96a0c2-f72f-4827-b023-83ba000b2fd2

├─nvme0n1p4
│        btrfs                  7f12b78a-ba24-43e0-8a93-235f76df6d03

Both drives have a directory named /mnt/chroot, so I mount the other drive on /mnt/chroot on the drive I’m booted on with sudo mntchroot UUID=[4c96a0c2-f72f-4827-b023-83ba000b2fd2 or 7f12b78a-ba24-43e0-8a93-235f76df6d03]. Then I can chroot into the other drive and run zypper or whatever else I need to do.

Gene