dm-crypt/システム全体の暗号化

提供: ArchWiki
2016年1月20日 (水) 16:13時点におけるKusakata (トーク | 投稿記録)による版 (同期)
ナビゲーションに移動 検索に移動

dm-crypt に戻る。

以下は dm-crypt を使って完全なシステム暗号化を行う一般的なシナリオの例です。通常のインストール手順に加える必要がある変更を全て説明しています。必要なツールは全て インストールイメージ に入っています。

概要

root ファイルシステムの暗号化については機能やパフォーマンスの点で dm-crypt が優れています。システムの root ファイルシステムが dm-crypt デバイス上にあれば、システム上のほとんど全てのファイルが暗号化されます。root 以外のファイルシステムを選択的に暗号化するのと異なり、root ファイルシステムの暗号化は様々な情報を隠匿できます。インストールされているプログラム、ユーザーアカウントのユーザー名、mlocate/var/log/ など媒介してデータ漏洩の恐れがあるファイルなど。さらに、root ファイルシステムを暗号化することでシステムの改竄が非常に難しくなります。ブートローダーやカーネルを除く全てが暗号化されるためです。

以上の利点をのぞく、それぞれのシナリオのメリットやデメリットなどの違いをまとめて、全てのシナリオを以下の表で説明します:

シナリオ メリット デメリット
#LUKS を使用するシンプルなパーティションレイアウト

LUKS で root を完全に暗号化するベーシックなセットアップ

  • パーティショニングと設定がシンプル
  • 柔軟性がない、暗号化するディスク領域をあらかじめ指定する必要がある
#LVM on LUKS

LUKS 暗号化パーティションの中で LVM を使うことでパーティショニングの柔軟性を確保

  • Simple partitioning with knowledge of LVM
  • Only one key required to unlock all volumes (e.g. easy resume-from-disk setup)
  • Volume layout not transparent when locked
  • ハイバネートを利用したいときの一番簡単な方法
  • LVM adds an additional mapping layer and hook
  • Less useful, if a singular volume should receive a separate key
#LUKS on LVM

LVM をセットアップした後に dm-crypt を使用

  • LVM can be used to have encrypted volumes span multiple disks
  • Easy mix of un-/encrypted volume groups
  • Complex; changing volumes requires changing encryption mappers too
  • Volumes require individual keys
  • LVM layout is transparent when locked
#Plain dm-crypt

dm-crypt の plain モードを使用、LUKS ヘッダーや LUKS の複数のキーのオプションは使わない
このシナリオでは /boot とキーストレージに USB デバイスを使いますが、これは他のデバイスでも利用可能です

  • Data resilience for cases where a LUKS header may be damaged
  • 否認可能暗号が使える
  • High care to all encryption parameters is required
  • Single encryption key and no option to change it
#boot パーティションの暗号化 (GRUB)

GRUB ブートローダーを使って boot パーティションを暗号化する方法を説明します。
このシナリオでは ESP パーティションを使いますが、他のシナリオでも ESP を使うことができます。

  • Same advantages as the scenario the installation is based on (LVM on LUKS for this particular example)
  • Less data is left unencrypted, i.e. the boot loader and the ESP partition, if present
  • Same disadvantages as the scenario the installation is based on (LVM on LUKS for this particular example)
  • More complicated configuration
  • Not supported by other boot loaders

上記全てのシナリオが外部からの脅威に対して十分な保護を約束しますが、共通の欠点も存在します。暗号化キーを持っているユーザーなら誰でもデバイスの全てを復号化して、他のユーザーのデータにもアクセスすることが可能という点です。これが問題だという場合は、ブロックデバイスの暗号化とスタックファイルシステムの暗号化と組み合わせて使用することで、両者の利点を取り入れることができます。ディスク暗号化を見て下さい。

他にも、スワップパーティションの暗号化を設定するべきかどうか考慮する必要があります。Dm-crypt/スワップの暗号化を見て下さい。

シナリオで使用されているパーティショニングの外観について Dm-crypt/ドライブの準備#パーティショニング も参照してください。

LUKS を使用するシンプルなパーティションレイアウト

この例ではシンプルなパーティションレイアウトによる 'dmcrypt+ LUKS のフルシステム暗号化を説明します:

+--------------------+--------------------------+--------------------------+
|Boot partition      |LUKS encrypted system     |Optional free space       |
|                    |partition                 |for additional partitions |
|/dev/sdaY           |/dev/sdaX                 |or swap to be setup later |
+--------------------+--------------------------+--------------------------+

