Rootfs encryption/fr

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Rootfs encryption and the translation is 27% complete.
Outdated translations are marked like this.
Other languages:

Chiffrer le système de fichier principal peut améliorer la sécurité et éviter des accès non autorisés.

Emerge

Remarque
cryptsetup is included in the livecd.
root #emerge --ask sys-fs/cryptsetup

System preparation

Important
Le kernel doit être configuré comme indiqué dans Dm-crypt: Kernel Configuration.

This guide is designed to be followed as part of a fresh Gentoo install, the install procedure can be followed until the following step: AMD64 Handbook: Designing a partition scheme

Disk preparation

Important
Partitioning typically does not involve modification of any of the data in partitions. If a drive is re-partitioned then encrypted, old data may remain in an unencrypted form until it is overwritten.
Remarque
Modern storage devices may not be securely erased with something like dd if=/dev/urandom of=/dev/sdX. See Secure wipe for more information.

This example will use GPT as disk partition schema. fdisk will be used as the partitioning tool though any partitioning utility will work.

See also
For more information about GPT and EFI, see Disks (AMD64 Handbook).

Create disk partitions

A common setup for a basic system with a single drive may contain a partition for the boot files, and a partition for the system root.

CODE
/dev/nvme0n1
 ├── /dev/nvme0n1p1 [EFI]       /boot      1 GB         fat32       Bootloader, bootloader support files, kernel and initramfs
 └── /dev/nvme0n1p2 [LUKS]      (crypt)    ->END        luks        encrypted partition
      └──  rootfs               /          ->END        btrfs       root partition

Create partitions

To create a partition layout using fdisk, start by creating a fresh partition table on the root disk:

root #fdisk /dev/nvme0n1
 
Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x81391dbc.
Command (m for help):g
Created a new GPT disklabel (GUID: 8D91A3C1-8661-2940-9076-65B815B36906).

With a GPT partition table created, the boot partition can be added using n:

Command (m for help):n
Partition number (1-128, default 1): 
First sector (2048-1953525134, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1953525134, default 1953523711): +1G
 
Created a new partition 1 of type 'Linux filesystem' and of size 1 GiB.

The ESP properties can be set using t:

Command (m for help):t
Selected partition 1
Partition type or alias (type L to list all): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.

The root partition can be crated with:

Command (m for help):n
Partition number (1-128, default 2): 
First sector (1050624-1953525134, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-1953525134, default 1953523711):
 
Created a new partition 2 of type 'Linux filesystem' and of size 931 GiB.

Finally, the changes can be written with w:

Command (m for help):w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Create the LUKS encrypted partition

Pour préparer le système de fichier chiffré, dm-crypt peut être utilisé :

Remarque
To ensure the dm-crypt module is loaded, the following command can be used:
root #modprobe dm-crypt

The status of the module can be checked with:

user $lsmod | grep dm-crypt

To format the root partition using LUKS, secured with a passphrase:

root #cryptsetup luksFormat --key-size 512 /dev/nvme0n1p2
 
WARNING!
========
This will overwrite data on /dev/nvme0n1p2 irrevocably.
 
Are you sure? (Type 'yes' in capital letters): 
YES
Enter passphrase for /dev/nvme0n1p2:

LUKS Header Backup

Important
Do not forget this step, keys/passwords are used to decrypt the LUKS header, if it is destroyed for some reason, the remaining data will only be recoverable with the header file.

The headers can be backed up with:

root #cryptsetup luksHeaderBackup /dev/nvme0n1p2 --header-backup-file crypt_headers.img

Open the LUKS volume

The encrypted device must be opened and mapped before it can be used, this can be done with:

root #cryptsetup luksOpen /dev/nvme0n1p2 crypt
Remarque
In this example, the volume is opened and mapped to /dev/mapper/crypt.

Format the Filesystems

Créer un système de fichier pour /dev/nvme0n1p1, la partition de boot contiendra le bootloader et les fichiers kernel. Cette partition est lue par UEFI. La plupart des cartes mères ne supportent que les systèmes de fichiers FAT32 :

root #mkfs.vfat -F32 /dev/nvme0n1p1

Next create root filesystem (in this example btrfs is used):

root #mkfs.btrfs -L rootfs /dev/mapper/crypt

Gentoo installation

