LVM でボリュームを管理する最大のメリットは、ディスクの空き容量が少なくなったときに、新しいハードディスクを追加し、容易にロジカルボリュームのサイズを拡張できるところにあります。ここでは、以下のようなパーティション構成でインストールされた /home ディレクトリの空き容量が少なくなったため、新たなハードディスク /dev/sdb を追加し、LVM によるボリューム管理へ移行するまでの手順を解説します。

はじめに、新規ハードディスクを追加し、項42.2 で解説した手順と同様にロジカルボリュームを作成します。
追加した /dev/sdb にパーティション /dev/sdb1 を作成し、忘れずにファイルシステムのタイプを 8e に変更します。
# fdisk /dev/sdb The number of cylinders for this disk is set to 1116. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1116, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-1116, default 1116): Using default value 1116 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: 9184 MB, 9184760320 bytes 255 heads, 63 sectors/track, 1116 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 1116 8964238+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. |
dm-mod モジュールをロードし、/dev/mapper/control デバイスを作成しておきます。
# modprobe dm-mod # /sbin/devmap_mknod.sh Creating /dev/mapper/control character device with major:10 minor:63. |
/dev/sdb1 をフィジカルボリュームとして追加します。
# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created |
ボリュームグループを作成します。ここでは、ボリュームグループ名を vg_new としています。vgscan コマンドを実行し、作成したボリュームグループがシステムに認識されることも確認してください。
# vgcreate vg_new /dev/sdb1 Volume group "vg_new" successfully created # vgscan Reading all physical volumes. This may take a while... Found volume group "vg_new" using metadata type lvm2 # vgdisplay --- Volume group --- VG Name vg_new System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 8.55 GB PE Size 4.00 MB Total PE 2188 Alloc PE / Size 0 / 0 Free PE / Size 2188 / 8.55 GB VG UUID ELdP2e-zXy2-x6rC-yP0A-81T3-9AKT-7hb5Jp |
ロジカルボリュームを作成します。ボリュームグループ名は、lv_home としています。また、サイズは作成可能な最大サイズを指定しています。最大サイズは、ボリュームグループのフィジカルエクステントの数とそのサイズから求めることができます。vgdisplay の出力結果からフィジカルエクステントの数は 2188、サイズはデフォルトの 4MB であることがわかりますので、2188 x 4MB = 8752M を指定しています。
# lvcreate -L 8752M -n lv_home vg_new Logical volume "lv_home" created |
作成したロジカルボリュームにファイルシステムを作成します。
# mkfs.ext3 /dev/vg_new/lv_home
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1121664 inodes, 2240512 blocks
112025 blocks (5.00%) reserved for the super user
First data block=0
69 block groups
32768 blocks per group, 32768 fragments per group
16256 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override. |
作成したロジカルボリュームを任意のディレクトリにマウントし、既存の /home のデータを tar コマンドでコピーします。
# mkdir /mnt/home-new
# mount /dev/vg_new/lv_home /mnt/home_new
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 4024220 1805660 2014136 48% /
/dev/sda1 62193 16203 42779 28% /boot
/dev/sda3 3020172 33164 2833588 2% /home
/dev/mapper/vg_new-lv_home
8821216 32828 8340288 1% /mnt/home_new
# (cd /home/ && tar --exclude=lost+found -cf - .) | (cd /mnt/home_new/ && tar -xf -) |
その後、既存の /home ディレクトリをアンマウントし、/dev/vg_new/lv_home にマウントし直します。
# umount /mnt/home_new
# umount /home
# mount /dev/vg_new/lv_home /home
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 4024220 1805660 2014136 48% /
/dev/sda1 62193 16203 42779 28% /boot
/dev/mapper/vg_new-lv_home
8821216 33164 8339952 1% /home |
正常にマウントされたことを確認して、/etc/fstab を修正しておきます。/home ディレクトリにマウントしていた既存の /dev/sda3 の行を /dev/vg_new/lv_home へ変更します。
/dev/sda2 / ext3 defaults 1 1 /dev/sda1 /boot ext3 defaults 1 2 #/dev/sda3 /home ext3 defaults 1 3 /dev/vg_new/lv_home /home ext3 defaults 1 3 /dev/cdrom /mnt/cdrom iso9660 noauto,owner,ro 0 0 /dev/fd0 /mnt/floppy auto noauto,owner 0 0 none /proc proc defaults 0 0 none /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 /dev/sda4 swap swap defaults 0 0 |
ここまでの操作で、/home ディレクトリを LVM で管理されたボリュームへ移行することができました。
続けて、/home パーティションとして使用していた /dev/sda3 をフィジカルボリュームとしてボリュームグループ vg_new に追加し、その後、ロジカルボリューム /dev/vg_new/lv_home のサイズを拡張するまでの手順を解説します。