最初のステップは Arch Linux のインストールイメージを起動した後すぐに実行します。

ディスクの準備

パーティションを作成する前に、Dm-crypt/ドライブの準備 で説明されているように、ディスクを完全に消去する必要性・方法を学んでください。

それから必要なパーティションを作成します。最低でも / が必要です (例: /dev/sdaX) と /boot (/dev/sdaY)。パーティショニングを参照。

boot 以外のパーティションの準備

以下のコマンドは暗号化された root パーティションを作成・マウントします。Dm-crypt/root 以外のファイルシステムの暗号化#パーティション に詳しく説明されている手順に該当します (ページタイトルと相違して、mkinitcpioブートローダーが正しく設定されていれば、root パーティションにも適用できます)。デフォルトになってない特定の暗号化オプションを使いたいときは (例: 暗号アルゴリズムや鍵長など)、最初のコマンドを実行する前に暗号化オプションを読んでください:

# cryptsetup -y -v luksFormat /dev/sdaX
# cryptsetup open /dev/sdaX cryptroot
# mkfs -t ext4 /dev/mapper/cryptroot
# mount -t ext4 /dev/mapper/cryptroot /mnt

マッピングが問題ないかチェック:

# umount /mnt
# cryptsetup close cryptroot
# cryptsetup open /dev/sdaX cryptroot
# mount -t ext4 /dev/mapper/cryptroot /mnt

パーティションを分割した場合 (例: /home)、以上のコマンドを全てのパーティションに繰り返し実行してください。ただし /boot は別です。起動時に追加のパーティションを扱う方法は Dm-crypt/root 以外のファイルシステムの暗号化#ロック解除とマウントの自動化 を見て下さい。

それぞれのブロックデバイスには個々のパスフレーズが必要になります。起動時に、別々のパスフレーズを入力しないといけないので、不便とも言えます。crypttab を使うことでシステムパーティションにキーファイルを保存して使用することで別のパーティションを解錠することができます。方法は Dm-crypt/デバイスの暗号化#LUKS を使ってキーファイルでパーティションをフォーマット を見て下さい。

boot パーティションの準備

セットアップする必要があるのは暗号化されない /boot パーティションで、暗号化する root に必要となります。例えば、標準的な MBR/BIOS/boot パーティションの場合、以下を実行します:

# mkfs -t ext4 /dev/sdaY
# mkdir /mnt/boot
# mount -t ext4 /dev/sdaY /mnt/boot

デバイスのマウント

インストールガイド#パーティションのマウントでは実際のパーティションではなく、マップされたデバイスをマウントしてください。もちろん、/boot は暗号化されていないので、直接マウントします。

mkinitcpio の設定

encrypt フックを mkinitcpio.conf 内の filesystems の前に追加します:

etc/mkinitcpio.conf
HOOKS="... encrypt ... filesystems ..."

他に必要なフックについては dm-crypt/システム設定#mkinitcpio を見て下さい。

設定後はイメージを再生成してください:

# mkinitcpio -p linux

ブートローダーの設定

暗号化された root パーティションを起動するには、ブートローダーに以下のカーネルパラメータを設定する必要があります (<device-UUID>/dev/sdaX の UUID に置き換えてください。詳しくは永続的なブロックデバイスの命名を参照):

cryptdevice=UUID=<device-UUID>:cryptroot root=/dev/mapper/cryptroot

他に必要なパラメータについては Dm-crypt/システム設定#ブートローダー を見て下さい。

LVM on LUKS

The straight-forward method is to set up LVM on top of the encrypted partition instead of the other way round. Technically the LVM is setup inside one big encrypted blockdevice. Hence, the LVM is not transparent until the blockdevice is unlocked and the underlying volume structure is scanned and mounted during boot.

The disk layout in this example is:

+-----------------------------------------------------------------------+ +----------------+
| Logical volume1       | Logical volume2       | Logical volume3       | |                |
|/dev/MyStorage/swapvol |/dev/MyStorage/rootvol |/dev/MyStorage/homevol | | Boot partition |
|_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _| | (may be on     |
|                                                                       | | other device)  |
|                        LUKS encrypted partition                       | |                |
|                          /dev/sdaX                                    | | /dev/sdbY      |
+-----------------------------------------------------------------------+ +----------------+

