CentOSのLVMの拡張

 

VMware側では単にハードディスクの容量を増やしただけでは、CentOS側で使用可能なディスク容量は増えません。

使用可能なディスク容量を増やすにはLVM(logical volume manager)を使って増やす必要があります。

 

1. terminalを開きスーパーユーザーになる

[centos@localhost ~]$ su

Password: 

 

2. メガバイト単位でファイルシステムのディスク使用状況を表示する

[root@localhost centos]# df -m

Filesystem           1M-blocks      Used Available Use% Mounted on

/dev/mapper/vg_centos6-lv_root

                         47826     18183     29158  39% /

tmpfs                     3936         1      3935   1% /dev/shm

/dev/sda1                  485        32       428   7% /boot

/dev/mapper/vg_centos6-lv_home

                         46557      9050     35143  21% /home

.host:/                1907343   1302391    604952  69% /mnt/hgfs

/dev/mapper/vg_centos6-lv_rootを見ると39%仕様となっている。

 

3. ハードディスクのパーティションを確認する

[root@localhost centos]# fdisk -l

 

Disk /dev/sda: 161.1 GB, 161061273600 bytes

255 heads, 63 sectors/track, 19581 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: 0x00060a7b

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64       13055   104344576   8e  Linux LVM

 

Disk /dev/dm-0: 50.9 GB, 50939822080 bytes

255 heads, 63 sectors/track, 6193 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/dm-0 doesn't contain a valid partition table

 

Disk /dev/dm-1: 6308 MB, 6308233216 bytes

255 heads, 63 sectors/track, 766 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/dm-1 doesn't contain a valid partition table

 

Disk /dev/dm-2: 49.6 GB, 49597644800 bytes

255 heads, 63 sectors/track, 6029 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/dm-2 doesn't contain a valid partition table

/dev/sdaを使ってるっぽい(小声)

 

4. ハードディスクのパーティションを設定する

[root@localhost centos]# 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').

 

4-1. /dev/sdaのパーティション情報を表示する

Command (m for help): p

 

Disk /dev/sda: 161.1 GB, 161061273600 bytes

255 heads, 63 sectors/track, 19581 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: 0x00060a7b

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64       13055   104344576   8e  Linux LVM

 

4-2. 新しいパーティションを作成する

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 3

First cylinder (13055-19581, default 13055): 13055

Last cylinder, +cylinders or +size{K,M,G} (13055-19581, default 19581): 19581

 

4-3. /dev/sdaのパーティション情報を表示する

Command (m for help): p

 

Disk /dev/sda: 161.1 GB, 161061273600 bytes

255 heads, 63 sectors/track, 19581 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: 0x00060a7b

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64       13055   104344576   8e  Linux LVM

/dev/sda3           13055       19581    52426782+  83  Linux

/dev/sda3が新たに追加されている

 

4-4. /dev/sda3のパーティション・タイプを83のLinuxから8eのLinux LVMへ変更する

Command (m for help): t

Partition number (1-4): 3

Hex code (type L to list codes): L

 

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        

 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-

 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-

 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-

 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx         

 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data    

 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .

 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   

 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt         

 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     

 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        

 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      

 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        

 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            

 f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor      

12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor      

14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  

16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    

17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 

18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep        

1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT            

1e  Hidden W95 FAT1

Hex code (type L to list codes): 8e

Changed system type of partition 3 to 8e (Linux LVM)

 

4-5. /dev/sdaのパーティション情報を表示する

Command (m for help): p

 

Disk /dev/sda: 161.1 GB, 161061273600 bytes

255 heads, 63 sectors/track, 19581 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: 0x00060a7b

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64       13055   104344576   8e  Linux LVM

/dev/sda3           13055       19581    52426782+  8e  Linux LVM

 

4-6. パーティション情報を書き込んで終了する

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.

[root@localhost centos]# 

 

5 CentOSを再起動する

 

6. terminalを開きスーパーユーザーになる

[centos@localhost ~]$ su

Password: 

 

7. 物理ボリューム(Physical Volume)の作成

[root@localhost centos]# pvcreate /dev/sda3

  Physical volume "/dev/sda3" successfully created

 

8.ボリュームグループを表示する

