vmware の容量を増やす

vmware の容量は必要最低限で作っているのだけどたまに容量が必要なときがでてくるので手軽に増やすためのメモ
大抵、CentOS をインストールしていてデフォルトの状態でつっこむのでパーティションが LVM になっていて気軽に増やすことができます。

手順

現状の容量

# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      7.2G  994M  5.9G  15% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm

一度 vmwareCentOS をシャットダウンして容量を拡張する、今回は8GBから10GBに容量を増やします。

ディスクが拡張されているか確認する

# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1044     8281507+  8e  Linux LVM

増やした容量をLVMでパーティションをきる

# fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
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): 3
First cylinder (1045-1305, default 1045): 
Using default value 1045
Last cylinder or +size or +sizeM or +sizeK (1045-1305, default 1305): 
Using default value 1305

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): 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.

有効にするために再起動する

# reboot

再起動してパーティションが増えているか確認する

# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1044     8281507+  8e  Linux LVM
/dev/sda3            1045        1305     2096482+  8e  Linux LVM

PV に追加した sda3 を追加する

# pvcreate /dev/sda3

先程作成した PV を VG に追加する、追加後 FreePE/Size の部分が追加されていることを確認する

# vgextend VolGroup00 /dev/sda3 
# vgdisplay

LV に先程追加してあまっている容量を追加する
Insufficient free space: ってでる場合は拡張しようとする容量が足りないということなので少し容量を減らしたりするといい

# lvextend -L +1.96GB /dev/VolGroup00/LogVol00

この段階では LV に追加されただけで実際のパーティションには追加されていない状況なのでリサイズする必要がある

# resize2fs /dev/VolGroup00/LogVol00
# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      9.1G  994M  7.7G  12% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm

LVM便利ですね!!!!