This method does not allow you to span the logical volumes over multiple disks, even in the future. The #LUKS on LVM method does not have this limitation.

ヒント: Two variants of this setup:

ディスクの準備

パーティションを作成する前に、Dm-crypt/ドライブの準備 で説明されているように、ディスクを完全に消去する必要性・方法を学んでください。

GPTGRUB ブートローダーを使う時は、GRUB#BIOS システム で説明されているように BIOS Boot Partition を作成してください。

Create a partition to be mounted at /boot of type 8300 with a size of 100 MB or more.

Create a partition of type 8E00, which will later contain the encrypted container.

Create the LUKS encrypted container at the "system" partition. Enter the chosen password twice.

# cryptsetup luksFormat /dev/sdaX

cryptsetup のオプションについては LUKS 暗号化のオプションを見て下さい。

Open the container:

# cryptsetup open --type luks /dev/sdaX lvm

The decrypted container is now available at /dev/mapper/lvm.

論理ボリュームの準備

Create a physical volume on top of the opened LUKS container:

# pvcreate /dev/mapper/lvm

MyStorage という名前のボリュームグループを作成して、先に作成した物理ボリュームを追加:

# vgcreate MyStorage /dev/mapper/lvm

ボリュームグループに論理ボリュームを作成:

# lvcreate -L 8G MyStorage -n swapvol
# lvcreate -L 15G MyStorage -n rootvol
# lvcreate -l +100%FREE MyStorage -n homevol

論理ボリュームのファイルシステムをフォーマット:

# mkfs.ext4 /dev/mapper/MyStorage-rootvol
# mkfs.ext4 /dev/mapper/MyStorage-homevol
# mkswap /dev/mapper/MyStorage-swapvol

ファイルシステムをマウント:

# mount /dev/MyStorage/rootvol /mnt
# mkdir /mnt/home
# mount /dev/MyStorage/homevol /mnt/home
# swapon /dev/MyStorage/swapvol

boot パーティションの準備

The bootloader loads the kernel, initramfs, and its own configuration files from the /boot directory. This directory must be located on a separate unencrypted filesystem.

/boot にするパーティションに Ext2 ファイルシステムを作成します。ブートローダーが読み込めるファイルシステムなら何でもかまいません。

# mkfs.ext2 /dev/sdbY

/mnt/boot ディレクトリを作成:

# mkdir /mnt/boot

パーティションを /mnt/boot にマウント:

# mount /dev/sdbY /mnt/boot

Aftwards continue with the installation procedure up to the mkinitcpio step.

mkinitcpio の設定

encryptlvm2 フックを mkinitcpio.conf 内の filesystems の前に追加します:

/etc/mkinitcpio.conf
HOOKS="... encrypt lvm2 ... filesystems ..."
ノート: The order of both hooks no longer matters with the current implementation of lvm2.

他に必要なフックについては dm-crypt/システム設定#mkinitcpio を見て下さい。

設定後はイメージを再生成してください:

# mkinitcpio -p linux

ブートローダーの設定

起動時に暗号化された root パーティションの暗号化が解除されるように、以下のカーネルパラメータをブートローダーで設定します (<device-UUID>/dev/sdaX の UUID に置き換えてください。詳しくは永続的なブロックデバイスの命名を参照):

cryptdevice=UUID=<device-UUID>:MyStorage root=/dev/mapper/MyStorage-rootvol

詳しくは Dm-crypt/システム設定#ブートローダー を見て下さい。

LUKS on LVM

LVM 上で暗号化を利用するには、まず LVM ボリュームをセットアップして、それから暗号化パーティションのベースとして使うことになります。この方法では、暗号化パーティションと非暗号化パーティションのミックスが可能です。#LVM on LUKS とは違って、複数のディスクにまたがるような通常の論理ボリュームは使えません。

The following short example creates a LUKS on LVM setup and mixes in the use of a key-file for the /home partition and temporary crypt volumes for /tmp and /swap. The latter is considered desirable from a security perspective, because no potentially sensitive temporary data survives the reboot, when the encryption is re-initialised. If you are experienced with LVM, you will be able to ignore/replace LVM and other specifics according to your plan. If you want to span a logical volume over multiple disks during setup already, a procedure to do so is described in Dm-crypt/特記事項#LVM を複数のディスクに拡張.

ディスクの準備

Partitioning scheme:

  • /dev/sda1 -> /boot
  • /dev/sda2 -> LVM

