CentOS磁盘扩容lvm


CentOS磁盘扩容lvm
 
安装的Centos的LVM空间减少的很快,没多久就不够用了,好多人使用的是Gparted扩容,命令行不好用,图形界面的Gparted在CentOS6.4上面找不到;有人使用Gparted-Live盘,感觉非常的麻烦,其实Linux本身提供了强大而又简单的扩容工具,非常的容易:
 
0:当前磁盘情况:
 
[root@CentOS ~]# df -h
Filesystem                                            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root                 5.5G  4.9G  375M  93% /
tmpfs                                                    499M  320K  498M   1% /dev/shm
/dev/sda1                                              485M   56M  404M  13% /boot
tmpfs                                                    499M     0  499M   0% /tmp/ram
 
1:查看要添加的硬盘,显示是/dev/sdb:
 
[root@CentOS ~]# fdisk -l
 
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x000d0b56
 
   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        1045     7875584   8e  Linux LVM
 
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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
 
.....:
 
2:初始化准备新增的磁盘:
 
[root@CentOS ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
 
 
3:把新增的磁盘添加到LVM:
 
[root@CentOS ~]# vgextend vg_centos /dev/sdb
  Volume group "vg_centos" successfully extended
 
 
4:查看增加磁盘后的LVM:
 
[root@CentOS ~]# vgdisplay -v vg_centos
    Using volume group(s) on command line
    Finding volume group "vg_centos"
  --- Volume group ---
  VG Name               vg_centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               15.50 GiB
  PE Size               4.00 MiB
  Total PE              3969
  Alloc PE / Size       1922 / 7.51 GiB
  Free  PE / Size       2047 / 8.00 GiB //这里显示还有多少空间可用,就是新增的磁盘空间
  VG UUID               6sYdCf-fA3g-Tyjz-lwfr-2hxP-lnFx-eVaMWj
   
  --- Logical volume ---
  LV Path                /dev/vg_centos/lv_root
  LV Name                lv_root
  VG Name                vg_centos
  LV UUID                jjByYP-BlFO-O70G-eYd9-Eupx-wqgS-AB2NNT
  LV Write Access        read/write
  LV Creation host, time CentOS.Host1, 2013-08-01 11:33:27 +0800
  LV Status              available
  # open                 1
  LV Size                5.54 GiB
  Current LE             1418
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg_centos/lv_swap
  LV Name                lv_swap
  VG Name                vg_centos
  LV UUID                eT8hdT-CbSj-5Kjx-1lyo-2Ru6-nB5o-fJ0HKU
  LV Write Access        read/write
  LV Creation host, time CentOS.Host1, 2013-08-01 11:33:29 +0800
  LV Status              available
  # open                 1
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               mEQ0cK-I0ja-45yS-fRqy-19Ds-0dr7-1CNFcx
  PV Status             allocatable
  Total PE / Free PE    1922 / 0
   
  PV Name               /dev/sdb     
  PV UUID               03e2Sl-hFVn-NrNr-eHfB-LeuY-D9P0-rSbv0P
  PV Status             allocatable
  Total PE / Free PE    2047 / 2047
 
 
5:扩大逻辑卷(像windows扩大逻辑卷一样):
 
[root@CentOS ~]# lvextend -L +7.9G /dev/vg_centos/lv_root
  Rounding size to boundary between physical extents: 7.90 GiB
  Extending logical volume lv_root to 13.44 GiB
  Logical volume lv_root successfully resized
 
 
6:查看扩容后的LVM
 
[root@CentOS ~]# vgdisplay -v vg_centos
    Using volume group(s) on command line
    Finding volume group "vg_centos"
  --- Volume group ---
  VG Name               vg_centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               15.50 GiB
  PE Size               4.00 MiB
  Total PE              3969
  Alloc PE / Size       3945 / 15.41 GiB
  Free  PE / Size       24 / 96.00 MiB
  VG UUID               6sYdCf-fA3g-Tyjz-lwfr-2hxP-lnFx-eVaMWj
   
  --- Logical volume ---
  LV Path                /dev/vg_centos/lv_root
  LV Name                lv_root
  VG Name                vg_centos
  LV UUID                jjByYP-BlFO-O70G-eYd9-Eupx-wqgS-AB2NNT
  LV Write Access        read/write
  LV Creation host, time CentOS.Host1, 2013-08-01 11:33:27 +0800
  LV Status              available
  # open                 1
  LV Size                13.44 GiB
  Current LE             3441
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg_centos/lv_swap
  LV Name                lv_swap
  VG Name                vg_centos
  LV UUID                eT8hdT-CbSj-5Kjx-1lyo-2Ru6-nB5o-fJ0HKU
  LV Write Access        read/write
  LV Creation host, time CentOS.Host1, 2013-08-01 11:33:29 +0800
  LV Status              available
  # open                 1
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               mEQ0cK-I0ja-45yS-fRqy-19Ds-0dr7-1CNFcx
  PV Status             allocatable
  Total PE / Free PE    1922 / 0
   
  PV Name               /dev/sdb     
  PV UUID               03e2Sl-hFVn-NrNr-eHfB-LeuY-D9P0-rSbv0P
  PV Status             allocatable
  Total PE / Free PE    2047 / 24
 
6:文件系统扩容(注意,这点必须做,因为上面只是空间扩容)
 
[root@CentOS ~]# resize2fs /dev/vg_centos/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_centos/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg_centos/lv_root to 3523584 (4k) blocks.
The filesystem on /dev/vg_centos/lv_root is now 3523584 blocks long.
 
7:查看最后磁盘情况
[root@CentOS ~]# df -h
Filesystem                                            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root                 14G  5.0G  7.7G  40% /
tmpfs                                                    499M  320K  498M   1% /dev/shm
/dev/sda1                                              485M   56M  404M  13% /boot
tmpfs                                                    499M     0  499M   0% /tmp/ram
 

相关内容

    暂无相关文章