論理ボリュームマネージャ(Logical Volume Manager、LVM)で構成されたVirtual Machineのパーティションを拡張してみました
仮想マシンの仮想ハードウェア構成は柔軟に変更でき仮想化のメリットの一つです
今回事前に用意されていたRHELのVMテンプレートで作成したのですが、HDDが45GBでした
これではさすがに少ないのでVHDを45GBから100GBに拡張しました
これ自体は仮想環境の管理ツールで簡単に拡張できますが、実際にOSに認識させるまでの手順をメモとして残します
参考にしたサイトです。すごく分かりやすかったです
Linux技術トレーニング 基本管理コース II
https://users.miraclelinux.com/technet/document/linux/training/2_2_3.html#training2_2_3
Linux サーバ構築 ( Fedora Core5 ) – LVM
http://www.systemo.net/fc5-12-lvm-extend.html
なおこの方法はかなり危険と思われます。あくまでも自己責任でお願い致しますm(__)m
VHDを45GBから100GBに拡張した状態。リモート作業だったためにLevel3で行いましたがコンソールが利用できるならシングルユーザモードが安全だと思います
1 2 3 4 5 6 7 8 9 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
[root@host01 ~]# parted -l Model: VMware Virtual disk (scsi) Disk /dev/sda: 107GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 263MB 262MB primary ext4 boot 2 263MB 48.3GB 48.1GB primary lvm Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol01: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 10.7GB 10.7GB ext4 Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol02: 28.7GB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 28.7GB 28.7GB ext4 Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol00: 8590MB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 8590MB 8590MB linux-swap(v1) [root@host01 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol02 27G 6.0G 20G 24% / tmpfs 1004M 0 1004M 0% /dev/shm /dev/sda1 243M 72M 158M 32% /boot /dev/mapper/VolGroup00-LogVol01 9.9G 518M 8.9G 6% /var [root@host01 ~]# vgdisplay --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 44.75 GiB PE Size 32.00 MiB Total PE 1432 Alloc PE / Size 1432 / 44.75 GiB Free PE / Size 0 / 0 VG UUID TljY5H-ywFf-3l9n-y3V2-8lQf-NPYW-7c0NDm [root@host01 ~]# vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 3 0 wz--n- 44.75g 0 [root@host01 ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert LogVol00 VolGroup00 -wi-ao 8.00g LogVol01 VolGroup00 -wi-ao 10.00g LogVol02 VolGroup00 -wi-ao 26.75g [root@host01 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup00 PV Size 44.75 GiB / not usable 5.00 MiB Allocatable yes (but full) PE Size 32.00 MiB Total PE 1432 Free PE 0 Allocated PE 1432 PV UUID g1dJfi-EQJ6-cARf-MWyF-h3K4-f04H-xxxxxx |
- fdiskで物理ボリュームの拡張
- pvresizeでFree領域を拡張
- lvextendで論理ボリュームの拡張
- resize2fsでファイルシステムの拡張
- 確認
fdiskで物理ボリュームの拡張を行います
1 2 3 4 5 6 7 8 9 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 |
[root@host01 ~]# fdisk /dev/sda 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): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): p Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0x00055837 Device Boot Start End Blocks Id System /dev/sda1 * 1 32 256000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 32 5875 46928896 8e Linux LVM |
Partition 2を削除
1 2 |
Command (m for help): d Partition number (1-4): 2 |
Partition 2を作成(領域を最大まで拡張します)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Command (m for help): n Command action e extended p primary partition (1-4) P Partition number (1-4): 2 First cylinder (32-13054, default 32): Using default value 32 Last cylinder, +cylinders or +size{K,M,G} (32-13054, default 13054): Using default value 13054 Command (m for help): p Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0x00055837 Device Boot Start End Blocks Id System /dev/sda1 * 1 32 256000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 32 13054 104599231 83 Linux |
IDを83から8eに変更
1 2 3 4 |
Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) |
パーティション情報書き込み
1 2 3 4 5 6 7 8 9 |
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 or after you run partprobe(8) or kpartx(8) Syncing disks. |
確認
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@host01 ~]# fdisk -ul /dev/sda Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00055837 Device Boot Start End Blocks Id System /dev/sda1 * 2048 514047 256000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 514048 209712509 104599231 8e Linux LVM |
再起動で起動できればここまではOKです
1 2 3 4 5 6 7 8 9 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
[root@host01 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup00 PV Size 44.75 GiB / not usable 5.00 MiB Allocatable yes (but full) PE Size 32.00 MiB Total PE 1432 Free PE 0 Allocated PE 1432 PV UUID g1dJfi-EQJ6-cARf-MWyF-h3K4-f04H-xxxxxxx [root@host01 ~]# pvresize /dev/sda2 Physical volume "/dev/sda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized [root@host01 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup00 PV Size 99.75 GiB / not usable 2.69 MiB Allocatable yes PE Size 32.00 MiB Total PE 3192 Free PE 1760 Allocated PE 1432 PV UUID g1dJfi-EQJ6-cARf-MWyF-h3K4-f04H-xxxxx [root@host01 ~]# vgdisplay --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 5df VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 99.75 GiB PE Size 32.00 MiB Total PE 3192 Alloc PE / Size 1432 / 44.75 GiB Free PE / Size 1760 / 55.00 GiB VG UUID TljY5H-ywFf-3l9n-y3V2-8lQf-NPYW-xxxxx [root@host01 ~]# parted -l Model: VMware Virtual disk (scsi) Disk /dev/sda: 107GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 263MB 262MB primary ext4 boot 2 263MB 107GB 107GB primary lvm Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol01: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 10.7GB 10.7GB ext4 Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol02: 28.7GB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 28.7GB 28.7GB ext4 Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol00: 8590MB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 8590MB 8590MB linux-swap(v1) |
/パーティションの27GBを50GBに拡張します
1 2 3 |
[root@host01 ~]# lvextend -L50G /dev/VolGroup00/LogVol02 Extending logical volume LogVol02 to 50.00 GiB Logical volume LogVol02 successfully resized |
/varのパーティション9.9GBに残り空き容量すべてを追加します
1 2 3 |
[root@host01 ~]# lvextend -l +100%FREE /dev/VolGroup00/LogVol01 Extending logical volume LogVol01 to 41.75 GiB Logical volume LogVol01 successfully resized |
ここまで作業してもまだファイルシステムは拡張していません
1 2 3 4 5 6 7 8 |
[root@host01 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol02 27G 6.0G 20G 24% / tmpfs 1004M 0 1004M 0% /dev/shm /dev/sda1 243M 72M 158M 32% /boot /dev/mapper/VolGroup00-LogVol01 9.9G 515M 8.9G 6% /var |
拡張します
1 2 3 4 5 6 |
[root@host01 ~]# resize2fs -p /dev/VolGroup00/LogVol01 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/VolGroup00/LogVol01 is mounted on /var; on-line resizing required old desc_blocks = 1, new_desc_blocks = 3 Performing an on-line resize of /dev/VolGroup00/LogVol01 to 10944512 (4k) blocks. The filesystem on /dev/VolGroup00/LogVol01 is now 10944512 blocks long. |
1 2 3 4 5 6 |
[root@host01 ~]# resize2fs -p /dev/VolGroup00/LogVol02 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/VolGroup00/LogVol02 is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 4 Performing an on-line resize of /dev/VolGroup00/LogVol02 to 13107200 (4k) blocks. The filesystem on /dev/VolGroup00/LogVol02 is now 13107200 blocks long. |
パーティションを確認します
1 2 3 4 5 6 7 8 |
[root@host01 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol02 50G 6.0G 41G 13% / tmpfs 1004M 0 1004M 0% /dev/shm /dev/sda1 243M 72M 158M 32% /boot /dev/mapper/VolGroup00-LogVol01 42G 522M 39G 2% /var |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[root@host01 ~]# parted -l Model: VMware Virtual disk (scsi) Disk /dev/sda: 107GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 263MB 262MB primary ext4 boot 2 263MB 107GB 107GB primary lvm Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol01: 44.8GB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 44.8GB 44.8GB ext4 Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol02: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 53.7GB 53.7GB ext4 Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup00-LogVol00: 8590MB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 8590MB 8590MB linux-swap(v1) |
LVMで柔軟なパーティション構成の変更ができるのは有り難いですが、一歩間違うとデータが吹っ飛ぶ可能性もあるので細心の注意が必要ですね