Dm-crypt/ドライブの準備#インストール前に dm-crypt で消去を見て /dev/sda2 をランダム化してください。

論理ボリュームの準備

# lvm pvcreate /dev/sda2
# lvm vgcreate lvm /dev/sda2
# lvm lvcreate -L 10G -n lvroot lvm
# lvm lvcreate -L 500M -n swap lvm
# lvm lvcreate -L 500M -n tmp lvm
# lvm lvcreate -l 100%FREE -n home lvm
# cryptsetup luksFormat -c aes-xts-plain64 -s 512 /dev/lvm/lvroot
# cryptsetup open --type luks /dev/lvm/lvroot root
# mkfs -t ext4 /dev/mapper/root
# mount /dev/mapper/root /mnt

Note that /home will be encrypted later in this example. Further, note that if you ever have to access the encrypted root from the Arch-ISO, the above open action will allow you to after the LVM shows up.

boot パーティションの準備

# dd if=/dev/zero of=/dev/sda1 bs=1M
# mkfs -t ext4 /dev/sda1
# mkdir /mnt/boot
# mount /dev/sda1 /mnt/boot

Now after setup of the encrypted LVM partitioning, it would be time to install: Arch Install Scripts.

mkinitcpio の設定

encryptlvm2 フックを mkinitcpio.conf 内の filesystems の前に追加します:

etc/mkinitcpio.conf
HOOKS="... block ''encrypt lvm2 ... filesystems ..."

他に必要なフックについては dm-crypt/システム設定#mkinitcpio を見て下さい。

設定ファイルを変更した後は次のコマンドを root 権限で実行してください:

# mkinitcpio -p linux

ブートローダーの設定

上の例の場合、ブートローダーの設定で root デバイスのカーネルオプションを以下のように変更します:

cryptdevice=/dev/lvm/lvroot:cryptoroot root=/dev/mapper/cryptoroot

詳しくは Dm-crypt/システム設定#ブートローダー を見て下さい。

fstab と crypttab の設定

/etc/fstab
 /dev/mapper/root        /       ext4            defaults        0       1
 /dev/sda1               /boot   ext4            defaults        0       2
 /dev/mapper/tmp         /tmp    tmpfs           defaults        0       0
 /dev/mapper/swap        none    swap            sw              0       0

以下の crypttab オプションは再起動するたびに一時ファイルシステムを暗号化します:

/etc/crypttab
 swap	/dev/lvm/swap	/dev/urandom	swap,cipher=aes-xts-plain64,size=256
 tmp	/dev/lvm/tmp	/dev/urandom	tmp,cipher=aes-xts-plain64,size=256

論理ボリューム /home の暗号化

Since this scenario uses LVM as the primary and dm-crypt as secondary mapper, each encrypted logical volume requires its own encryption. Yet, unlike the temporary filesystems configured with volatile encryption above, the logical volume for /home should be persistent, of course. The following assumes you have rebooted into the installed system, otherwise you have to adjust paths. To safe on entering a second passphrase at boot for it, a keyfile is created:

mkdir -m 700 /etc/luks-keys
dd if=/dev/random of=/etc/luks-keys/home bs=1 count=256

論理ボリュームは以下のように暗号化します:

cryptsetup luksFormat -v -s 512 /dev/lvm/home /etc/luks-keys/home
cryptsetup -d /etc/luks-keys/home open --type luks /dev/lvm/home home
mkfs -t ext4 /dev/mapper/home
mount /dev/mapper/home /home

暗号化されたマウントは crypttab で設定します:

/etc/crypttab
home	/dev/lvm/home   /etc/luks-keys/home
/etc/fstab
/dev/mapper/home        /home   ext4        defaults        0       2

これでセットアップは完了です。 and setup is done.

If you want to expand the logical volume for /home (or any other volume) at a later point, it is important to note that the LUKS encrypted part has to be resized as well. For a procedure see Dm-crypt/特記事項#LVM を複数のディスクに拡張.

Plain dm-crypt

This scenario sets up a system on a dm-crypt a full disk with plain mode encryption. Note that for most use cases, the methods using LUKS described above are the better options for both system encryption and encrypted partitions. LUKS features like key management with multiple pass-phrases/key-files are unavailable with plain mode.

dm-crypt plain mode does not require a header on the encrypted disk: this means that an unpartitioned, encrypted disk will be indistinguishable from a disk filled with random data, which is the desired attribute for this scenario, see also Wikipedia:Deniable encryption.