このように、LVM によるボリューム管理を活用すると、新たなフィジカルボリュームを追加し、ボリュームグループの拡大、およびそのボリュームグループ上にあるロジカルボリュームのサイズを容易に拡張することができます。
はじめに、/dev/sda3 のタイプを 8e に変更します。以下のように reboot のメッセージが表示された場合は、システムを再起動してください。
# fdisk /dev/sda The number of cylinders for this disk is set to 1106. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): 8e Changed system type of partition 3 to 8e (Linux LVM) Command (m for help): p Disk /dev/sda: 9105 MB, 9105050112 bytes 255 heads, 63 sectors/track, 1106 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 8 64228+ 83 Linux /dev/sda2 9 517 4088542+ 83 Linux /dev/sda3 518 899 3068415 8e Linux LVM /dev/sda4 900 1106 1662727+ 82 Linux swap Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. |
フィジカルボリュームとして /dev/sda3 を追加します。
# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created |
作成したフィジカルボリュームを既存のボリュームグループ /dev/vg_new に追加します。フィジカルボリュームを既存のボリュームグループに追加するには、vgextend コマンドを以下のように実行します。
# vgextend vg_new /dev/sda3 Volume group "vg_new" successfully extended |
追加後の vgdisplay を確認すると、以下のようにボリュームグループのサイズが 11.47 GB に拡張されたことがわかります。
# vgdisplay --- Volume group --- VG Name vg_new System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 11.47 GB PE Size 4.00 MB Total PE 2937 Alloc PE / Size 2188 / 8.55 GB Free PE / Size 749 / 2.93 GB VG UUID ELdP2e-zXy2-x6rC-yP0A-81T3-9AKT-7hb5Jp |
次に、ロジカルボリューム /dev/vg_new/lv_home のサイズを拡大します。以下のように lvextend コマンドを実行します。
# lvextend -L 11748M /dev/vg_new/lv_home Extending logical volume lv_home to 11.47 GB Logical volume lv_home successfully resized |
この例では、指定可能なの最大サイズ(2937 x 4MB = 11748M)を指定しています。また、サイズの指定には、+ 記号を使用することもできます。例えば以下のように実行すれば、既存のサイズから 2GB 拡張されます。
# lvextend -L +2G /dev/vg_new/lv_home |
ロジカルボリュームのサイズは拡張されましたが、この状態ではファイルシステムのサイズはもとのままであるため、ファイルシステムのサイズを拡大する必要があります。Turbolinux 10 Server が標準のファイルシステムに採用している ext3 のサイズ変更を行うには、resize2fs コマンドを使用します。
![]() | ファイルシステムのサイズを変更するコマンドは、ファイルシステムにより異なります。ReiserFS であれば resize_reiserfs、XFS であれば xfs_growfs などを使用します。 |
Turbolinux 10 Server で ext3 のサイズ変更を行うには、ファイルシステムをアンマウントする必要があります。必要に応じてランレベルを 1 に変更するなどの処理を行った後で、以下のコマンドを実行します。
# umount /home # e2fsck -f /dev/vg_new/lv_home e2fsck 1.35 (28-Feb-2004) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg_new/lv_home: 99/1121664 files (0.0% non-contiguous), 43499/2240512 blocks [root@dhcp-97 root]# resize2fs /dev/vg_new/lv_home resize2fs 1.35 (28-Feb-2004) Resizing the filesystem on /dev/vg_new/lv_home to 3007488 (4k) blocks. The filesystem on /dev/vg_new/lv_home is now 3007488 blocks long. |
マウントしてファイルシステムのサイズが拡張されたことを確認します。
# mount /home
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 4024220 1805680 2014116 48% /
/dev/sda1 62193 16203 42779 28% /boot
/dev/mapper/vg_new-lv_home
11842192 33164 11327832 1% /home |