Revision 2 of 2026-11-25 20:31 UTC by tux, the current one. Current version - History
Encrypted disk
5.1
Three tools for disks, all in the packages: LUKS (cryptsetup) encrypts a partition, a USB key or a file, so that a lost laptop or key gives nothing away without the passphrase; software RAID (mdadm) keeps a copy of the data on a second disk; LVM (lvm2) makes volumes you can grow and move across disks.
On an installed SliTaz 5.1 they work for data: a second partition, a second disk, a USB key, a directory of your home. The system itself, the root partition, stays a plain partition: see The root partition below.
What you need
As root:
# spk-add cryptsetup
# spk-add mdadm
# spk-add lvm2
Take only the ones you use. The kernel parts are modules: dm-mod,
dm-crypt and the RAID modules are in linux-lts-storage, the
ciphers (xts, aesni-intel...) in linux-lts-crypto. cryptsetup
pulls both in; the desktop ISOs already have linux-lts-storage, the Base
ISO does not:
# spk-add linux-lts-storage
Every command on this page runs as root.
An encrypted partition
Here the partition is /dev/sdb1: check the name with blkid or
fdisk -l first. Formatting erases everything on it.
# cryptsetup luksFormat /dev/sdb1
Type YES in capitals, then the passphrase twice. Open it under a name
of your choice, here data, and make a file system inside:
# cryptsetup open /dev/sdb1 data
# mkfs.ext4 -L data /dev/mapper/data
# mkdir -p /mnt/data
# mount /dev/mapper/data /mnt/data
# chown tux:users /mnt/data
/dev/mapper/data is the decrypted view of the partition: use it like
any partition. When you are done:
# umount /mnt/data
# cryptsetup close data
cryptsetup status data shows an open device, cryptsetup luksDump
/dev/sdb1 the header of the partition (format, key slots). A partition
can have several passphrases; to add one:
# cryptsetup luksAddKey /dev/sdb1
Back up the header. If the first megabytes of the partition are damaged, the data is lost even with the right passphrase. Keep a copy of the header somewhere else (not on the encrypted partition):
# cryptsetup luksHeaderBackup /dev/sdb1 --header-backup-file sdb1-header.img
Open it after login
SliTaz has no crypttab: no boot script opens encrypted devices. Open
it once logged in, with a small script, for example /usr/local/sbin/data-open:
#!/bin/sh
cryptsetup open /dev/disk/by-uuid/UUID data &&
mount /dev/mapper/data /mnt/data
Replace UUID with the one blkid /dev/sdb1 gives for the LUKS
partition (TYPE="crypto_LUKS"): the device name can change, the UUID
does not. Make it executable with chmod +x and run it as root from a
terminal after login.
If you add the volume to /etc/fstab, give it the noauto option: the
boot mounts fstab before anything can open the volume, and the line
would fail.
/dev/mapper/data /mnt/data ext4 noauto 0 0
mount /mnt/data then mounts it after cryptsetup open.
A container in a file
No free partition? A LUKS volume can live in a file, on any partition or a USB key. cryptsetup sets up the loop device by itself.
# dd if=/dev/zero of=/home/tux/private.img bs=1M count=512
# cryptsetup luksFormat /home/tux/private.img
# cryptsetup open /home/tux/private.img private
# mkfs.ext4 /dev/mapper/private
# mkdir -p /home/tux/private
# mount /dev/mapper/private /home/tux/private
# chown tux:users /home/tux/private
512 MB here; change count= for another size. Close it with umount
then cryptsetup close private.
Encrypted USB key
The same steps as for a partition, on the partition of the key
(/dev/sdc1, check with blkid). Such a key opens on any Linux with
cryptsetup, not on Windows.
Software RAID with mdadm
A mirror (RAID 1) of two partitions of the same size, on two disks,
here /dev/sda3 and /dev/sdb3:
# modprobe raid1
# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda3 /dev/sdb3
# mkfs.ext4 /dev/md0
# mdadm --detail --scan >> /etc/mdadm.conf
cat /proc/mdstat shows the array and the first copy between the two
disks; you can use /dev/md0 during the copy. The RAID modules are
raid0, raid1, raid10 and raid456.
Nothing assembles the array at boot. Add these lines at the end of
/etc/init.d/local.sh:
modprobe raid1
mdadm --assemble --scan
mount /dev/md0 /mnt/raid
and keep /dev/md0 out of /etc/fstab, or give it noauto.
mdadm --detail /dev/md0 says whether a disk failed. To replace it:
# mdadm /dev/md0 --fail /dev/sdb3 --remove /dev/sdb3
change the disk, make the same partition on it, then
mdadm /dev/md0 --add /dev/sdb3: the copy starts again.
LVM
LVM puts one or more partitions (physical volumes) in a group, and cuts
the group into logical volumes that can be resized later. Here one
partition, /dev/sdb2, and a group named vg0:
# modprobe dm-mod
# pvcreate /dev/sdb2
# vgcreate vg0 /dev/sdb2
# lvcreate -L 20G -n data vg0
# mkfs.ext4 /dev/mapper/vg0-data
The volume is /dev/mapper/vg0-data (also /dev/vg0/data). To grow it
later by 5 GB, then the ext4 file system inside:
# lvextend -L +5G vg0/data
# resize2fs /dev/mapper/vg0-data
pvs, vgs and lvs list what exists. At boot the volumes are not
activated: add to /etc/init.d/local.sh
modprobe dm-mod
vgchange -ay
mount /dev/mapper/vg0-data /mnt/lvm
The lvm2 package brings udev rules made for systemd: their automatic
activation does nothing on SliTaz, vgchange -ay is what activates
the volumes.
LVM in LUKS: open the LUKS volume first, then pvcreate
/dev/mapper/data and go on as above; at boot, cryptsetup open comes
before vgchange -ay. LUKS on RAID: cryptsetup luksFormat
/dev/md0.
The root partition
An installed SliTaz 5.1 boots without an initramfs: GRUB loads the
kernel, and the kernel mounts root= itself. The device-mapper and the
RAID drivers are modules, which are on the root partition, so the
kernel cannot use them to reach it. The root partition cannot be
encrypted, on RAID or on LVM with the installer or the standard boot.
The live /init still knows the boot options cryptoroot=,
lvmroot=, softraid= and dmraid=, but they need an initramfs with
cryptsetup, mdadm or lvm2 and their modules inside. SliTaz 5.0 had the
preinit flavor for that; it is not rebuilt for 5.1. See
Boot process.
What you can do:
- keep your files on an encrypted partition or container, as above, and put your documents there;
/tmpis emptied at each boot (CLEAN_UP_SYSTEM="yes"in/etc/rcS.conf);- prefer zram to a swap partition, it stays in RAM: see Zram swap.
Encrypted swap
If you need a swap partition, it can get a new random key at each boot:
nothing written there survives a reboot. As root, with the swap
partition /dev/sda2: remove its line from /etc/fstab, then turn it
off and erase its swap signature, or the boot finds it again and turns
it on as a plain swap:
# swapoff /dev/sda2
# dd if=/dev/zero of=/dev/sda2 bs=1M count=1
Then add to /etc/init.d/local.sh:
cryptsetup open --type plain --key-file /dev/urandom /dev/sda2 swap
mkswap /dev/mapper/swap > /dev/null && swapon /dev/mapper/swap
Check the partition name twice: this erases it at every boot.
Tips
- On an old machine with little memory, a volume made on a recent
computer may need more RAM to open than there is: LUKS2 uses Argon2,
which takes memory on purpose. Format it on the old machine itself,
where cryptsetup lowers the memory cost, or with
cryptsetup luksFormat --pbkdf pbkdf2 /dev/sdb1. cryptsetup benchmarkcompares the ciphers on your processor.- The mount points of these examples (
/mnt/data,/mnt/raid,/mnt/lvm) must exist: create them once withmkdir -p.
Troubleshooting
"Cannot initialize device-mapper. Is dm_mod kernel module loaded?":
run modprobe dm-mod as root; if the module is not found, install
linux-lts-storage. "running as non-root user" means you are not root.
"No key available with this passphrase.": wrong passphrase, or the
wrong keyboard layout at the console. Check the keymap with
trame keyboard get.
"Device data is still in use." when closing: the volume is still
mounted, or a shell sits in its directory. umount it first.
The RAID or the LVM volume is missing after a reboot: the lines in
/etc/init.d/local.sh were not run, or the fstab line has no noauto.
Read the boot messages with bootlog.