Plain dm-crypt encrypted disks can be more resilient to damage than LUKS encrypted disks, because it does not rely on an encryption master-key which can be a single-point of failure if damaged. However, using plain mode also requires more manual configuration of encryption options to achieve the same cryptographic strength. See also ディスク暗号化#暗号メタデータ.

ヒント: If headerless encryption is your goal but you are unsure about the lack of key-derivation with plain mode, then two alternatives are:
  • tcplay which offers headerless encryption but with the PBKDF2 function, or
  • dm-crypt LUKS mode by using the cryptsetup --header option. It cannot be used with the standard encrypt hook, but the hook may be modified.

The scenario uses a USB stick for the boot device and another one to store the encryption key. The disk layout is:

|--------------------+------------------+--------------------+ +---------------+ +---------------+
|Volume 1:           |Volume 2:         |Volume 3:           | |Boot device    | |Encryption key |
|                    |                  |                    | |               | |file storage   |
|root                |swap              |home                | |/boot          | |(unpartitioned |
|                    |                  |                    | |               | |in example)    |
|/dev/store/root     |/dev/store/swap   |/dev/store/home     | |/dev/sdY1      | |/dev/sdZ       |
|--------------------+------------------+--------------------| |---------------| |---------------|
|disk drive /dev/sdaX encrypted using plain mode and LVM     | |USB stick 1    | |USB stick 2    |
+------------------------------------------------------------+ +---------------+ +---------------+

/boot and the boot loader cannot be kept on the encrypted drive, or it will defeat the purpose of using plain mode for deniable encryption. This also allows storing the options required to open/unlock the plain encrypted device in the boot loader configuration, since typing them on each boot would be error prone.

This scenario also uses a key file, assuming it stored as raw bits on a second USB stick, so that to the eyes of an unaware attacker who might get the usbkey the encryption key will appear as random data instead of being visible as a normal file. See also Wikipedia:Security through obscurity, follow Dm-crypt/デバイスの暗号化#キーファイル to prepare the keyfile.

ヒント:
  • It is also possible to use a single usb key by copying the keyfile to the initram directly. An example keyfile /etc/keyfile gets copied to the initram image by setting FILES="/etc/keyfile" in /etc/mkinitcpio.conf. The way to instruct the encrypt hook to read the keyfile in the initram image is using rootfs: prefix before the filename, e.g. cryptkey=rootfs:/etc/keyfile.
  • Another option is using a passphrase with good entropy.

ディスクの準備

It is vital that the mapped device is filled with data. In particular this applies to the scenario usecase we apply here.

Dm-crypt/ドライブの準備Dm-crypt/ドライブの準備#dm-crypt 固有の方法 を見て下さい。

boot 以外のパーティションの準備

詳しくは Dm-crypt/デバイスの暗号化#plain モードの暗号化オプション を参照。

Using the device /dev/sdX, with the twofish-xts cipher with a 512 bit key size and using a keyfile we have the following options for this scenario:

# cryptsetup --hash=sha512 --cipher=twofish-xts-plain64 --offset=0 --key-file=/dev/sdZ --key-size=512 open --type=plain /dev/sdX enc

Unlike encrypting with LUKS, the above command must be executed in full whenever the mapping needs to be re-established, so it is important to remember the cipher, hash and key file details.

We can now check a mapping entry has been made for /dev/mapper/enc:

# fdisk -l

Next, we setup LVM logical volumes on the mapped device, see LVM#Arch Linux を LVM にインストールする for further details:

# pvcreate /dev/mapper/enc
# vgcreate store /dev/mapper/enc
# lvcreate -L 20G store -n root
# lvcreate -L 10G store -n swap
# lvcreate -l +100%FREE store -n home

論理ボリュームをフォーマットしてマウントします。詳しくはファイルシステム#デバイスのフォーマットを見て下さい

# mkfs.ext4 /dev/store/root
# mkfs.ext4 /dev/store/home
# mount /dev/store/root /mnt
# mkdir /mnt/home
# mount /dev/store/home /mnt/home
# mkswap /dev/store/swap
# swapon /dev/store/swap

boot パーティションの準備

The /boot partition can be installed on the standard vfat partition of a USB stick, if required. But if manual partitioning is needed, then a small 200MB partition is all that is required. Create the partition using a partitioning tool of your choice.

We choose a non-journalling file system to preserve the flash memory of the /boot partition, if not already formatted as vfat:

