User:Zulu Foxtrott/GentooOnARM/EasyInstall/StructuringBtrfs

From Gentoo Wiki
Jump to:navigation Jump to:search

Default: Using subvolumes to structure a Btrfs filesystem

How many subvolumes and what for?

The layout of the Btrfs filesystem structure is highly dependent on the demands of the system. It is advised to have at least separate subvolumes for / (the primary hierarchy root), /home and the swapfile which will increase security and make backups and other types of maintenance easier. If Gentoo is being installed to perform as a mail server, then /var should be backed by a subvolume of its own as all mails are stored inside the /var directory. Game servers may have a separate subvolume to mount at /opt since most gaming server software is installed therein. The reasoning for these is similar to the /home directory: security, backups, and maintenance.

With Btrfs the available space on the underlying partition (or block device, in case the Btrfs filesystem is created directly on it) is allocated dynamically and on demand to the subvolumes. Thus it's not necessary to define the size of subvolumes or even bother about it, as long as the underlying partition is big enough to accommodate all the data.

What about swap space?

The copy-on-write nature of Btrfs is not suitable for swapping. That's why on Btrfs swap space is realized with swapfiles. Thus it's possible to set special file attributes (NOCOW) to selectively disable copy-on-write. With NOCOW set, it becomes necessary to pre-allocate space to the swapfile.

There is no perfect value for the size of the swapfile. The purpose of swap space is to provide disk storage to the kernel when internal memory (RAM) is under pressure. A swap space allows for the kernel to move memory pages that are not likely to be accessed soon to disk (swap or page-out), freeing memory. Of course, if that memory is suddenly needed, these pages need to be put back in memory (page-in) which will take a while (as disks are very slow compared to internal memory).

When the system is not going to run memory intensive applications or the system has lots of memory available, then it probably does not need much swap space. However, swap space is also used to store the entire memory in case of hibernation. If the system is going to need hibernation, then a bigger swap space is necessary, often at least the amount of memory installed in the system.

Prior to kernel 5.0 Btrfs did not support swapfiles at all. Resort to a traditional swap partition in case the target system is supposed to run older kernels. To that end, designing a partition scheme is recommended.


If firmware=rockchip Using parted to partition the device

If firmware=uefi Using parted to partition the device

If firmware=raspi4 Using fdisk to partition the device

If firmware=depthcharge Using cgpt to partition the device