ZFS に Arch Linux をインストール

提供: ArchWiki
2016年2月12日 (金) 23:54時点におけるKusakata (トーク | 投稿記録)による版 (同期)
ナビゲーションに移動 検索に移動

関連記事

この記事では root の ZFS ファイルシステムに Arch Linux をインストールするのに必要な手順を解説しています。この記事はビギナーズガイドの補足です。

インストール

ZFS パッケージのインストールについては ZFS#インストール を見て下さい。archiso から ZFS に Arch Linux をインストールする場合、demz-repo-archiso リポジトリを使用するのが楽です。

archzfs を archiso に埋め込む

ZFS の記事を見て下さい。

ドライブのパーティション

ZFS で使用するパーティションテーブルのタイプの選択に関する情報はビギナーズガイド#ドライブの準備を見て下さい。ZFS は GPT と MBR パーティションテーブルをサポートしています。

ZFS は自分でパーティションを管理するので、基本的なパーティションテーブルスキームだけが必要になります。ZFS ファイルシステムを含めるパーティションのタイプは bf00 か "Solaris Root" である必要があります。

パーティションスキーム

以下は MBR を使用する場合の、ZFS root セットアップの基本的なパーティションスキームの例です:

Part     Size   Type
----     ----   -------------------------
   1     512M   Ext boot partition (8300)
   2     XXXG   Solaris Root (bf00)

以下は GPT を使用する場合の例です。BIOS ブートパーティションにブートローダーが含まれます:

Part     Size   Type
----     ----   -------------------------
   1       2M   BIOS boot partition (ef02)
   1     512M   Ext boot partition (8300)
   2     XXXG   Solaris Root (bf00)

ハードウェアやブートローダーによっては他のパーティションが必要になることがあります。詳しくはビギナーズガイド#ブートローダのインストールと設定を見て下さい。

