chore: improved folder structure

This commit is contained in:
Michele Cereda
2023-09-18 00:37:48 +02:00
parent bcd597f9ea
commit 66428e7670
5 changed files with 154 additions and 77 deletions

View File

@@ -13,125 +13,133 @@ Features and benefits [here][introduction]. (Meta)Data profiles [here][mkfs.btrf
## TL;DR ## TL;DR
```sh ```sh
# Create a volume with single metadata and double data blocks # Create volumes with single metadata and double data blocks.
# Useless in practice, but a good example nonetheless. # Useless in practice, but a good example nonetheless.
sudo mkfs.btrfs --metadata 'single' --data 'dup' '/dev/sdb' sudo mkfs.btrfs --metadata "single" --data "dup" "/dev/sdb"
# Sparse a volume on multiple devices. # Sparse one volume on multiple devices.
sudo mkfs.btrfs --label 'data' /dev/sd{a,c,d,f,g} --force \ sudo mkfs.btrfs --label "data" /dev/sd{a,c,d,f,g} --force \
&& echo "LABEL=data /mnt/data btrfs compress=zstd 0 0" && echo "LABEL=data /mnt/data btrfs compress=zstd 0 0"
| tee -a /etc/fstab | tee -a /etc/fstab
```
# List all btrfs file systems. ```sh
# List all BTRFS file systems.
sudo btrfs filesystem show sudo btrfs filesystem show
# Show detailed `df` analogue for a filesystem. # Show detailed `df` analogue for filesystems.
sudo btrfs filesystem df 'path/to/filesystem' sudo btrfs filesystem df "path/to/filesystem"
sudo btrfs filesystem df -h 'path/to/filesystem' sudo btrfs filesystem df -h "path/to/filesystem"
# Show detailed `du` analogue for a filesystem. # Show detailed `du` analogue for filesystems.
sudo btrfs filesystem du 'path/to/filesystem' sudo btrfs filesystem du "path/to/filesystem"
sudo btrfs filesystem du --human-readable -s 'path/to/filesystem' sudo btrfs filesystem du --human-readable -s "path/to/filesystem"
# Give more details about usage. # Give more details about filesystems' usage.
sudo btrfs filesystem usage 'path/to/filesystem' sudo btrfs filesystem usage "path/to/filesystem"
# Resize online volumes. # Resize *online* volumes.
# -2g decreases, +2g increases. # -2g decreases, +2g increases.
sudo btrfs filesystem resize '-2g' 'path/to/volume' sudo btrfs filesystem resize "-2g" "path/to/volume"
sudo btrfs filesystem resize 'max' 'path/to/volume' sudo btrfs filesystem resize "max" "path/to/volume"
# Add new devices to a filesystem. # Add new devices to filesystems.
sudo btrfs device add '/dev/sdb' '/mnt' sudo btrfs device add "/dev/sdb" "path/to/filesystem"
# Remove devices from a filesystem. # Remove devices from filesystems.
sudo btrfs device delete missing '/mnt' sudo btrfs device delete missing "path/to/filesystem"
# List subvolumes. # List subvolumes.
sudo btrfs subvolume list '/mnt' sudo btrfs subvolume list "path/to/subvolume"
# Create subvolumes. # Create subvolumes.
btrfs subvolume create ~/subvolume btrfs subvolume create "${HOME}/path/to/subvolume"
sudo btrfs subvolume create '/mnt/subvolume' sudo btrfs subvolume create "path/to/subvolume"
# Create a readonly snapshot of a subvolume. # Create snapshots of subvolumes.
btrfs subvolume snapshot ~/subvolume ~/snapshot btrfs subvolume snapshot "${HOME}/path/to/subvolume" "${HOME}/path/to/snapshot"
sudo btrfs subvolume snapshot -r '/mnt/volume/subvolume' '/mnt/volume/snapshot' sudo btrfs subvolume snapshot -r "path/to/subvolume" "path/to/snapshot"
# Mount subvolumes without mounting their main filesystem. # Mount subvolumes without mounting their main filesystem.
sudo mount -o 'subvol=sv1' '/dev/sdb' '/mnt' sudo mount -o 'subvol=sv1' "/dev/sdb" "/mnt"
# Delete a subvolume. # Delete subvolumes.
sudo btrfs subvolume delete --commit-each '/mnt/volume/subvolume' sudo btrfs subvolume delete --commit-each "path/to/subvolume"
# Deduplicate a volume's blocks. # Automatically compress new files and folders in directories in BTRFS mounts.
sudo duperemove -Adrh --hashfile='/tmp/dr.hash' '/mnt/volume1' '/media' 'volume2' chattr +c 'path/to/dir'
sudo jdupes --dedupe -rZ '/mnt/volume1' '/media' 'volume2'
# Disable Copy-on-Write for folders or subvolumes.
chattr +C 'path/to/dir'
# Deduplicate volumes' blocks.
sudo duperemove -Adrh --hashfile="/tmp/dr.hash" "path/1""path/n"
sudo jdupes --dedupe -rZ "path/1""path/n"
# Send and receive snapshots. # Send and receive snapshots.
sudo btrfs send '/source/.snapshots/snap' \ sudo btrfs send "path/to/source/snapshots" \
| sudo btrfs receive '/destination/.snapshots/' | sudo btrfs receive "path/to/destination/snapshots/folder/"
# Show the properties of a subvolume/filesystem/inode/device. # Show the properties of subvolumes/filesystems/inodes/devices.
btrfs property get -ts 'path/to/subvolume' btrfs property get -ts "path/to/subvolume"
btrfs property get -tf 'path/to/filesystem' btrfs -tf "path/to/filesystem"
btrfs property get -ti 'path/to/inode' btrfs -ti "path/to/inode"
btrfs property get -td 'path/to/device' btrfs -td "path/to/device"
btrfs property get 'path/to/autoselected/type/of/resource' btrfs "path/to/autoselected/type/of/resource"
# Change a subvolume to RO on the fly. # Change RW subvolumes to RO ones on the fly.
btrfs property set -ts 'path/to/subvolume' 'ro' 'true' btrfs property set -ts "path/to/subvolume" 'ro' 'true'
# Show a volume's information. # Show subvolumes' information.
sudo btrfs subvolume show 'path/to/subvolume' sudo btrfs subvolume show "path/to/subvolume"
# Check the compress ratio of a compressed volume. # Check the compress ratio of compressed volumes.
# Requires `compsize`. # Requires `compsize`.
sudo compsize '/mnt/volume' sudo compsize "path/to/subvolume"
# Show the status of a running or paused balance operation. # Show the status of running or paused balance operations.
sudo btrfs balance status 'path/to/filesystem' sudo btrfs balance status "path/to/filesystem"
# Balance all block groups. # Balance all block groups.
# Slow: rewrites all blocks in filesystem. # Slow, because it rewrites *all* blocks in the filesystem.
sudo btrfs balance start 'path/to/filesystem' sudo btrfs balance start "path/to/filesystem"
sudo btrfs balance start 'path/to/filesystem' --bg --enqueue sudo btrfs balance start "path/to/filesystem" --bg --enqueue
# Balance data block groups which are less than 15% utilized. # Balance data block groups which are less than 15% utilized.
# Run the operation in the background # Run the operation in the background.
sudo btrfs balance start --bg -dusage='15' 'path/to/filesystem' sudo btrfs balance start --bg -dusage='15' "path/to/filesystem"
# Balance a max of 10 metadata chunks with less than 20% utilization and at # Balance a max of 10 metadata chunks with less than 20% utilization and at
# least 1 chunk on a given device 'devid'. # least 1 chunk on a given device 'devid'.
# Get the device's devid with `btrfs filesystem show`. # Get the device's devid with `btrfs filesystem show`.
sudo btrfs balance start -musage='20,limit=10,devid=devid' 'path/to/filesystem' sudo btrfs balance start -musage='20,limit=10,devid=devid' "path/to/filesystem"
# Convert data blocks to the 'raid6' profile, and metadata to 'raid1c3'. # Convert data blocks to the 'raid6' profile, and metadata to 'raid1c3'.
sudo btrfs balance start -dconvert='raid6' -mconvert='raid1c3' 'path/to/filesystem' sudo btrfs balance start -dconvert='raid6' -mconvert='raid1c3' "path/to/filesystem"
# Convert data blocks to raid1 skipping already converted chunks. # Convert data blocks to raid1 skipping already converted chunks.
# Useful after a previous cancelled conversion operation. # Useful after a previous cancelled conversion operation.
sudo btrfs balance start -dconvert='raid1,soft' 'path/to/filesystem' sudo btrfs balance start -dconvert='raid1,soft' "path/to/filesystem"
# Cancel, pause or resume a running or paused balance operation. # Cancel, pause or resume running or paused balance operations.
sudo btrfs balance cancel 'path/to/filesystem' sudo btrfs balance cancel "path/to/filesystem"
sudo btrfs balance pause 'path/to/filesystem' sudo btrfs balance pause "path/to/filesystem"
sudo btrfs balance resume 'path/to/filesystem' sudo btrfs balance resume "path/to/filesystem"
# Enable quota. # Enable quota.
sudo btrfs quota enable 'path/to/subvolume' sudo btrfs quota enable "path/to/subvolume"
# Show quota. # Show quota.
sudo btrfs qgroup show 'path/to/subvolume' sudo btrfs qgroup show "path/to/subvolume"
# Convert ext3/ext4 to btrfs. # Convert ext3/ext4 filesystems to BTRFS.
btrfs-convert '/dev/sdb1' btrfs-convert "/dev/sdb1"
# Convert btrfs to ext3/ext4. # Convert BTRFS filesystems to ext3/ext4.
btrfs-convert -r '/dev/sdb1' btrfs-convert -r "/dev/sdb1"
# Create and activate a 2GB swapfile. # Create and activate a 2GB swapfile.
# Generic procedure. Valid for all `btrfs`' versions. # Generic procedure.
truncate -s '0' 'path/to/swapfile' truncate -s '0' 'path/to/swapfile'
chattr +C 'path/to/swapfile' chattr +C 'path/to/swapfile'
fallocate -l '2G' 'path/to/swapfile' fallocate -l '2G' 'path/to/swapfile'
@@ -140,7 +148,7 @@ mkswap 'path/to/swapfile'
swapon 'path/to/swapfile' swapon 'path/to/swapfile'
# Create and activate a 2GB swapfile. # Create and activate a 2GB swapfile.
# `btrfs` >= 6.1 only. # `btrfs` utility >= 6.1 only.
btrfs filesystem mkswapfile --size '2G' 'path/to/swapfile' btrfs filesystem mkswapfile --size '2G' 'path/to/swapfile'
swapon 'path/to/swapfile' swapon 'path/to/swapfile'
``` ```
@@ -150,7 +158,7 @@ swapon 'path/to/swapfile'
See also [snapper]. See also [snapper].
```sh ```sh
sudo btrfs send --no-data -p '/old/snapshot' '/new/snapshot' \ sudo btrfs send --no-data -p "path/to/old/snapshot" "path/to/new/snapshot" \
| sudo btrfs receive --dump | sudo btrfs receive --dump
# Requires one to be using `snapper` to manage the snapshots. # Requires one to be using `snapper` to manage the snapshots.

View File

@@ -3,18 +3,37 @@
## TL;DR ## TL;DR
```sh ```sh
# Copy permissions from another file. # Change permissions of files or directories.
# Only available in GNU cp. chmod '775' "path/to/dir"
chmod --reference 'reference-file' 'changed-file' chmod 'u=rw' "path/to/dir"
chmod 'go+x' "path/to/file"
# Set 'setuid' bit.
chmod '04755' "path/to/dir"
chmod 'u-s' "path/to/file"
# Set 'setgid' bit.
chmod '02775' "path/to/dir"
chmod 'g+s' "path/to/file"
# Set 'sticky' bit.
# Allows only the *owner* to change content and delete.
chmod '01775' "path/to/dir"
chmod 'a+t' "path/to/file"
# Set combinations of 'set*id' and 'sticky' bits.
chmod '03775' "path/to/setgid/and/sticky/dir"
chmod '05664' "path/to/setuid/and/sticky/file"
chmod '07644' "path/to/setuid/setgid/and/sticky/file"
``` ```
## Sources ## Sources
- [18 selected super-useful Linux one-liners] - [File permissions and attributes]
<!-- <!--
References References
--> -->
<!-- Others --> <!-- Others -->
[18 selected super-useful linux one-liners]: https://medium.com/codex/18-selected-super-useful-linux-one-liners-398ba6d20f8c [file permissions and attributes]: https://wiki.archlinux.org/title/File_permissions_and_attributes

View File

@@ -4,6 +4,7 @@
1. [Hardware](#hardware) 1. [Hardware](#hardware)
1. [Software](#software) 1. [Software](#software)
1. [Folder structure](#folder-structure)
1. [Further readings](#further-readings) 1. [Further readings](#further-readings)
1. [Sources](#sources) 1. [Sources](#sources)
@@ -28,11 +29,25 @@
| OS file system | Default (ext4) | | | OS file system | Default (ext4) | |
| Data file system | ZFS | See [ZFS on OpenMediaVault](../openmediavault.md#zfs) | | Data file system | ZFS | See [ZFS on OpenMediaVault](../openmediavault.md#zfs) |
ZFS datasets used as shared folders shall have the following properties: The ZFS pool and datasets used as shared folders shall have the following properties:
- `aclinherit:restricted`; - `aclinherit:restricted`;
- `aclmode:groupmask`; - `aclmode:groupmask`;
- `acltype:posix` + `xattr:sa` until `nfsv4` is supported on Linux. - `acltype:posix` + `xattr:sa` until `nfsv4` is supported on Linux.
## Folder structure
```sh
/tank/ <-- pool
├── shared/ <-- shared datasets root, 'nobody:users', 'rwsrwsr-x' + 'd:u::rwX,g::rwX,o::rX'
│ ├── media/
│ └── oam/
└── user/ <-- private datasets root, 'user:user', 'rwsr-s---' + 'd:u::rwX,g::rX,o::-'
├── archive/
├── docs/
├── oam/
└── work/
```
## Further readings ## Further readings
- [OpenMediaVault] - [OpenMediaVault]

View File

@@ -0,0 +1,31 @@
# Chmod
## TL;DR
```sh
# Copy permissions from another file.
chmod --reference 'reference-file' 'changed-file'
```
## Further readings
- [`chmod`][chmod]
## Sources
All the references in the [further readings] section, plus the following:
- [18 selected super-useful Linux one-liners]
<!--
References
-->
<!-- In-article sections -->
[further readings]: #further-readings
<!-- Knowledge base -->
[chmod]: ../chmod.md
<!-- Others -->
[18 selected super-useful linux one-liners]: https://medium.com/codex/18-selected-super-useful-linux-one-liners-398ba6d20f8c

View File

@@ -121,13 +121,17 @@ zfs snapshot 'pool_name/filesystem_name@snapshot_name'
zfs destroy 'pool_name/filesystem_name@snapshot_name' zfs destroy 'pool_name/filesystem_name@snapshot_name'
# Query a file system or volume configuration (get properties). # Query a file system or volume configuration (get properties).
zfs get all 'pool_name' zfs get 'all' 'pool_name'
zfs get all 'pool_name/filesystem_name' zfs get 'aclmode,aclinherit,acltype,xattr' 'pool_name/filesystem_name'
# Enable or change settings on a filesystem. # Enable or change settings on a filesystem.
zfs set 'compression=on' 'pool_name/filesystem_name' zfs set 'compression=on' 'pool_name/filesystem_name'
zfs set 'mountpoint=/my/mount/path' 'pool_name/filesystem_name' zfs set 'mountpoint=/my/mount/path' 'pool_name/filesystem_name'
# Reset properties to default.
zfs inherit 'compression' 'pool_name/filesystem_name'
zfs inherit -r 'acltype' 'pool_name/filesystem_name'
# Get more information about zfs volumes properties. # Get more information about zfs volumes properties.
man zfs man zfs
``` ```