How to install ZFS in Debian 12 “Bookworm”
How to install ZFS in Debian Linux 12 “Bookworm”
The procedure is as follows:
- Open your terminal application.
- For remote server login using the ssh command:
- ssh user@debian-12-server
- Add or enable contrib repo to /etc/apt/sources.list using sed command:
- sed -r -i'.BAK' 's/^deb(.*)$/deb\1 contrib/g' /etc/apt/sources.list
Here is how it looks when contrib is appended to each line:deb http://deb.debian.org/debian bookworm main non-free non-free-firmware contrib deb http://deb.debian.org/debian bookworm-updates main non-free non-free-firmware contrib deb http://deb.debian.org/debian-security/ bookworm-security main non-free non-free-firmware contrib
- Update apt repo database, type:
- apt update
- Install zfs package on a Debian Linux 12:
- apt install linux-headers-amd64 zfsutils-linux zfs-dkms zfs-zed
Are you using a cloud server with cloud Linux kernel? Try: - apt install linux-headers-cloud-amd64 zfsutils-linux zfs-dkms zfs-zed
- Test it by running zfs version command:
modprobe zfs #<--load the module1.
zfs version
Outputs:zfs-2.1.11-1 zfs-kmod-2.1.11-1
Help! ZFS is eating all my RAM in a Debian machine
No, ZFS is not eating all RAM. But, ensure that your system meets the requirements for running ZFS, such as having enough RAM and storage capacity. Additionally, it’s always a good idea to back up your important data before changing your file system. There are ways to tame ZFS ram usage so that all applications can run smoothly. Please see the following pages:
- How to set up ZFS ARC size on Ubuntu/Debian Linux (FreeBSD specific info is here.)
- How to check ZFS File system storage pool on Linux/Unix
Turning a simple disk /dev/xvdf into ZFS
WARNING! Please be cautious when using the following commands, as they will delete all data stored on the disk drive. It is crucial to ensure the device name is correct before executing these commands. The nixCraft or author cannot be held responsible for any data loss. It is highly recommended to maintain verified backups at all times.
Say you have a cloud-based block storage disk named /dev/xvdf. Here is how to create ZFS disks under Linux:
- Remove all data from the /dev/xvdf (replace the /dev/xvdf with correct device name):
- sudo sgdisk --zap-all /dev/xvdf
- Next, you must create a Solaris ZFS partition. For example:
- sudo sgdisk --new=1:0:0 --typecode=1:BF00 /dev/xvdf
- Create a new ZFS pool for Linux:
- sudo zpool create -f -d -m none -o ashift=12 -O atime=off -o feature@lz4_compress=enabled backup /dev/xvdf1
The above command creates a new ZFS pool named backup using the following zpool create command switches:- -f : Forces the creation of the pool
- -d : Disables automatic device discovery.
- -m none : Does not use a mirror to protect the pool because I’ve a single disk here.
- -o ashift=12 : Sets the alignment shift to 12, which improves performance for large files.
- -O atime=off : Disables access time tracking, which improves performance.
- -o feature@lz4_compress=enabled : Enables LZ4 compression for the pool to save disk space.
- /dev/xvdf1 : The block storage device to use for the pool.
- Create a new dataset:
- sudo zfs create backup/rsnapshot
sudo zfs set compression=lz4 backup/rsnapshot
sudo zfs set atime=off backup/rsnapshot - sudo zfs set mountpoint=/backup backup
- You can now use the /backup/rsnapshot/ to store files and verify using the mount command or df command/du command. Use the following command to get space info about zfs storage pool:
- sudo zpool list
Outputs:NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT backup 127G 15.4G 112G - - - 12% 1.00x ONLINE -
Summing up
That is all. Now ZFS is installed on your Debian Linux 12 “Bookworm” system. You can now use zfs and zpool commands to create new pools and do ZFS maintenance. For more info, see the following manual pages using the man command or help command:
man zpool
man zfs
man apt
man apt-get
man sources.list