ヒント: ZFS をサポートしているブートローダーは #ブートローダーのインストールと設定 で説明しています。
警告: Several GRUB bugs (bug #42861, zfsonlinux/grub/issues/5) prevent or complicate installing it on ZFS partitions, use of a separate boot partition is recommended

ディスクのフォーマット

他のシステムパーティションと同じようにブートパーティションをフォーマットしてください。Solaris パーティションや BIOS ブートパーティションには何もしないでください。Solaris パーティションは ZFS が、BIOS ブートパーティションはブートローダーが処理します。

ZFS ファイルシステムのセットアップ

まず、ZFS モジュールがロードされていることを確認してください:

# modprobe zfs

root zpool の作成

# zpool create zroot /dev/disk/by-id/id-to-partition
警告: ZFS を使うときはいつでも id 名を使って下さい。そうしないとインポートエラーが発生します。

必要なファイルシステムの作成

必要であれば、/home/root などのサブファイルシステムのマウントポイントを以下のコマンドで作成できます:

# zfs create zroot/home -o mountpoint=/home
# zfs create zroot/root -o mountpoint=/root

システムディレクトリ (/var/etc など) で別のデータセットを使いたい場合、/etc/fstab にデータセットを記述しないとシステムが起動しなくなります。以下でまた触れます。

スワップパーティション

ZFS#スワップボリューム を見て下さい。

root ファイルシステムの設定

まず、ルートファイルシステムのマウントポイントを設定:

# zfs set mountpoint=/ zroot

そして、任意のサブファイルシステムを設定:

# zfs set mountpoint=/home zroot/home
# zfs set mountpoint=/root zroot/root

システムディレクトリで別のデータセットを使用する場合 (/var/usr):

# zfs set mountpoint=legacy zroot/usr
# zfs set mountpoint=legacy zroot/var

/etc/fstab にデータセットを記述:

/etc/fstab
# <file system>        <dir>         <type>    <options>             <dump> <pass>
zroot/usr              /usr          zfs       defaults,noatime      0      0
zroot/var              /var          zfs      defaults,noatime,acl   0      0

/var ファイルシステムはアクセス制御リスト (acl) が有効であることを必要としますが、zfs ではデフォルトで無効になっています。有効にするには zfs set を使います:

# zfs set xattr=sa zroot/var
# zfs set acltype=posixacl zroot/var

xattr=sa プロパティは必須ではありませんが、推奨されています。詳しくは man zfs を参照。

ルートファイルシステムに bootfs プロパティを設定してブートローダーがオペレーティングシステムの場所を認識できるようにします:

# zpool set bootfs=zroot zroot

プールをエクスポート:

# zpool export zroot
警告: Do not skip this, otherwise you will be required to use -f when importing your pools. This unloads the imported pool.
ノート: This might fail if you added a swap partition above. Need to turn it off with the swapoff command.

最後に、プールを再インポートしてください:

# zpool import -d /dev/disk/by-id -R /mnt zroot
ノート: -d is not the actual device id, but the /dev/by-id directory containing the symbolic links.

上記のコマンドでエラーが表示される場合、プールをエクスポートしてコマンドを再実行してください。それで ZFS ファイルシステムを使用する準備が整います。

新しいシステムに zpool.cache ファイルをコピーします。後で ZFS デーモンを起動するのに必要になります。

# cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache

/etc/zfs/zpool.cache が存在しない場合は作成してください:

# zpool set cachefile=/etc/zfs/zpool.cache zroot

Arch Linux のインストールと設定

ビギナーズガイドの手順に従ってください。ZFSonLinux を使うにあたって特別に注意が必要なことを記します。

  • まず mount コマンドを使って boot やシステムパーティションをマウント。
  • ベースシステムのインストール。
  • ビギナーズガイド#fstab の生成 で書かれている方法は ZFS の場合オーバーキルです。ZFS は基本的にパーティションを自動的にマウントするので、システムディレクトリのデータセットを作成したりしないかぎり、fstab ファイルに ZFS パーティションを記述する必要はありません。ファイルシステムの fstab を生成するときは、次のコマンドを使ってください:
# genfstab -U -p /mnt | grep boot >> /mnt/etc/fstab
  • /etc/fstab を編集:
ノート:
  • If you chose to create datasets for system directories, keep them in this fstab! Comment out the lines for the '/, /root, and /home mountpoints, rather than deleting them. You may need those UUIDs later if something goes wrong.
  • Anyone who just stuck with the guide's directions can delete everything except for the swap file and the boot/EFI partition. It seems convention to replace the swap's uuid with /dev/zvol/zroot/swap.
  • 初期 RAM ディスクを作成するときは、まず /etc/mkinitcpio.conf を編集して filesystems の前に zfs を追加してください。また、keyboard フックは zfs の前に移動して、何か問題が起こったときにコンソールにキーボードで入力できるようにしてください。また、fsck は削除できます (Ext3 や Ext4 を使わない場合)。HOOKS 行は以下のようになるはずです:
HOOKS="base udev autodetect modconf block keyboard zfs filesystems"
ノート: If you are using a separate dataset for /usr and have followed the instructions below, you must make sure you have the usr hook enabled after zfs, or your system will not boot.
  • 次のコマンドで initramfs を再生成:
# mkinitcpio -p linux

ブートローダーのインストールと設定

BIOS マザーボードの場合

GRUB#BIOS システム に従ってディスクに GRUB をインストールしてください。grub-mkconfig は ZFS ファイルシステムを正しく検出できないので、grub.cfg を手動で編集する必要があります:

/boot/grub/grub.cfg
set timeout=2
set default=0

# (0) Arch Linux
menuentry "Arch Linux" {
    linux /vmlinuz-linux zfs=zroot rw
    initrd /initramfs-linux.img
}

/boot パーティションを別に作成していなかった場合は、カーネルと initrd のパスを以下のように記述する必要があります:

 /dataset/@/actual/path  

例:

   linux /@/boot/vmlinuz-linux zfs=zroot rw
   initrd /@/boot/initramfs-linux.img

UEFI マザーボードの場合

UEFI ブートローダーには EFISTUBrEFInd を使ってください。ビギナーズガイド#UEFI マザーボードの場合を参照。ZFS では refind_linux.conf のカーネルパラメータには zfs=bootfszfs=zroot を含める必要があります。そうしないと ZFS からシステムが起動しません。rootrootfstype パラメータは不要です。

アンマウントと再起動

あと少しです。

# exit
# umount /mnt/boot
# zfs umount -a
# zpool export zroot

そして再起動してください。

警告: If you do not properly export the zpool, the pool will refuse to import in the ramdisk environment and you will be stuck at the busybox terminal.

最初に起動した後

ここまで何も問題がなければ、システムが起動するはずです。これ以降も問題なくシステムが再起動できるように、zfs.target を有効化してください。プールが自動マウントされ hostid が設定されます。

自動でマウントさせたいプールごとに以下のコマンドを実行:

# zpool set cachefile=/etc/zfs/zpool.cache <pool>

systemd でターゲットを有効化:

# systemctl enable zfs.target

root で ZFS を使う場合、root ファイルシステムのマウント時にマシンの hostid を使うことはできなくなります。2つの解決方法があります。1つは spl の hostid をブートローダーのカーネルパラメータに記述する方法です。例えば spl.spl_hostid=0x00bab10c を追加します。hostid コマンドを使うことで数字を確認できます。

The other, and suggested, solution is to make sure that there is a hostid in /etc/hostid, and then regenerate the initramfs image. Which will copy the hostid into the initramfs image. To do write the hostid file safely you need to use a small C program:

#include <stdio.h>
#include <errno.h>
#include <unistd.h>

int main() {
    int res;
    res = sethostid(gethostid());
    if (res != 0) {
        switch (errno) {
            case EACCES:
            fprintf(stderr, "Error! No permission to write the"
                         " file used to store the host ID.\n"
                         "Are you root?\n");
            break;
            case EPERM:
            fprintf(stderr, "Error! The calling process's effective"
                            " user or group ID is not the same as"
                            " its corresponding real ID.\n");
            break;
            default:
            fprintf(stderr, "Unknown error.\n");
        }
        return 1;
    }
    return 0;
}

Copy it, save it as writehostid.c and compile it with gcc -o writehostid writehostid.c, finally execute it and regenerate the initramfs image:

# ./writehostid
# mkinitcpio -p linux

You can now delete the two files writehostid.c and writehostid. Your system should work and reboot properly now.

参照