# mkfs.ext2 /dev/sdY1
# mkdir /mnt/boot
# mount /dev/sdY1 /mnt/boot

mkinitcpio の設定

encryptlvm2 フックを mkinitcpio.conf 内の filesystems の前に追加します:

etc/mkinitcpio.conf
HOOKS="... encrypt lvm2 ... filesystems ..."

他に必要なフックについては dm-crypt/システム設定#mkinitcpio を見て下さい。

設定後はイメージを再生成してください:

# mkinitcpio -p linux

ブートローダーの設定

暗号化した root パーティションを起動するには、以下のカーネルパラメータをブートローダーで設定する必要があります:

cryptdevice=/dev/sdX:enc cryptkey=/dev/sdZ:0:512 crypto=sha512:twofish-xts-plain64:512:0:

他に必要なパラメータについては Dm-crypt/システム設定#ブートローダー を見て下さい。

ヒント: GRUB を使用する場合、次のコマンドを使うことで /boot パーティションと同じ USB にインストールすることができます:
# grub-install --recheck /dev/sdY

インストール後

You may wish to remove the USB sticks after booting. Since the /boot partition is not usually needed, the noauto option can be added to the relevant line in /etc/fstab:

/etc/fstab
# /dev/sdYn
/dev/sdYn /boot ext2 noauto,rw,noatime 0 2

However, when an update to the kernel or bootloader is required, the /boot partition must be present and mounted. As the entry in fstab already exists, it can be mounted simply with:

# mount /boot

boot パーティションの暗号化 (GRUB)

This setup utilizes the same partition layout and configuration for the system's root partition as the previous #LVM on LUKS section, with two distinct differences:

  1. The setup is performed for an UEFI system and
  2. A special feature of the GRUB bootloader is used to additionally encrypt the boot partition /boot. See also GRUB#Boot partition.

The disk layout in this example is:

+---------------+----------------+----------------+----------------+----------------+
|ESP partition: |Boot partition: |Volume 1:       |Volume 2:       |Volume 3:       |
|               |                |                |                |                |
|/boot/efi      |/boot           |root            |swap            |home            |
|               |                |                |                |                |
|               |                |/dev/store/root |/dev/store/swap |/dev/store/home |
|/dev/sdaX      |/dev/sdaY       +----------------+----------------+----------------+
|unencrypted    |LUKS encrypted  |/dev/sdaZ encrypted using LVM on LUKS             |
+---------------+----------------+--------------------------------------------------+
ヒント: All scenarios are intended as examples. It is, of course, possible to apply both of the two above distinct installation steps with the other scenarios as well. See also the variants linked in #LVM on LUKS.

ディスクの準備

Prior to creating any partitions, you should inform yourself about the importance and methods to securely erase the disk, described in Dm-crypt/ドライブの準備.

Create an EFI System Partition (ESP) with an appropriate size, it will later be mounted at /boot/efi.

Create a partition to be mounted at /boot of type 8300 with a size of 100 MB or more.

ヒント: When using the GRUB bootloader together with a BIOS/GPT, create a BIOS Boot Partition as explained in GRUB#BIOS システム instead of the ESP.

Create a partition of type 8E00, which will later contain the encrypted container.

Create the LUKS encrypted container at the "system" partition.

# cryptsetup luksFormat /dev/sdaZ

For more information about the available cryptsetup options see the LUKS encryption options prior to above command.

Your partition layout should look similar to this:

 gdisk /dev/sda 
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1050623   512.0 MiB   EF00  EFI System
   2         1050624         1460223   200.0 MiB   8300  Linux filesystem
   3         1460224        41943006   19.3 GiB    8E00  Linux LVM

コンテナを開く:

# cryptsetup open --type luks /dev/sdaZ lvm

The decrypted container is now available at /dev/mapper/lvm.

論理ボリュームの準備

The LVM logical volumes of this example follow the exact layout as the previous scenario. Therefore, please follow Preparing the logical volumes above or adjust as required.

boot パーティションの準備

ブートローダーは /boot ディレクトリからカーネルや initramfs、あるいはブートローダーの設定ファイルをロードします。

First, create the LUKS container where the files will be located and installed into:

# cryptsetup luksFormat /dev/sdaY 

Next, open it:

# cryptsetup open /dev/sdaY cryptboot 

/boot にするパーティションにファイルシステムを作成。ブートローダーから読み込めるならどんなファイルシステムでもかまいません:

