share facebook facebook twitter menu hatena pocket slack

2014.08.01 FRI

LVM Typeのパーティションを拡張する

cloudpackがみさんです。

起動したAMIのディスクボリュームがLVMだったので、partedでの既存パーティション拡張はできません。

LVMなんだから新しいパーティションを作成してvgextendしたら良いのでは・・・と思うものの、

既存パーティションが拡張できないか試してみました。sfdiskを使います。

参考m(__)m

既存パーティションの拡張

LVMタイプのパーティション/dev/xvda2 を拡張します

fdisk -l /dev/xvda

Disk /dev/xvda: 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: 0x000eacf6

Device Boot      Start         End      Blocks   Id  System

/dev/xvda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/xvda2 64 2025 15751168 8e Linux LVM

sfdisk -d /dev/xvda > xvda.dump

vi xvda.dump

partition table of /dev/xvda

unit: sectors

/dev/xvda1 : start= 2048, size= 1024000, Id=83, bootable /dev/xvda2 : start= 1026048, size= ★208686462(※cylinders * heads * sectors - start=のサイズ1026048), Id=8e /dev/xvda3 : start= 0, size= 0, Id= 0 /dev/xvda4 : start= 0, size= 0, Id= 0

sfdisk /dev/xvda --force < xvda.dump

Checking that no-one is using this disk right now ... BLKRRPART: Device or resource busy

This disk is currently in use - repartitioning is probably a bad idea. Umount all file systems, and swapoff all swap partitions on this disk. Use the --no-reread flag to suppress this check.

Disk /dev/xvda: 13054 cylinders, 255 heads, 63 sectors/track Old situation: Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System /dev/xvda1 * 0+ 63- 64- 512000 83 Linux /dev/xvda2 63+ 2024- 1961- 15751168 8e Linux LVM /dev/xvda3 0 - 0 0 0 Empty /dev/xvda4 0 - 0 0 0 Empty New situation: Units = sectors of 512 bytes, counting from 0

Device Boot Start End #sectors Id System /dev/xvda1 * 2048 1026047 1024000 83 Linux /dev/xvda2 1026048 209712509 208686462 8e Linux LVM /dev/xvda3 0 - 0 0 Empty /dev/xvda4 0 - 0 0 Empty Warning: partition 1 does not end at a cylinder boundary Successfully wrote the new partition table

Re-reading the partition table ... BLKRRPART: Device or resource busy The command to re-read the partition table failed. Run partprobe(8), kpartx(8) or reboot your system now, before using mkfs

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1) to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1 (See fdisk(8).)

shutdown -r -y now

再起動後のfdisk

fdisk -l

Disk /dev/xvda: 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: 0x000eacf6

Device Boot      Start         End      Blocks   Id  System

/dev/xvda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/xvda2 64 13054 104343231 8e Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 15.3 GB, 15271460864 bytes 255 heads, 63 sectors/track, 1856 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: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 855 MB, 855638016 bytes 255 heads, 63 sectors/track, 104 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: 0x00000000

VGの確認

vgdisplay

--- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 ★ VG Size 15.02 GiB PE Size 4.00 MiB Total PE 3845 Alloc PE / Size 3845 / 15.02 GiB Free PE / Size 0 / 0 VG UUID lvi8Kt-MMja-nTvI-terh-7ljb-ImyV-SScwRk

PV/LVMの拡張

pvresize /dev/xvda2

Physical volume "/dev/xvda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized

vgdisplay

--- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 8 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 ★ VG Size 99.51 GiB PE Size 4.00 MiB Total PE 25474 Alloc PE / Size 3845 / 15.02 GiB ★ Free PE / Size 21629 / 84.49 GiB ←このFree PEを割り当てる VG UUID lvi8Kt-MMja-nTvI-terh-7ljb-ImyV-SScwRk

lvextend -l +21629 /dev/mapper/VolGroup-lv_root /dev/xvda2

Extending logical volume lv_root to 98.71 GiB Logical volume lv_root successfully resized

resize2fs /dev/mapper/VolGroup-lv_root

resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 7 Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 25876480 (4k) blocks. The filesystem on /dev/mapper/VolGroup-lv_root is now 25876480 blocks long.

df -h

Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 98G 1.1G 92G 2% / tmpfs 938M 0 938M 0% /dev/shm /dev/xvda1 485M 54M 407M 12% /boot

です。

元記事はこちらです。