reencrypt_linux_post_install
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| reencrypt_linux_post_install [2025/05/03 18:40] – [Do the actual reencryption] usera | reencrypt_linux_post_install [2026/06/19 09:25] (current) – usera | ||
|---|---|---|---|
| Line 13: | Line 13: | ||
| You should make (encrypted !) backups of your system all the time. However, you should **ABSOLUTELY** do it before any operation on your disks or partitions such as the one presented here: there is a significant risk to destroy ALL your data. | You should make (encrypted !) backups of your system all the time. However, you should **ABSOLUTELY** do it before any operation on your disks or partitions such as the one presented here: there is a significant risk to destroy ALL your data. | ||
| - | I suggest a backup using two different open source softwares. The first one is [[https:// | + | Please follow the procedures listed |
| - | For this, you will need: | ||
| - | |||
| - | - An external hard drive to store the backup. I suggest using an external SSD with a capacity of roughly 3 times your whole drive capacity. For example, if you have a 500GB drive, you will probably be fine with a 2TB drive, but it should be used only for this purpose. | ||
| - | - An external USB stick to install CloneZilla. It should be at least 1GB and be used only for CloneZilla | ||
| - | |||
| - | ==== STEP 1.1: prepare the CloneZilla USB stick ==== | ||
| - | |||
| - | First, [[https:// | ||
| - | |||
| - | Then, verify the download, using the following commands: | ||
| - | |||
| - | < | ||
| - | wget https:// | ||
| - | wget https:// | ||
| - | gpg --keyserver hkp:// | ||
| - | gpg --verify CHECKSUMS.TXT.gpg CHECKSUMS.TXT | ||
| - | </ | ||
| - | |||
| - | The output should show the line: | ||
| - | < | ||
| - | gpg: Good signature from "DRBL Project (Diskless Remote Boot in Linux) < | ||
| - | </ | ||
| - | |||
| - | You then have verified that the file CHECKSUM.TXT has been encrypted by the owner of the private key of the clonezilla project. | ||
| - | You can then compare the checksum of your file with the content of CHECKSUMS.TXT: | ||
| - | |||
| - | < | ||
| - | sha256sum clonezilla-live-3.2.1-9-amd64.iso | ||
| - | </ | ||
| - | |||
| - | Replace the filename with the actual file you downloaded if it is another version. Check that the output of this command is part of the output of: | ||
| - | |||
| - | < | ||
| - | cat CHECKSUMS.TXT | ||
| - | </ | ||
| - | |||
| - | If so, you are sure to have the right file. You can then proceed to flash you USB key. I recommend using [[balena-etcher|Balena Etcher]], which is Open Source, user friendly and cross platform. | ||
| - | |||
| - | ==== STEP 1.2: prepare the external SSD ==== | ||
| - | |||
| - | You are going to make two partitions on your external SSD: | ||
| - | - __One unencrypted partition__, | ||
| - | - __One encrypted partition__, | ||
| - | |||
| - | - One for the backups of your /home directory (meaning Videos, Photos, Documents, ...) This will be done later with a software called BackinTime | ||
| - | - One for snapshots of your root filesystem (so your programs). This should be done later (but it will not be covered in this tutorial), once you have a stable encrypted system, with a program called Timeshift. | ||
| - | |||
| - | For this you should use the gparted tool, that you can install with: | ||
| - | < | ||
| - | sudo apt install gparted | ||
| - | </ | ||
| - | |||
| - | Launch it: | ||
| - | |||
| - | < | ||
| - | sudo gparted | ||
| - | </ | ||
| - | |||
| - | This will prompt the following screen, where I will take the example of a small 1GB USB key formatting (a USB key behaves the same way as any storage device from a software perspective), | ||
| - | |||
| - | First it will prompt you to the partitioning of your current disk most likely. This is my case, where I have a standard partitioning for full disk encryption: | ||
| - | - One small (500MB for example) unencrypted partition in fat32 for the EFI boot system (/boot/efi) | ||
| - | - One small (500MB for example) unencrypted partition in ext4 for the boot partition (/boot) | ||
| - | - One large (in my case almost 500GB) encrypted partition in etx4 for my whole filesystem | ||
| - | |||
| - | {{ :: | ||
| - | |||
| - | Select the disk you want to partition (beware that **the coming operations will delete all data that you have on this disk**). | ||
| - | |||
| - | {{ :: | ||
| - | |||
| - | {{ :: | ||
| - | To modify the partitions you first need to unmount them | ||
| - | |||
| - | {{ :: | ||
| - | |||
| - | Then you can create a new partition table. There are several type of such partition table, we will choose gpt, which is the most commonly used one. | ||
| - | |||
| - | {{ :: | ||
| - | |||
| - | {{ :: | ||
| - | |||
| - | You can make a new partition now by right clicking on the empty space | ||
| - | |||
| - | {{ :: | ||
| - | Choose the size you want (in this example I take 500MB for each partitions, in your case it could be 700GB and 1300GB) | ||
| - | |||
| - | {{ :: | ||
| - | Repeat the operation for the second partition | ||
| - | {{ :: | ||
| - | |||
| - | {{ :: | ||
| - | click on Apply (the green check mark). **You are warned: all data are going to be lost on this disk**. Click on Apply. | ||
| - | |||
| - | {{ :: | ||
| - | |||
| - | you can then close gparted. Open a terminal and proceed to the encryption of the second partition. You can find its name with the command: | ||
| - | |||
| - | < | ||
| - | lsblk | ||
| - | </ | ||
| - | |||
| - | In my case I get the following output: | ||
| - | < | ||
| - | NAME | ||
| - | sda 8:0 0 465.8G | ||
| - | ├─sda1 | ||
| - | ├─sda2 | ||
| - | └─sda3 | ||
| - | └─disk1 | ||
| - | ├─usera--computer--vg-root | ||
| - | ├─usera--computer--vg-swap_1 254:2 0 | ||
| - | └─usera--computer--vg-home | ||
| - | sdb 8:16 | ||
| - | ├─sdb1 | ||
| - | └─sdb2 | ||
| - | </ | ||
| - | |||
| - | you can see that this command gives more details than gparted, especially since my encrypted disk is decrypted, and you can see the next level, three "sub partitions" | ||
| - | This parenthesis closed, I can identify the partition I want to encrypt: it is called sdb2 (in linux, disks are usually called sda, sdb, sdc..., and partitions in a disk called sda1, sda2, etc.). | ||
| - | |||
| - | To encrypt the second partition, let us install the cryptsetup tool, in case it is not already there on your computer. Open a terminal and enter: | ||
| - | |||
| - | < | ||
| - | sudo apt-get -y install cryptsetup | ||
| - | </ | ||
| - | |||
| - | Then you can proceed with the encryption (careful: if the partition you want to encrypt has another name, change it accordingly): | ||
| - | |||
| - | < | ||
| - | sudo umount /dev/sdb2 | ||
| - | sudo cryptsetup luksFormat /dev/sdb2 | ||
| - | </ | ||
| - | |||
| - | You need to enter ' | ||
| - | < | ||
| - | WARNING: Device /dev/sdb2 already contains a ' | ||
| - | |||
| - | WARNING! | ||
| - | ======== | ||
| - | This will overwrite data on /dev/sdb2 irrevocably. | ||
| - | |||
| - | Are you sure? (Type ' | ||
| - | Enter passphrase for / | ||
| - | Verify passphrase: | ||
| - | </ | ||
| - | |||
| - | After a couple time (a bit more depending on the size of the partition), your partition is now encrypted. | ||
| - | |||
| - | you can now decrypt it with the following command: | ||
| - | |||
| - | < | ||
| - | sudo cryptsetup luksOpen /dev/sdb2 cryptodisk | ||
| - | </ | ||
| - | you will be prompted with your passphrase. Now that your disk is decrypted, you can check that the command: | ||
| - | < | ||
| - | lsblk | ||
| - | </ | ||
| - | gives a different result: | ||
| - | < | ||
| - | NAME | ||
| - | sda 8:0 0 465.8G | ||
| - | ├─sda1 | ||
| - | ├─sda2 | ||
| - | └─sda3 | ||
| - | └─disk1 | ||
| - | ├─usera--computer--vg-root | ||
| - | ├─usera--computer--vg-swap_1 254:2 0 | ||
| - | └─usera--computer--vg-home | ||
| - | sdb 8:16 | ||
| - | ├─sdb1 | ||
| - | └─sdb2 | ||
| - | └─cryptodisk | ||
| - | sr0 | ||
| - | </ | ||
| - | |||
| - | We will now prepare the two "sub partitions" | ||
| - | |||
| - | < | ||
| - | sudo apt install lvm2 | ||
| - | </ | ||
| - | |||
| - | you will need to execute the following commands: | ||
| - | |||
| - | You first create what we call a " | ||
| - | < | ||
| - | sudo pvcreate / | ||
| - | </ | ||
| - | |||
| - | then you create a " | ||
| - | |||
| - | < | ||
| - | sudo vgcreate vgbackup / | ||
| - | </ | ||
| - | |||
| - | Then you create two " | ||
| - | |||
| - | < | ||
| - | sudo lvcreate -L 250M -n root vgbackup | ||
| - | sudo lvcreate -l 100%FREE -n home vgbackup | ||
| - | </ | ||
| - | |||
| - | then you can check again the output of | ||
| - | < | ||
| - | lsblk | ||
| - | </ | ||
| - | You can see that we have the right partitioning: | ||
| - | |||
| - | < | ||
| - | NAME | ||
| - | sda 8:0 0 465.8G | ||
| - | ├─sda1 | ||
| - | ├─sda2 | ||
| - | └─sda3 | ||
| - | └─disk1 | ||
| - | ├─usera--computer--vg-root | ||
| - | ├─usera--computer--vg-swap_1 254:2 0 | ||
| - | └─usera--computer--vg-home | ||
| - | sdb 8:16 | ||
| - | ├─sdb1 | ||
| - | └─sdb2 | ||
| - | └─cryptodisk | ||
| - | ├─vgbackup-root | ||
| - | └─vgbackup-home | ||
| - | sr0 | ||
| - | </ | ||
| - | |||
| - | Then you need to create a "file system" | ||
| - | < | ||
| - | sudo mkfs.ext4 / | ||
| - | sudo mkfs.ext4 / | ||
| - | </ | ||
| - | this formatted those partitions with the filesystem called " | ||
| - | |||
| - | In what we did, there are several levels of partitions that you need to know: | ||
| - | {{ :: | ||
| - | |||
| - | You can then close the LVM: | ||
| - | < | ||
| - | sudo vgchange -an vgbackup | ||
| - | </ | ||
| - | |||
| - | and the luks container: | ||
| - | < | ||
| - | sudo cryptsetup luksClose cryptodisk | ||
| - | </ | ||
| - | |||
| - | |||
| - | ==== STEP 1.3: do the actual backup ==== | ||
| - | |||
| - | you can then follow the [[https:// | ||
| - | |||
| - | Once this is done, you can do another backup of your /home, which contains all your regular files. For this you can use the software backintime. You can install it with: | ||
| - | < | ||
| - | sudo apt install backintime-qt | ||
| - | </ | ||
| - | |||
| - | Before launching it, we need to decrypt the encrypted disk, and mount the logical volume we intend to use: | ||
| - | < | ||
| - | sudo cryptsetup luksOpen /dev/sdb2 cryptsetup | ||
| - | sudo vgchange -ay | ||
| - | sudo mount / | ||
| - | </ | ||
| - | |||
| - | now everything written on /mnt on your computer will be written on your disk. | ||
| - | |||
| - | You can then launch backintime with: | ||
| - | < | ||
| - | sudo backintime-qt | ||
| - | </ | ||
| - | |||
| - | you can then configure it to save things in /mnt: | ||
| - | |||
| - | {{ :: | ||
| - | |||
| - | |||
| - | {{ :: | ||
| - | |||
| - | |||
| - | {{ :: | ||
| - | |||
| - | And then click on "Take snapshot" | ||
| - | |||
| - | {{ :: | ||
| - | |||
| - | you can then unmount and remove your backup disk: | ||
| - | |||
| - | < | ||
| - | sudo umount /mnt | ||
| - | sudo vgchange -an vgbackup | ||
| - | sudo cryptsetup luksClose cryptodisk | ||
| - | </ | ||
| ===== STEP 2: Setup your partitioning ===== | ===== STEP 2: Setup your partitioning ===== | ||
| Line 476: | Line 184: | ||
| Resizing the filesystem on / | Resizing the filesystem on / | ||
| The filesystem on / | The filesystem on / | ||
| + | </ | ||
| + | |||
| + | Now, you need to note down the content of the file / | ||
| + | < | ||
| + | cat / | ||
| </ | </ | ||
| Line 492: | Line 205: | ||
| </ | </ | ||
| - | the prompt will change a bit: you are now an administrator inside your own system! Enter the following command: | + | the prompt will change a bit: you are now an administrator inside your own system! |
| + | Let us first check that we are connected to internet. To do that, you need to try to ping a website: | ||
| + | |||
| + | < | ||
| + | ping google.com | ||
| + | </ | ||
| + | |||
| + | if you see something like this: | ||
| + | < | ||
| + | (base) usera@debian: | ||
| + | PING google.com (142.250.74.78) 56(84) bytes of data. | ||
| + | 64 bytes from arn09s23-in-f14.1e100.net (142.250.74.78): | ||
| + | 64 bytes from arn09s23-in-f14.1e100.net (142.250.74.78): | ||
| + | 64 bytes from arn09s23-in-f14.1e100.net (142.250.74.78): | ||
| + | </ | ||
| + | |||
| + | then you are good to go, you can do CTRL+C to stop it. Otherwise, try copying the content of the / | ||
| + | |||
| + | < | ||
| + | nano / | ||
| + | </ | ||
| + | then paste the content, and enter CTRL+X, then Y do save the changes. Try again to ping: | ||
| + | |||
| + | < | ||
| + | ping google.com | ||
| + | </ | ||
| + | |||
| + | It should work now. | ||
| + | |||
| + | Now, install some required packages: | ||
| + | < | ||
| + | sudo apt install cryptsetup cryptsetup-initramfs | ||
| + | </ | ||
| + | |||
| + | and let us do some modifications. | ||
| + | Enter the following command: | ||
| < | < | ||
| Line 536: | Line 284: | ||
| / | / | ||
| </ | </ | ||
| + | |||
| + | you need finally to modify the file / | ||
| + | < | ||
| + | nano / | ||
| + | </ | ||
| + | |||
| + | you need to locate the entry " | ||
| + | where you change <LUKS partition UUID> for the UUID of your encrypted partition. | ||
| + | You can then enter: | ||
| + | |||
| + | < | ||
| + | sudo update-initramfs -u | ||
| + | </ | ||
| + | |||
| + | and then: | ||
| + | |||
| + | < | ||
| + | update-grub | ||
| + | </ | ||
| + | |||
| + | and finally the following commands: | ||
| + | |||
| + | < | ||
| + | exit | ||
| + | sudo shutdown -r now | ||
| + | </ | ||
| + | |||
| + | you will then remove your USB key and boot in your encrypted system hopefully. You should see a prompt asking to unlock your disk, and then your familiar OS will boot, with all the configuration you previously had. Congratulations ! | ||
reencrypt_linux_post_install.1746297631.txt.gz · Last modified: by usera
