linux下如何增加LVM磁盘空间

根文件系统快用完了,给你一块新硬盘,怎样实现根文件系统扩容?这是面试中经常会出现的一个问题。接下来,我们就在虚拟机里面做一下这个试验。

1、试验环境

物理机:Windows XP
虚拟机:VMware 7
虚拟系统:RHEL 4

2、当前的磁盘使用情况

三块SCSI虚拟硬盘,每个8G,总共24G。一个卷组VolGroup00,分成两个逻辑卷,LogVol00作为根文件系统,LogVol01作为swap。

[root@Shell_HAT]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       20G   17G  1.9G  91% /
/dev/sda1              99M  9.0M   85M  10% /boot
none                  506M     0  506M   0% /dev/shm


LVM添加硬盘和扩容

    测试环境:CentOS7 64位(KVM虚拟机)

    LVM版本:lvm2-2.02.105-14.el7.x86_64

    1、添加一块硬盘(8GB)到系统中

wKioL1UCppmhSdIjAAKV8ioaU_8847.jpg

    使用 fdisk -l 查看到这块新盘为/dev/vdb:

1
shell # fdisk -l

wKiom1UCpifTBblUAAQ82M1Bf5g201.jpg

    2、对新盘分区

    使用 fdisk 命令对新盘进行分区,这里建立了一个主分区/dev/vdb1,大小8GB,最后使用 partprobe 命令重新读取分区表:

1
2
shell # fdisk /dev/vdb
shell # partprobe

wKioL1UCp5GxyGZaAA4mZCbd6zI957.jpg

    在分区的过程中,注意设置格式为8e,这是LVM的分区格式。



[root@Shell_HAT]# ls -l /dev/sd*
brw-rw----  1 root disk 8,  0 Mar 11  2012 /dev/sda
brw-rw----  1 root disk 8,  1 Mar 11  2012 /dev/sda1
brw-rw----  1 root disk 8,  2 Mar 11  2012 /dev/sda2
brw-rw----  1 root disk 8, 16 Mar 11  2012 /dev/sdb
brw-rw----  1 root disk 8, 17 Mar 11  2012 /dev/sdb1
brw-rw----  1 root disk 8, 32 Mar 11  2012 /dev/sdc
brw-rw----  1 root disk 8, 33 Mar 11  2012 /dev/sdc1


[root@Shell_HAT]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898   8e  Linux LVM

Disk /dev/sdc: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1044     8385898   8e  Linux LVM


[root@Shell_HAT]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  17
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               23.81 GB
  PE Size               32.00 MB
  Total PE              762
  Alloc PE / Size       760 / 23.75 GB
  Free  PE / Size       2 / 64.00 MB
  VG UUID               djJXj5-3rkx-PEpi-2OJn-ZofS-VaF6-KUo9UR


[root@Shell_HAT]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                kOehzE-SEAQ-tm3L-jIkG-gbZv-YWC5-apQWWf
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                19.81 GB
  Current LE             634
  Segments               4
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                vI2EKQ-5tne-heGk-bbkL-9K6g-23fs-b9e3Y4
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                3.94 GB
  Current LE             126
  Segments               2
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:1


[root@Shell_HAT]# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /dev/shm                tmpfs   defaults        0 0
none                    /proc                   proc    defaults        0 0
none                    /sys                    sysfs   defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0


3、在VMware里面新增一块SCSI虚拟硬盘

确认虚拟系统RHEL4处于关机状态,用VMware打开Red Hat Enterprise Linux 4.vmx,点击Edit virtual machine setings,点击Add按钮,选中Hard Disk,点击Next按钮,选中Create a new virtual disk,点击Next按钮,选中SCSI,点击Next按钮,设置Maximum disk size为8,点击Next按钮,点击Finish按钮,点击OK按钮,启动虚拟系统RHEL4。

4、根文件系统扩容

用一句话来总结:创建物理卷 >>> 卷组扩容 >>> 逻辑卷扩容 >>> 文件系统扩容

(1)创建物理卷

[root@Shell_HAT]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created

(2)查看创建好的物理卷

[root@Shell_HAT]# pvdisplay /dev/sdd
  --- NEW Physical volume ---
  PV Name               /dev/sdd
  VG Name
  PV Size               8.00 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               5ne1Nx-bsCO-9Vxh-6Pmc-rBnf-dsZo-WjQDYS


(3)卷组扩容

[root@Shell_HAT]# vgextend VolGroup00 /dev/sdd
  Volume group "VolGroup00" successfully extended

(4)查看扩容之后的卷组信息

[root@Shell_HAT]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  18
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               31.78 GB
  PE Size               32.00 MB
  Total PE              1017
  Alloc PE / Size       760 / 23.75 GB
  Free  PE / Size       257 / 8.03 GB
  VG UUID               djJXj5-3rkx-PEpi-2OJn-ZofS-VaF6-KUo9UR


(5)逻辑卷扩容

[root@Shell_HAT]# lvextend -L+8G /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 27.81 GB
  Logical volume LogVol00 successfully resized


(6)查看扩容之后的逻辑卷

[root@Shell_HAT]# lvdisplay /dev/VolGroup00/LogVol00
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                kOehzE-SEAQ-tm3L-jIkG-gbZv-YWC5-apQWWf
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                27.81 GB
  Current LE             890
  Segments               5
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0


(7)文件系统在线扩容

[root@Shell_HAT]# resize2fs /dev/VolGroup00/LogVol00
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b

(8)大功告成

[root@Shell_HAT]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       28G   17G  9.4G  65% /
/dev/sda1              99M  9.0M   85M  10% /boot
none                  506M     0  506M   0% /dev/shm










本文转自 bobo5900pro  51CTO博客,原文链接:http://blog.51cto.com/bobo5900pro/1702160,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值