LVM に Arch Linux をインストールする

提供: ArchWiki
2022年9月1日 (木) 14:42時点におけるAshMyzk (トーク | 投稿記録)による版 (→‎物理ボリュームを作成する: 翻訳)
ナビゲーションに移動 検索に移動

関連記事

LVM ボリュームは、インストール手順パーティショニングフォーマットの間で作成する必要があります。パーティションを直接フォーマットしてルートファイルシステムにするのではなく、ファイルシステムを論理ボリューム (LV) 内で作成します。

概略:

  • 必要なパッケージをインストールする。(LVM#始める を参照)
  • 物理ボリューム (PV) を格納するパーティションを作成する。
  • PV を作成する。ディスクが一つしかない場合は一つの大きなパーティションに一つの PV を作成するのが良いでしょう。ディスクが複数ある場合はそれぞれにパーティションを作成してパーティション毎に PV を作ることができます。
  • ボリュームグループ (VG) を作成して全ての PV を追加する。
  • その VG の中に論理ボリューム (LV) を作成する。
  • インストールガイド#パーティションのフォーマット に進んで下さい。
  • インストールガイドの「初期 RAM ディスク環境を作成する」手順にたどり着いたら、/etc/mkinitcpio.conflvm2 フックを追加する (詳細は下記に)。
警告: LVM をサポートしていないブートローダを使う場合は、/boot を LVM 内に配置することはできません。/boot 用に別のパーティションを作成し、それを直接フォーマットしなければなりません。LVM をサポートしているブートローダとして知られているのは GRUB だけです。

インストール

インストールガイド#パーティション までインストールガイドに従います。この時点でインストールガイドから分岐し、LVM を念頭に置いたパーティショニングを行います。

パーティションを作成する

まず、LVM をセットアップする前に必要に応じてディスクをパーティショニングしてください。

パーティショニングを作成してください:

  • Master Boot Record パーティションテーブルを使用する場合は、パーティションタイプ ID8e に設定してください (fdisk ではパーティションタイプ Linux LVM)。
  • GUID パーティションテーブルを使う場合は、パーティションタイプ GUIDE6D6D379-F507-44C2-A23C-238F2A3DF928 に設定してください (fdisk ではパーティションタイプ Linux LVMgdisk では 8e00 )。

物理ボリュームを作成する

物理ボリュームとして使えるデバイスを確認するには:

# lvmdiskscan
警告: 物理ボリュームを作成するデバイスをよく確認してください。間違ったデバイスを使ってしまうとデータが消失してしまいます。

デバイス上に物理ボリュームを作成する:

# pvcreate DEVICE

このコマンドはデバイスにヘッダを作成し、LVM で使えるようにします。LVM#LVM の構成要素 に書かれてあるように、DEVICE には任意のブロックデバイス (例: ディスク /dev/sda やパーティション /dev/sda2、ループバックデバイスなど) を指定できます。例えば:

# pvcreate /dev/sda2

作成した物理ボリュームを以下のコマンドで確認できます:

# pvdisplay

また、物理ボリュームの情報は以下のコマンドで得られます:

# pvscan
ヒント: 既存のディスク署名で問題が発生した場合、wipefs を使って署名を削除できます。
ノート: パーティションを作成していない SSD を使う場合、pvcreate --dataalignment 1m /dev/sda を使用してください (消去ブロックのサイズが 1 MiB 未満の場合)、ここ を参照。

ボリュームグループを作成・拡張する

First you need to create a volume group on any one of the physical volumes:

# vgcreate <volume_group> <physical_volume>

For example:

# vgcreate VolGroup00 /dev/sda2

See lvm(8) for a list of valid characters for volume group names.

Extending the volume group is just as easy:

# vgextend <volume_group> <physical_volume>

For example, to add both sdb1 and sdc to your volume group:

# vgextend VolGroup00 /dev/sdb1
# vgextend VolGroup00 /dev/sdc

You can track how your volume group grows with:

# vgdisplay

This is also what you would do if you wanted to add a disk to a RAID or mirror group with failed disks.

ノート: You can create more than one volume group if you need to, but then you will not have all your storage presented as a single disk.

物理ボリュームとボリュームグループを同時に作成する

LVM allows you to combine the creation of a volume group and the physical volumes in one easy step. For example, to create the group VolGroup00 with the three devices mentioned above, you can run:

# vgcreate VolGroup00 /dev/sda2 /dev/sdb1 /dev/sdc

This command will first set up the three partitions as physical volumes (if necessary) and then create the volume group with the three volumes. The command will warn you if it detects an existing filesystem on any devices.

論理ボリュームを作成する

ヒント:
  • If you wish to use snapshots, logical volume caching, thin provisioned logical volumes or RAID see LVM#Logical volumes.
  • If a logical volume will be formatted with ext4, leave at least 256 MiB free space in the volume group to allow using e2scrub(8).

Now we need to create logical volumes on this volume group. You create a logical volume with the next command by specifying the new volume's name and size, and the volume group it will reside on:

# lvcreate -L <size> <volume_group> -n <logical_volume>

For example:

# lvcreate -L 10G VolGroup00 -n lvolhome

This will create a logical volume that you can access later with /dev/VolGroup00/lvolhome. Just like volume groups, you can use any name you want for your logical volume when creating it besides a few exceptions listed in lvm(8) § VALID_NAMES.

You can also specify one or more physical volumes to restrict where LVM allocates the data. For example, you may wish to create a logical volume for the root filesystem on your small SSD, and your home volume on a slower mechanical drive. Simply add the physical volume devices to the command line, for example:

# lvcreate -L 10G VolGroup00 -n lvolhome /dev/sdc1

To use all the free space left in a volume group, use the next command:

# lvcreate -l 100%FREE  <volume_group> -n <logical_volume>

You can track created logical volumes with:

# lvdisplay
ノート: You may need to load the device-mapper kernel module (modprobe dm_mod) for the above commands to succeed.
ヒント: You can start out with relatively small logical volumes and expand them later if needed. For simplicity, leave some free space in the volume group so there is room for expansion.

論理ボリュームをフォーマット・マウントする

Your logical volumes should now be located in /dev/YourVolumeGroupName/. If you cannot find them, use the next commands to bring up the module for creating device nodes and to make volume groups available:

# modprobe dm_mod
# vgscan
# vgchange -ay

Now you can format your logical volumes and mount them as normal partitions (see mount a file system for additional details):

# mkfs.<fstype> /dev/<volume_group>/<logical_volume>
# mount /dev/<volume_group>/<logical_volume> /<mountpoint>

For example:

# mkfs.ext4 /dev/VolGroup00/lvolhome
# mount /dev/VolGroup00/lvolhome /home
警告: When choosing mountpoints, just select your newly created logical volumes (use: /dev/Volgroup00/lvolhome). Do not select the actual partitions on which logical volumes were created (do not use: /dev/sda2).

システムを設定する

mkinitcpio フックを追加する

In case your root filesystem is on LVM, you will need to enable the appropriate mkinitcpio hooks, otherwise your system might not boot. Enable:

  • udev and lvm2 for the default busybox-based initramfs
  • systemd and lvm2 for systemd-based initramfs

udev is there by default. Edit the file and insert lvm2 between block and filesystems like so:

/etc/mkinitcpio.conf
HOOKS=(base udev ... block lvm2 filesystems)

For systemd based initramfs:

/etc/mkinitcpio.conf
HOOKS=(base systemd ... block lvm2 filesystems)

Afterwards, you can continue in normal installation instructions with the create an initial ramdisk step.

ヒント:
  • The lvm2 hook is installed by lvm2, not mkinitcpio. If you are running mkinitcpio in an arch-chroot for a new installation, lvm2 must be installed inside the arch-chroot for mkinitcpio to find the lvm2 hook. If lvm2 only exists outside the arch-chroot, mkinitcpio will output Error: Hook 'lvm2' cannot be found.
  • If your root filesystem is on LVM RAID see #Configure mkinitcpio for RAID.

mkinitcpio を RAID 用に設定する

If your root filesystem is on LVM RAID additionally to the lvm2 hook, you need to add dm-raid and the appropriate RAID modules (e.g. raid0, raid1, raid10 and/or raid456) to the MODULES array in mkinitcpio.conf. Also dm_integrity module is needed if you created RAID with integrity checksums (--raidintegrity option in lvcreate).

For busybox based initramfs:

/etc/mkinitcpio.conf
MODULES=(dm-raid dm_integrity raid0 raid1 raid10 raid456)
HOOKS=(base udev ... block lvm2 filesystems)

For systemd based initramfs:

/etc/mkinitcpio.conf
MODULES=(dm-raid dm_integrity raid0 raid1 raid10 raid456)
HOOKS=(base systemd ... block lvm2 filesystems)

For systems using LVM thin volumes the location of systemd between udev and block causes the malfunction of the thin volume. just with the parameters (base udev autodetect modconf block lvm2 filesystems keyboard fsck) works: root FS inside a lvm logical volume, and other LVM's (normal and thin) at other locations.

カーネルブートオプション

If the root file system resides in a logical volume, the root= kernel parameter must be pointed to the mapped device, e.g /dev/vg-name/lv-name.