BTRFS - How to convert single disk into RAID 1 (with LUKS)?

Hi. I have a laptop with two disks and I’d like to use them in a RAID-1 configuration but I also want encryption. I ran into a lot of issues trying to used (mdadm) RAID with LUKS and it looks like BTRFS might be a better solution. So far I’ve installed a fresh copy of Manjaro i3 CE on it using the installer with BTRFS on a single disk and just ignored the other disk during installation.

I am brand new to BTRFS so don’t really know what to do. I think I just need to add a partition on the new drive to BTRFS and then change the mode to RAID. Again, not sure exactly how to do this.

This is what my partition schema looks like after the installation:

Found valid GPT with protective MBR; using GPT.
Disk /dev/nvme0n1: 1000215216 sectors, 476.9 GiB
Model: KINGSTON SKC3000S512G                   
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 7DC7A800-68BE-4BEE-A7AB-84AFF3F9DBF3
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 2048, last usable sector is 1000215182
Partitions will be aligned on 8-sector boundaries
Total free space is 10331 sectors (5.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            4096          618495   300.0 MiB   EF00  
   2          618496       981751961   467.8 GiB   8300  root
   3       981751962      1000206899   8.8 GiB     8300

And:

Filesystem      Size  Used Avail Use% Mounted on
dev             3.8G     0  3.8G   0% /dev
run             3.8G  1.7M  3.8G   1% /run
efivarfs        192K   42K  146K  23% /sys/firmware/efi/efivars
/dev/dm-0       468G   12G  456G   3% /
tmpfs           3.8G  276K  3.8G   1% /dev/shm
/dev/dm-0       468G   12G  456G   3% /home
/dev/dm-0       468G   12G  456G   3% /var/cache
/dev/dm-0       468G   12G  456G   3% /var/log
tmpfs           3.8G  604K  3.8G   1% /tmp
/dev/nvme0n1p1  300M  720K  299M   1% /boot/efi
tmpfs           779M   72K  779M   1% /run/user/1000

I have copied the GPT partition schema to the new drive (nvme1n1) like so:

$ sudo sgdisk /dev/nvme0n1 -R /dev/nvme1n1
$ sudo sgdisk -G /dev/nvme1n1

Do I just need to add the new partition like so?

$ sudo btrfs device add /dev/nvme1n1p2 PATH

What would the path be?

Thanks.

Probably:

sudo btrfs device add /dev/nvme1n1p2 /
sudo btrfs balance start -dconvert=raid1 -mconvert=raid1 --bg /
sudo watch -n1 'btrfs balance status /'

:notebook: Replace /dev/nvme1n1p2 with the unlocked cryptdevice /dev/mapper/whatevername if you use luks.

Also keep in mind that you need to add the btrfs hook to mkinitcpio.conf so that the device will remain bootable. See: mkinitcpio - ArchWiki

You find good Information about Btrfs in the wiki

and in

:footprints:

Please be carefull not to have the same UUID on different partitions :see_no_evil:

Yeah I do use luks I guess although my sum knowledge of it is clicking the “encrypt device” during the installation.

The only thing I did after the installation was copy the gpt partition schema to the new drive…so there is no /dev/mapper/something for nvme1n1p2.

Since your reply, I have tried to create a new luks volume with the below command. I have no idea if that is correct or if I’ve used the same key (I was never asked for a passphrase).

$ sudo cryptsetup -v -c aes-xts-plain64 -h sha256 -s 512 luksFormat /dev/nvme1n1p2 /crypto_keyfile.bin

You’re right - btrfs is not currently included in HOOKS. I would have thought it got added by the installer during installation. How is it currently bootable then?

Well then have a nice self-study. You know where to look and how to test it. Get familiar with luks before using btrfs on that. I don’t use luks.

The btrfs hook needs to be there, when you have a multiple-disk. It will scan it on boot time to discover all btrfs partitions. Not needed on a single-disk.

1 Like

Thanks for your reply. I might have to re-think this one then. If it’s gonna involve a lot of messing around I might as well just install Arch Linux. I really use Manjaro for convenience when I don’t want to spend days installing an OS. LUKS with (mdadm) RAID should work. It’s a shame the Manjaro installer doesn’t currently support encrypted RAID. Thanks anyway.

Well, it works, when configured correctly, but note that this is not a normal basic installation for average users, rather a edge case for experts.

So using ArchLinux would be probably better, if you need a special setup, although Manjaro can also be installed like that.

Does calamares (the installer) even support raid (mdadm)? I doubt that. It’s more an upstream problem see: Feature request: Support RAID · Issue #987 · calamares/calamares · GitHub and not Manjaro’s fault.

In theory yes.

Remember that RAID is not a replacement for a regular important files backup.

Calamares is not an installer specifically targeted Manjaro.

I have been using mdadm for various purposes but I have seen it loose confiugration far too many times - thus needing manual intervention.

For the average user this is not recommended - you can setup the disks beforehand - then run the installer.

You can review my notes if you like https://root.nix.dk/en/notes-and-bookmarks/md-raid-notes

You should take that up with the devs of the installer, Calamares, not Manjaro.

Then don’t. I can not see this comment as anything other than toxic. The things you talk about here is outside of Manjaros control unless you expect them to develop their own installer.