# mkfs.ext2 /dev/mapper/cryptboot

/mnt/boot ディレクトリを作成:

# mkdir /mnt/boot

パーティションを /mnt/boot にマウント:

# mount /dev/mapper/cryptboot /mnt/boot

Create a mountpoint for the ESP at /boot/efi for compatibility with grub-install and mount it:

# mkdir /mnt/boot/efi
# mount /dev/sdaX /mnt/boot/efi

At this point, you should have the following partitions and logical volumes inside of /mnt:

lsblk
NAME              	  MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                       8:0      0   200G  0 disk  
├─sda1                    8:1      0   512M  0 part  /boot/efi
├─sda2                    8:2      0   200M  0 part  
│ └─boot		  254:0    0   198M  0 crypt /boot
└─sda3                    8:3      0   100G  0 part  
  └─lvm                   254:1    0   100G  0 crypt 
    ├─MyStorage-swapvol   254:2    0     8G  0 lvm   [SWAP]
    ├─MyStorage-rootvol   254:3    0    15G  0 lvm   /
    └─MyStorage-homevol   254:4    0    77G  0 lvm   /home

Afterwards continue with the installation procedure up to the mkinitcpio step.

mkinitcpio の設定

mkinitcpio.confencryptlvm2 フックを追加:

/etc/mkinitcpio.conf
HOOKS="... encrypt lvm2 ... filesystems ..."

詳細や必要な他のフックについては dm-crypt/システム設定#mkinitcpio を参照。


設定後はイメージを再生成してください:

# mkinitcpio -p linux

ブートローダーの設定

起動時に暗号化された root パーティションの暗号化が解除されるように、以下のカーネルパラメータをブートローダーで設定します (<device-UUID>/dev/sdaX の UUID に置き換えてください。詳しくは永続的なブロックデバイスの命名を参照):

cryptdevice=UUID=<device-UUID>:MyStorage root=/dev/mapper/MyStorage-rootvol

詳しくは Dm-crypt/システム設定#ブートローダー を参照。

それから GRUB ブートローダーをインストールして LUKS で暗号化された /boot パーティションを認識させます。GRUB#Boot パーティションを参照。

/etc/default/grub を開いてパラメーターを末端に追加:

GRUB_ENABLE_CRYPTODISK=y

GRUB メニュー設定ファイルを作成:

# grub-mkconfig -o /boot/grub/grub.cfg

マウントされている ESP に GRUB をインストール:

# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub --recheck

設定に問題がなければ、次の起動時に GRUB は /boot パーティションのロックを解除するためのパスフレーズを要求するはずです。

fstab と crypttab の設定

This section deals with extra configuration to let the system mount the encrypted /boot.

While GRUB asks for a passphrase to unlock the encrypted /boot after above instructions, the partition unlock is not passed on to the initramfs. Hence, /boot will not be available after the system has re-/booted, because the encrypt hook only unlocks the system's root.

インストール時に genfstab スクリプトを使用した場合、/boot/boot/efi マウントポイントのエントリが含まれた /etc/fstab が作成されています。しかしながらシステムはブートパーティションに生成されたデバイスマッパーを見つけることができません。デバイスマッパーを使えるようにするために、以下を crypttab に追加してください。例:

/etc/crypttab
cryptboot  /dev/sdaY      none        luks

上記を設定するとパスフレーズが二回要求されるようになります (GRUB と systemd ユニットでそれぞれ一回ずつ入力しなくてはなりません)。/boot のロックを解除するエントリを重複させたくない場合、Dm-crypt/デバイスの暗号化#キーファイルの指示に従ってください:

  1. ランダムなテキストのキーファイルを作成
  2. キーファイルを (/dev/sdaY) ブートパーティションの LUKS ヘッダに追加
  3. /etc/fstab のエントリを確認して起動時に自動的にロックが解除されるように /etc/crypttab 行を追加

If for some reason the keyfile fails to unlock the boot partition, systemd will fallback to ask for a passphrase to unlock and, in case that is correct, continue booting.

ヒント: Optional post-installation steps:
  • It may be worth considering to add the GRUB bootloader to the ignore list of /etc/pacman.conf in order to take particular control of when the bootloader (which includes its own encryption modules) is updated.
  • If you want to encrypt the /boot partition to protect against offline tampering threats, the mkinitcpio-chkcryptoboot hook has been contributed to help.