Skip to contentSkip to conversation

how to extend a btrfs disk image?

DISCUSSION Ulli Horlacher 2 participants 5 messages Dec 17, 2020 – Dec 20, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

How can I add a second disk-image to an existing btrfs filesystem?

I have to use btrfs via a disk image on a nfs Netapp storage system with a 16 TB file size limit. One cannot use bigger files.

I have set up sucessfully:

root@fextest:/nfs/rusnas/fex# touch disk1.btrfs
root@fextest:/nfs/rusnas/fex# truncate -s 16TB disk1.btrfs
root@fextest:/nfs/rusnas/fex# ll disk1.btrfs
-rw-r--r-- root root 16,000,000,000,000 2020-12-17 13:18:59 disk1.btrfs
root@fextest:/nfs/rusnas/fex# mkfs.btrfs disk1.btrfs
btrfs-progs v5.4.1
See http://btrfs.wiki.kernel.org for more information.
Label:              (null)
UUID:               4f7befb1-c892-497f-a40c-c6ac1a18368d
Node size:          16384
Sector size:        4096
Filesystem size:    14.55TiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         DUP               1.00GiB
  System:           DUP               8.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata
Checksum:           crc32c
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1    14.55TiB  disk1.btrfs
root@fextest:/nfs/rusnas/fex# mount disk1.btrfs /mnt/tmp
root@fextest:/nfs/rusnas/fex# df -TH /mnt/tmp
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/loop2     btrfs   16T  3.7M   16T   1% /mnt/tmp

No problem so far, everything is easy ;-)

Now I want to extend this filesystem, but this approach fails:

root@fextest:/nfs/rusnas/fex# touch disk2.btrfs
root@fextest:/nfs/rusnas/fex# truncate -s 16TB disk2.btrfs
root@fextest:/nfs/rusnas/fex# btrfs device add /nfs/rusnas/fex/disk2.btrfs /mnt/tmp
ERROR: /nfs/rusnas/fex/disk2.btrfs is not a block device
root@fextest:/nfs/rusnas/fex# sysinfo 
System:        Linux fextest 5.4.0-58-generic x86_64
Distribution:  Ubuntu 20.04.1 LTS
Hardware:      VMware, Inc. VMware Virtual Platform None (VMware)
CPU:           Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz, 4 x 2394 MHz
RAM:           4095 MB
Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK         
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/
REF:<[email protected]>
#1 lore raw
Quoted 4 lines · On Thu, 17 Dec 2020 13:30:08 +0100 Ulli Horlacher…
root@fextest:/nfs/rusnas/fex# mount disk1.btrfs /mnt/tmp
root@fextest:/nfs/rusnas/fex# df -TH /mnt/tmp
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/loop2     btrfs   16T  3.7M   16T   1% /mnt/tmp

You see here 'mount' has transparently created a 'loop device' for you in order to mount the FS.

Quoted 6 lines

Now I want to extend this filesystem, but this approach fails:

root@fextest:/nfs/rusnas/fex# touch disk2.btrfs
root@fextest:/nfs/rusnas/fex# truncate -s 16TB disk2.btrfs
root@fextest:/nfs/rusnas/fex# btrfs device add /nfs/rusnas/fex/disk2.btrfs /mnt/tmp
ERROR: /nfs/rusnas/fex/disk2.btrfs is not a block device

Since file is not a block device, here you have to do the same manually. See documentation for 'losetup'.

Signature · 2 lines
With respect,
Roman
#2 lore raw
Quoted 7 lines · Roman Mamedov
Quoted 4 lines
root@fextest:/nfs/rusnas/fex# touch disk2.btrfs
root@fextest:/nfs/rusnas/fex# truncate -s 16TB disk2.btrfs
root@fextest:/nfs/rusnas/fex# btrfs device add /nfs/rusnas/fex/disk2.btrfs /mnt/tmp
ERROR: /nfs/rusnas/fex/disk2.btrfs is not a block device

Since file is not a block device, here you have to do the same manually. See documentation for 'losetup'.

Ok, I was able to extend the btrfs filesystem via a loopback devive.

What is the suggested way to do this at boot time?

For now I have in /etc/rc.local:

cd /nfs/rusnas/fex
for d in spool_[1-9].btrfs; do
echo -n "$d ==> "
losetup -fP --show $d
done
sync
sleep 2 # without this sleep the mount will fail!
mount -v spool_1.btrfs /mnt/spool

This works, but is there a more elegant way?
Using /etc/fstab seems not to be possible?

Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK         
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/
REF:<20201217191207.17243c40@natsu>
#3 lore raw
Quoted 6 lines · On Sat, 19 Dec 2020 23:59:45 +0100 Ulli Horlacher…

Ok, I was able to extend the btrfs filesystem via a loopback devive.

What is the suggested way to do this at boot time?

For now I have in /etc/rc.local:

Quoted 7 lines

cd /nfs/rusnas/fex
for d in spool_[1-9].btrfs; do
echo -n "$d ==> "
losetup -fP --show $d
done
sync
sleep 2 # without this sleep the mount will fail!

You could try replacing the sleep with "btrfs device scan", certainly more elegant (assuming it helps). Maybe even narrow it down to "btrfs device scan /dev/loop*", or even scan each added device.

Quoted 1 line

mount -v spool_1.btrfs /mnt/spool

Better mount one of the loop devices, not the file, lest mount will probably make one more, a dupe of one that your script has already added, and who knows what side effects this could have.

Quoted 2 lines

This works, but is there a more elegant way?
Using /etc/fstab seems not to be possible?

There doesn't seem to be "/etc/looptab" or such, that would set these up on boot. So your approach seems fine to me.

Signature · 2 lines
With respect,
Roman
#4 lore raw
Quoted 10 lines · Roman Mamedov
Quoted 9 lines

For now I have in /etc/rc.local:

cd /nfs/rusnas/fex
for d in spool_[1-9].btrfs; do
echo -n "$d ==> "
losetup -fP --show $d
done
sync
sleep 2 # without this sleep the mount will fail!

Quoted 3 lines

You could try replacing the sleep with "btrfs device scan", certainly more elegant (assuming it helps). Maybe even narrow it down to "btrfs device scan /dev/loop*", or even scan each added device.

Indeed better!

Quoted 5 lines
Quoted 1 line

mount -v spool_1.btrfs /mnt/spool

Better mount one of the loop devices, not the file, lest mount will probably make one more, a dupe of one that your script has already added, and who knows what side effects this could have.

Ok, now I use:

ldev=$(losetup -l | awk '/spool_1.btrfs/{print $1;exit}') mount -v $ldev /mnt/spool

This is all necessary because our Netapp storage system has an annoying 16 TB file size limit. This was ok for the last century, but for today it is an anachronism.

Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK         
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/
REF:<20201220142252.01cf4140@natsu>