Linuxサーバー(CentOS6)でLVM(Logicl Volume Manager)を作成する手順をまとめました。
LVMは論理ボリュームとしてパーティションを提供します。
ユーザーから物理ボリュームの存在を消し、論理ボリュームでパーティションを提供します。
また、ユーザーから物理ボリュームの増設や変更などを表示することなくディスクデバイスの管理を行うことができます。
簡単に言うと、仮想のボリュームということです。
以下はLVMの作成手順となります。
Linux「LVM」作成からマウントまでの手順
LVMの作成は大まかに以下の通りとなります。
- PV (Phisical Volume) 作成 ~ 物理パーティションをLVM用に設定
- VG (Volume Group) 作成 ~ PV を VG に割り当てる
- LV (Logical Volume) 作成 ~ VG から論理パーティションを切り出す
- LV を任意のファイルシステムでフォーマット
- フォーマットした領域をマウント
PV (Phisical Volume) 作成
接続しているディスクを確認します。
1 | $ fdisk -l |
lvmdiskscanで物理ボリュームとして使用可能なブロックデバイスを確認します。
1 | $ lvmdiskscan |
今回は、/dev/sdb にパーティションを1つだけ作成し、LVM用に指定した後、書き込みます。
※一度作成すると「8e(LVM)」を作成するだけでOKです。
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | $ fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x0f958ebf. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1044, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): Using default value 1044 Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0f958ebf Device Boot Start End Blocks Id System /dev/sdb1 1 1044 8385898+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. $ |
最後に pvcreate コマンドでLVMを使用する準備が整います。
※一度作成すると共有パーティションでは同じものを作成しなくてよい。
1 2 | $ pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created |
VG (Volume Group) 作成
ボリュームグループ “vg02” を作成します。ちなみに、グループ名に数字をつける必要はないです。
※一度作成すると共有パーティションでは同じものを作成しなくてよい。
1 2 | $ vgcreate vg02 /dev/sdb1 Volume group "vg02" successfully created |
LV (Logical Volume) 作成
※新規のLVを作成する際は必要です。同じものは作成しなくてよいです。
LV等見えない場合はOS再起動で見えます。
vg02 に 300GB の testvol を作成します。
1 | $ lvcreate -n testvol --size 300G vg02 |
デバイスマッパーに割り当てられた数字を確認するには以下のコマンドを実行します。
1 | $ lvdisplay |
LVをフォーマット
フォーマットは物理パーティションに実行するのと同様に指定します。
ext4 の場合は以下の通り。
1 | $ mkfs.ext4 /dev/vg02/testvol |
フォーマットした領域をマウント
“/testvol” ディレクトリを作成し、そこにマウントします。
マウント時にファイルシステムを指定する必要は特にないです。
1 2 3 | $ mkdir /testvol $ mount /dev/vg02/testvol /testvol $ |
※次回起動時のマウント用に/etc/fstabに追記します。
1 | vi /etc/fstab |
以下を追記
1 | /dev/vg02/testvol /testvol ext4 defaults 0 0 |
以上がLinuxでのLVM作成手順となります。

ITエンジニアの開発・検証・学習としてインターネット上で専用のサーバ(VPS)を利用しましょう!
実務経験はVPSで学べます。
コメント