Centos新添加硬盘LVM扩容

2016/4/9 14:11 下午 目录  Linux 评论

一、为centos添加一块硬盘

1.用fdisk -l 查看硬盘情况:

[root@webserver77 ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

磁盘 /dev/vda:8589 MB, 8589934592 字节,16777216 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:gpt


#         Start          End    Size  Type            Name
 1           34     16777182      8G  Microsoft basic vda1

磁盘 /dev/vdb:8589 MB, 8589934592 字节,16777216 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

可以看到我们添加了一块8G的硬盘

2.给硬盘格式化和分区(添加2T以上的硬盘,格式化为GPT格式):

[root@webserver77 ~]# parted /dev/vdb
GNU Parted 3.1
使用 /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
(parted) mkpart primary 0 -1                                              
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? Ignore                                           
(parted) print                                                            
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     标志
 1      17.4kB  8589MB  8589MB               primary

8G全部分到同一个主分区

二、给逻辑分区扩容

1.添加物理卷

[root@webserver77 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@webserver77 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               99.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              25473
  Free PE               0
  Allocated PE          25473
  PV UUID               fGIG8r-3EPC-mgAe-pT1m-6eLp-XP2E-2HfXaE
   
  --- Physical volume ---
  PV Name               /dev/vda1
  VG Name               centos
  PV Size               8.00 GiB / not usable 3.97 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2047
  Free PE               0
  Allocated PE          2047
  PV UUID               ATS22N-kmWz-wvbB-5jhN-UX8n-CDvA-nASxic
   
  "/dev/vdb1" is a new physical volume of "8.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vdb1
  VG Name               
  PV Size               8.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               cPNqEl-vgJj-KhKc-a7EP-ImLG-tOre-0uMzq3

2.把物理卷添加到卷组,给卷组扩容

[root@webserver77 ~]# vgdisplay
  --- Volume group ---
  VG Name               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               107.50 GiB
  PE Size               4.00 MiB
  Total PE              27520
  Alloc PE / Size       27520 / 107.50 GiB
  Free  PE / Size       0 / 0   
  VG UUID               jrMtCq-BcTL-qJE5-Kawe-okl1-j2UY-0A7c4t
   
[root@webserver77 ~]# vgextend centos /dev/vdb1
  Volume group "centos" successfully extended
[root@webserver77 ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  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               115.50 GiB
  PE Size               4.00 MiB
  Total PE              29567
  Alloc PE / Size       27520 / 107.50 GiB
  Free  PE / Size       2047 / 8.00 GiB
  VG UUID               jrMtCq-BcTL-qJE5-Kawe-okl1-j2UY-0A7c4t

3.给逻辑卷扩容

[root@webserver77 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                il91uC-8x7e-TH20-H39Y-DCs0-LBer-0O22HC
  LV Write Access        read/write
  LV Creation host, time localhost, 2015-12-16 16:57:30 +0800
  LV Status              available
  # open                 1
  LV Size                105.5 GiB
  Current LE             27522
  Segments               4
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                lX5t4r-nl7c-f7TT-sKaD-5Adg-wc7F-xN90c0
  LV Write Access        read/write
  LV Creation host, time localhost, 2015-12-16 16:57:30 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
 
   
[root@webserver77 ~]# lvextend -L +8GiB /dev/centos/root
 Size of logical volume centos/root changed from 105.50 GiB to 113.50 GiB .
 Logical volume root successfully resized

此时根分区容量依然没有变化

三、给XFS文件系统扩容

使用xfs_growfs扩展分区,如果你不使用“-D”选项来指定大小,xfs_growfs将会自动扩展XFS文件系统到最大的可用大小。

[root@webserver77 ~]# df -h
文件系统                                容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root                 106G  7.4G   99G    8% /
devtmpfs                                992M     0  992M    0% /dev
tmpfs                                  1001M     0 1001M    0% /dev/shm
tmpfs                                  1001M   65M  937M    7% /run
tmpfs                                  1001M     0 1001M    0% /sys/fs/cgroup
/dev/sda1                               497M  102M  395M   21% /boot
192.168.199.137:/var/local/exports/iso  106G  7.4G   99G    8% /var/lib/libvirt/images/iso
[root@webserver77 ~]# xfs_growfs /dev/mapper/centos-root 
meta-data=/dev/mapper/centos-root isize=256    agcount=5, agsize=6389760 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=27656192, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=12480, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 27656192 to 29752320
[root@webserver77 ~]# df -h
文件系统                                容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root                 114G  7.4G  107G    7% /
devtmpfs                                992M     0  992M    0% /dev
tmpfs                                  1001M     0 1001M    0% /dev/shm
tmpfs                                  1001M   65M  937M    7% /run
tmpfs                                  1001M     0 1001M    0% /sys/fs/cgroup
/dev/sda1                               497M  102M  395M   21% /boot
192.168.199.137:/var/local/exports/iso  114G  7.4G  107G    7% /var/lib/libvirt/images/iso

至此,根分区扩展成功。