2021-12-09 19:46:42 +00:00
|
|
|
The COW mechanism and multiple devices under one hood enable an interesting
|
2022-05-13 15:42:14 +00:00
|
|
|
concept, called a seeding device: extending a read-only filesystem on a
|
|
|
|
device with another device that captures all writes. For example
|
2021-12-09 19:46:42 +00:00
|
|
|
imagine an immutable golden image of an operating system enhanced with another
|
|
|
|
device that allows to use the data from the golden image and normal operation.
|
|
|
|
This idea originated on CD-ROMs with base OS and allowing to use them for live
|
|
|
|
systems, but this became obsolete. There are technologies providing similar
|
|
|
|
functionality, like *unionmount*, *overlayfs* or *qcow2* image snapshot.
|
|
|
|
|
|
|
|
The seeding device starts as a normal filesystem, once the contents is ready,
|
2023-04-26 23:48:47 +00:00
|
|
|
:command:`btrfstune -S 1` is used to flag it as a seeding device. Mounting such device
|
|
|
|
will not allow any writes, except adding a new device by :command:`btrfs device add`.
|
2021-12-09 19:46:42 +00:00
|
|
|
Then the filesystem can be remounted as read-write.
|
|
|
|
|
|
|
|
Given that the filesystem on the seeding device is always recognized as
|
2022-05-13 15:42:14 +00:00
|
|
|
read-only, it can be used to seed multiple filesystems from one device at the
|
|
|
|
same time. The UUID that is normally attached to a device is automatically
|
|
|
|
changed to a random UUID on each mount.
|
2021-12-09 19:46:42 +00:00
|
|
|
|
|
|
|
Once the seeding device is mounted, it needs the writable device. After adding
|
2022-04-14 17:30:30 +00:00
|
|
|
it, unmounting and mounting with :command:`umount /path; mount /dev/writable
|
|
|
|
/path` or remounting read-write with :command:`remount -o remount,rw` makes the
|
|
|
|
filesystem at :file:`/path` ready for use.
|
2021-12-09 19:46:42 +00:00
|
|
|
|
2022-04-14 17:30:30 +00:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
There is a known bug with using remount to make the mount writeable:
|
|
|
|
remount will leave the filesystem in a state where it is unable to
|
|
|
|
clean deleted snapshots, so it will leak space until it is unmounted
|
|
|
|
and mounted properly.
|
|
|
|
|
|
|
|
Furthermore, deleting the seeding device from the filesystem can turn it into
|
2021-12-09 19:46:42 +00:00
|
|
|
a normal filesystem, provided that the writable device can also contain all the
|
|
|
|
data from the seeding device.
|
|
|
|
|
2023-04-26 23:48:47 +00:00
|
|
|
The seeding device flag can be cleared again by :command:`btrfstune -f -S 0`, e.g.
|
2021-12-09 19:46:42 +00:00
|
|
|
allowing to update with newer data but please note that this will invalidate
|
|
|
|
all existing filesystems that use this particular seeding device. This works
|
2022-05-13 15:42:14 +00:00
|
|
|
for some use cases, not for others, and the forcing flag to the command is
|
2021-12-09 19:46:42 +00:00
|
|
|
mandatory to avoid accidental mistakes.
|
|
|
|
|
|
|
|
Example how to create and use one seeding device:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# mkfs.btrfs /dev/sda
|
|
|
|
# mount /dev/sda /mnt/mnt1
|
2022-05-13 15:42:14 +00:00
|
|
|
... fill mnt1 with data
|
2021-12-09 19:46:42 +00:00
|
|
|
# umount /mnt/mnt1
|
2022-05-13 15:42:14 +00:00
|
|
|
|
2021-12-09 19:46:42 +00:00
|
|
|
# btrfstune -S 1 /dev/sda
|
2022-05-13 15:42:14 +00:00
|
|
|
|
2021-12-09 19:46:42 +00:00
|
|
|
# mount /dev/sda /mnt/mnt1
|
2022-05-13 15:42:14 +00:00
|
|
|
# btrfs device add /dev/sdb /mnt/mnt1
|
2022-04-14 17:30:30 +00:00
|
|
|
# umount /mnt/mnt1
|
|
|
|
# mount /dev/sdb /mnt/mnt1
|
2022-05-13 15:42:14 +00:00
|
|
|
... /mnt/mnt1 is now writable
|
2021-12-09 19:46:42 +00:00
|
|
|
|
|
|
|
Now */mnt/mnt1* can be used normally. The device */dev/sda* can be mounted
|
|
|
|
again with a another writable device:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# mount /dev/sda /mnt/mnt2
|
|
|
|
# btrfs device add /dev/sdc /mnt/mnt2
|
2022-04-14 17:30:30 +00:00
|
|
|
# umount /mnt/mnt2
|
|
|
|
# mount /dev/sdc /mnt/mnt2
|
2021-12-09 19:46:42 +00:00
|
|
|
... /mnt/mnt2 is now writable
|
|
|
|
|
|
|
|
The writable device (*/dev/sdb*) can be decoupled from the seeding device and
|
|
|
|
used independently:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# btrfs device delete /dev/sda /mnt/mnt1
|
|
|
|
|
|
|
|
As the contents originated in the seeding device, it's possible to turn
|
|
|
|
*/dev/sdb* to a seeding device again and repeat the whole process.
|
|
|
|
|
|
|
|
A few things to note:
|
|
|
|
|
|
|
|
* it's recommended to use only single device for the seeding device, it works
|
|
|
|
for multiple devices but the *single* profile must be used in order to make
|
|
|
|
the seeding device deletion work
|
2021-12-17 09:49:39 +00:00
|
|
|
* block group profiles *single* and *dup* support the use cases above
|
2023-04-26 23:48:47 +00:00
|
|
|
* the label is copied from the seeding device and can be changed by :command:`btrfs filesystem label`
|
2021-12-09 19:46:42 +00:00
|
|
|
* each new mount of the seeding device gets a new random UUID
|
2022-04-14 17:30:30 +00:00
|
|
|
* :command:`umount /path; mount /dev/writable /path` can be replaced with
|
|
|
|
:command:`mount -o remount,rw /path`
|
|
|
|
but it won't reclaim space of deleted subvolumes until the seeding device
|
|
|
|
is mounted read-write again before making it seeding again
|
2022-05-13 15:42:14 +00:00
|
|
|
|
|
|
|
Chained seeding devices
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
Though it's not recommended and is rather an obscure and untested use case,
|
|
|
|
chaining seeding devices is possible. In the first example, the writable device
|
|
|
|
*/dev/sdb* can be turned onto another seeding device again, depending on the
|
|
|
|
unchanged seeding device */dev/sda*. Then using */dev/sdb* as the primary
|
|
|
|
seeding device it can be extended with another writable device, say */dev/sdd*,
|
|
|
|
and it continues as before as a simple tree structure on devices.
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# mkfs.btrfs /dev/sda
|
|
|
|
# mount /dev/sda /mnt/mnt1
|
|
|
|
... fill mnt1 with data
|
|
|
|
# umount /mnt/mnt1
|
|
|
|
|
|
|
|
# btrfstune -S 1 /dev/sda
|
|
|
|
|
|
|
|
# mount /dev/sda /mnt/mnt1
|
|
|
|
# btrfs device add /dev/sdb /mnt/mnt1
|
|
|
|
# mount -o remount,rw /mnt/mnt1
|
|
|
|
... /mnt/mnt1 is now writable
|
|
|
|
# umount /mnt/mnt1
|
|
|
|
|
|
|
|
# btrfstune -S 1 /dev/sdb
|
|
|
|
|
|
|
|
# mount /dev/sdb /mnt/mnt1
|
|
|
|
# btrfs device add /dev/sdc /mnt
|
|
|
|
# mount -o remount,rw /mnt/mnt1
|
|
|
|
... /mnt/mnt1 is now writable
|
|
|
|
# umount /mnt/mnt1
|
|
|
|
|
|
|
|
As a result we have:
|
|
|
|
|
|
|
|
* *sda* is a single seeding device, with its initial contents
|
|
|
|
* *sdb* is a seeding device but requires *sda*, the contents are from the time
|
2022-12-07 20:00:25 +00:00
|
|
|
when *sdb* is made seeding, i.e. contents of *sda* with any later changes
|
2022-05-13 15:42:14 +00:00
|
|
|
* *sdc* last writable, can be made a seeding one the same way as was *sdb*,
|
|
|
|
preserving its contents and depending on *sda* and *sdb*
|
|
|
|
|
|
|
|
As long as the seeding devices are unmodified and available, they can be used
|
|
|
|
to start another branch.
|