share facebook facebook2 twitter menu hatena pocket slack

2014.08.01 FRI

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

岸上 健太郎

WRITTEN BY岸上 健太郎

cloudpackがみさんです。

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

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

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

参考m(__)m

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

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

</p>

<h1>fdisk -l /dev/xvda</h1>

<p>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</p>

<pre><code>Device Boot      Start         End      Blocks   Id  System
</code></pre>

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

<h1>sfdisk -d /dev/xvda &amp;gt; xvda.dump</h1>

<h1>vi xvda.dump</h1>

<h1>partition table of /dev/xvda</h1>

<p>unit: sectors</p>

<p>/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</p>

<h1>sfdisk /dev/xvda --force &amp;lt; xvda.dump</h1>

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

<p>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.</p>

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

<p>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</p>

<p>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</p>

<p>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</p>

<p>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).)</p>

<h1>shutdown -r -y now</h1>

<p>

再起動後のfdisk

</p>

<h1>fdisk -l</h1>

<p>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</p>

<pre><code>Device Boot      Start         End      Blocks   Id  System
</code></pre>

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

<p>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</p>

<p>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の確認

</p>

<h1>vgdisplay</h1>

<p>--- 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の拡張

</p>

<h1>pvresize /dev/xvda2</h1>

<p>Physical volume &amp;quot;/dev/xvda2&amp;quot; changed
  1 physical volume(s) resized / 0 physical volume(s) not resized</p>

<h1>vgdisplay</h1>

<p>--- 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</p>

<h1>lvextend -l +21629 /dev/mapper/VolGroup-lv_root /dev/xvda2</h1>

<p>Extending logical volume lv_root to 98.71 GiB
  Logical volume lv_root successfully resized</p>

<h1>resize2fs /dev/mapper/VolGroup-lv_root</h1>

<p>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.</p>

<h1>df -h</h1>

<p>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

です。

元記事はこちらです。

岸上 健太郎

岸上 健太郎

頑張るぞ!