If this procedure is being followed during a Gentoo install (in place of Handbook:AMD64/Full/Installation through Handbook:AMD64/Full/Installation), the following steps can be used to mount the created partition, to continue with the install.

Monter la partition racine

Le système de fichier principal peut être monté à ce nouvel endroit avec :

root #mount LABEL=rootfs /mnt/gentoo

Finaliser l'installation de gentoo

Important
Le guide d'installation standard devrait fonctionner. Quelques considérations doivent être prises, le système de fichier initial doit être créé avec le support du déchiffrement de la partition principale et le bootloader doit être installé et configuré.

A ce stade, l'installation de Gentoo peut être continuée normalement : Installation d'une archive tar


Configuration fstab

Important
Le bon fichier /etc/fstab doit être édité, si c'est fait avant d'entrer en chroot, assurez vous que le bon chemin est utilisé. Plus d'information peuvent être trouvées dans la partie More information exists in système de fichier du guide d'installation.

Pour un montage des volumes consistants, les labels et les UUIDs doivent être utilisés.

Les périphériques blocs et les IDs de partition associés peuvent être affichés avec :

root #lsblk -o name,uuid
NAME        UUID
sdb                                           
├─nvme0n1p1 BDF2-0139
└─nvme0n1p2 4bb45bd6-9ed9-44b3-b547-b411079f043b
  └─crypt   cb070f9e-da0e-4bc5-825c-b01bb2707704

En fois les UUIDs et les labels identifiés, le fichier /etc/fstab peut être édité pour ajouter les montages intéressants :

FILE /mnt/gentoo/etc/fstab
'"`UNIQ--pre-0000000C-QINU`"'

Initramfs configuration

Un initramfs doit être utilisé pour déchiffrer et monter la partition principale. Cela peut être fait en utilisant Dracut et en définissant les bonnes options dans la ligne de commande kernel.

Important
This configuration should be done while chrooted, or on a live system.

Les modules suivant doivent être ajoutés dans la configuration add_dracutmodules dans le fichier /etc/dracut.conf

FILE /etc/dracut.confMinimum required components to decrypt LUKS volumes using dracut
add_dracutmodules+=" crypt dm rootfs-block "
Important
Les espaces pour les différentes configurations Dracut sont très importants. Assurez vous qu'il n'y a pas d'espaces entre add_dracutmodules et +=" et que les paramètres dans add_dracutmodules sont bien entourés d'espaces.

Dracut can be configured to build with configuration for LUKS hardcoded, first disk information must be obtained:

root #lsblk -o name,uuid
NAME        UUID
sda
└─sda1      BDF2-0139
nvme0n1
└─nvme0n1p1 4bb45bd6-9ed9-44b3-b547-b411079f043b
  └─crypt   cb070f9e-da0e-4bc5-825c-b01bb2707704
FILE /etc/dracut.confEmbed cmdline parameters for rootfs decryption
kernel_cmdline+=" root=UUID=cb070f9e-da0e-4bc5-825c-b01bb2707704 rd.luks.uuid=4bb45bd6-9ed9-44b3-b547-b411079f043b "
Remarque
Compiler l'option root= dans le kernel est nécessaire lorsque vous utilisez sys-boot/systemd-boot, mais redondant si vous utilisez GRUB's car grub-mkconfig va automatiquement ajouter ce paramètre.

Si systemd est utilisé comme système d'initialisation, il doit être compilé avec le USE-flag cryptsetup :

FILE /etc/portage/package.use/systemd
sys-apps/systemd cryptsetup

And rebuild systemd:

root #emerge --ask sys-apps/systemd

Once Dracut is configured, a new initramfs can be generated by running:

root #dracut
Important
Dracut writes the file to /boot by default, this must be mounted.

Si le système de fichiers virtuel initial doit être généré pour un autre que celui actuellement actif, l'option --kver doit être utilisé :

root #dracut --kver 6.1.28-gentoo

Cela peut se produire lorsque la version du kernel dans le Live CD Gentoo est différente de celle installé par sys-kernel/gentoo-sources lors de la compilation du kernel.

Conseil
Possible kernel versions can be found by using ls /lib/modules.

Voir aussi

  • Dm-crypt — un système de chiffrement de disque utilisant le framework de l'API cryptographique du noyau et le sous-système de mapping des périphériques.
  • Dm-crypt full disk encryption — discusses several aspects of using dm-crypt for (full) disk encryption.