105 lines
2 KiB
Markdown
105 lines
2 KiB
Markdown
---
|
|
arch-wiki: https://wiki.archlinux.org/title/Btrfs
|
|
obj: filesystem
|
|
---
|
|
# Btrfs
|
|
Btrfs is a modern copy on write (CoW) filesystem for [Linux](../Linux.md) aimed at implementing advanced features while also focusing on fault tolerance, repair and easy administration. Btrfs is licensed under the GPL and open for contribution from anyone.
|
|
|
|
## Create the filesystem
|
|
**Single Device**:
|
|
``` shell
|
|
mkfs.btrfs -L _mylabel_ /dev/partition
|
|
```
|
|
**Multiple Devices (similiar to [RAID](RAID.md))**:
|
|
```shell
|
|
mkfs.btrfs -d single -m raid1 /dev/part1 /dev/part2 ...
|
|
```
|
|
|
|
## Subvolumes
|
|
Subvolumes are their own seperated namespaces and work like [ZFS](ZFS.md) Datasets. They can be mounted seperately. Each Btrfs file system has a top-level subvolume with ID 5.
|
|
|
|
**Create a subvolume**:
|
|
```shell
|
|
btrfs subvolume create /path/to/subvolume
|
|
```
|
|
|
|
**List suvolumes**:
|
|
```shell
|
|
btrfs subvolume list -p path
|
|
```
|
|
|
|
**Delete subvolume**:
|
|
```shell
|
|
btrfs subvolume delete /path/to/subvolume
|
|
```
|
|
|
|
## Using Swapfiles
|
|
Swapfiles can be used by disabling CoW:
|
|
```shell
|
|
chattr +C /path/to/swapsubvolume
|
|
```
|
|
|
|
**Use swapfile:**
|
|
```shell
|
|
touch /swapfile
|
|
chattr +C /swapfile
|
|
fallocate -l 8G /swapfile
|
|
chmod 0600 /swapfile
|
|
mkswap /swapfile
|
|
swapon /swapfile
|
|
```
|
|
|
|
## Filesystem Usage
|
|
**See Usage**:
|
|
```shell
|
|
btrfs filesystem usage /
|
|
```
|
|
|
|
**Available Space:**
|
|
```shell
|
|
btrfs filesystem df /
|
|
```
|
|
|
|
## Scrub
|
|
Btrfs can self heal itself or check for errors with scrubbing.
|
|
**Start:**
|
|
```shell
|
|
btrfs scrub start /
|
|
```
|
|
|
|
**See Status:**
|
|
```shell
|
|
btrfs scrub status /
|
|
```
|
|
|
|
## Balance
|
|
Rebalance the filesystem.
|
|
```shell
|
|
btrfs balance start --bg /
|
|
btrfs balance status /
|
|
```
|
|
|
|
## Snapshots
|
|
Btrfs can use snapshots
|
|
```shell
|
|
btrfs subvolume snapshot source [dest/]name
|
|
````
|
|
|
|
## Resizing
|
|
Btrfs can be resized.
|
|
|
|
**To extend the file system size to the maximum available size of the device:**
|
|
```shell
|
|
btrfs filesystem resize max /
|
|
```
|
|
|
|
**To extend the file system to a specific size:**
|
|
```shell
|
|
btrfs filesystem resize size /
|
|
```
|
|
|
|
**Add or remove size**
|
|
```shell
|
|
btrfs filesystem resize +size /
|
|
btrfs filesystem resize -size /
|
|
```
|