[root@localhost centos]# vgdisplay -v

    Finding all volume groups

    Finding volume group "vg_centos6"

  --- Volume group ---

  VG Name               vg_centos6

  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               99.51 GiB

  PE Size               4.00 MiB

  Total PE              25474

  Alloc PE / Size       25474 / 99.51 GiB

  Free  PE / Size       0 / 0   

  VG UUID               PtUDsL-3HSo-lU9p-NqI4-jMFv-ckQE-FRRZgv

   

  --- Logical volume ---

  LV Name                /dev/vg_centos6/lv_root

  VG Name                vg_centos6

  LV UUID                xIzqpu-Trt4-DQ3L-IZgh-dzPs-HYK7-PoDN0g

  LV Write Access        read/write

  LV Status              available

  # open                 1

  LV Size                47.44 GiB

  Current LE             12145

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0

   

  --- Logical volume ---

  LV Name                /dev/vg_centos6/lv_home

  VG Name                vg_centos6

  LV UUID                JYNJhk-hm1P-aSII-MN8V-mRQA-8Eg2-xnHhe6

  LV Write Access        read/write

  LV Status              available

  # open                 1

  LV Size                46.19 GiB

  Current LE             11825

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:2

   

  --- Logical volume ---

  LV Name                /dev/vg_centos6/lv_swap

  VG Name                vg_centos6

  LV UUID                uSJ3Fe-yzY5-aT3V-TS50-cZ0T-9KmP-w4AyTS

  LV Write Access        read/write

  LV Status              available

  # open                 1

  LV Size                5.88 GiB

  Current LE             1504

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:1

   

  --- Physical volumes ---

  PV Name               /dev/sda2     

  PV UUID               f7ryyL-jBUx-1Jte-hpCU-ecAm-gwDA-KADUjh

  PV Status             allocatable

  Total PE / Free PE    25474 / 0

ボリューム名がvg_centos6でvolume groupのsizeは99.51GBと表示されている。

 

9. vg_centos6のvolume groupのsizeを拡張する

[root@localhost centos]# vgextend vg_centos6 /dev/sda3

  Volume group "vg_centos6" successfully extended

 

10. ボリュームグループを表示する

[root@localhost centos]# vgdisplay -v

    Finding all volume groups

    Finding volume group "vg_centos6"

  --- Volume group ---

  VG Name               vg_centos6

  System ID             

  Format                lvm2

  Metadata Areas        2

  Metadata Sequence No  5

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                3

  Open LV               3

  Max PV                0

  Cur PV                2

  Act PV                2

  VG Size               149.50 GiB

  PE Size               4.00 MiB

  Total PE              38273

  Alloc PE / Size       25474 / 99.51 GiB

  Free  PE / Size       12799 / 50.00 GiB

  VG UUID               PtUDsL-3HSo-lU9p-NqI4-jMFv-ckQE-FRRZgv

   

  --- Logical volume ---

  LV Name                /dev/vg_centos6/lv_root

  VG Name                vg_centos6

  LV UUID                xIzqpu-Trt4-DQ3L-IZgh-dzPs-HYK7-PoDN0g

  LV Write Access        read/write

  LV Status              available

  # open                 1

  LV Size                47.44 GiB

  Current LE             12145

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0

   

  --- Logical volume ---

  LV Name                /dev/vg_centos6/lv_home

  VG Name                vg_centos6

  LV UUID                JYNJhk-hm1P-aSII-MN8V-mRQA-8Eg2-xnHhe6

  LV Write Access        read/write

  LV Status              available

  # open                 1

  LV Size                46.19 GiB

  Current LE             11825

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:2

   

  --- Logical volume ---

  LV Name                /dev/vg_centos6/lv_swap

  VG Name                vg_centos6

  LV UUID                uSJ3Fe-yzY5-aT3V-TS50-cZ0T-9KmP-w4AyTS

  LV Write Access        read/write

  LV Status              available

  # open                 1

  LV Size                5.88 GiB

  Current LE             1504

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:1

   

  --- Physical volumes ---

  PV Name               /dev/sda2     

  PV UUID               f7ryyL-jBUx-1Jte-hpCU-ecAm-gwDA-KADUjh

  PV Status             allocatable

  Total PE / Free PE    25474 / 0

   

  PV Name               /dev/sda3     

  PV UUID               mUeYL8-A2IB-fGGE-sWwU-pUGG-nsFR-JuByAM

  PV Status             allocatable

  Total PE / Free PE    12799 / 12799

空き物理エクステント(Free Physical Extent)は12799と表示されました。

   

11. ボリュームグループvg_centos6の論理ボリューム(lv_root)を12799物理エクステントほど拡張する

[root@localhost centos]# lvextend -l +12799 /dev/vg_centos6/lv_root

  Extending logical volume lv_root to 97.44 GiB

  Logical volume lv_root successfully resized

 

12. ファイルシステムをサイズを変更する

[root@localhost centos]# resize2fs /dev/vg_centos6/lv_root

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg_centos6/lv_root is mounted on /; on-line resizing required

old desc_blocks = 3, new_desc_blocks = 7

Performing an on-line resize of /dev/vg_centos6/lv_root to 25542656 (4k) blocks.

The filesystem on /dev/vg_centos6/lv_root is now 25542656 blocks long.

 

13. ファイルシステムのディスク使用状況を表示する

[root@localhost centos]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_centos6-lv_root

                       96G   18G   78G  19% /

tmpfs                 3.9G  260K  3.9G   1% /dev/shm

/dev/sda1             485M   32M  428M   7% /boot

/dev/mapper/vg_centos6-lv_home

                       46G  8.9G   35G  21% /home

.host:/               1.9T  1.3T  591G  69% /mnt/hgfs

[root@localhost centos]# 

/dev/mapper/vg_centos-6-lv_rootの使用状況が39%から19%になりました。