LVM磁盘在线扩容

参考:http://blog.csdn.net/naruto2011sasuke/article/details/50459117
需求,本来服务器挂载在home下面只有200G 现在将其扩充到500G 以满足业务需求,
首先将在将服务器的磁盘 扩充到500G 然后再到服务端操作:
具体操作

1. 初始状态

[

root@localhost ~]# fdisk -l

Disk /dev/xvda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x0005b130

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       39163   314059776   8e  Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

可以看到新加的磁盘空间已经可以看到,我们将其多的空间全部挂载到home下面去

2. 分区

将其多余的空间划分到xvda3

[root@localhost ~]# fdisk /dev/xvda

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

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (39163-65270, default 39163):
Using default value 39163
Last cylinder, +cylinders or +size{K,M,G} (39163-65270, default 65270):
Using default value 65270

Command (m for help): p

Disk /dev/xvda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x0005b130

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       39163   314059776   8e  Linux LVM
/dev/xvda3           39163       65270   209708475   83  Linux

Command (m for help): w
The partition table has been altered!

此时 可以看到分区已经分好了:

[root@localhost ~]# fdisk -l

Disk /dev/xvda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x0005b130

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       39163   314059776   8e  Linux LVM
/dev/xvda3           39163       65270   209708475   83  Linux

3. PV阶段

现在的xvda3还不是lvm, 所以执行pvcreate /dev/xvda3
查看xvda3使用情况:

[root@localhost ~]# pvs
  PV         VG       Fmt  Attr PSize   PFree
  /dev/xvda2 VolGroup lvm2 a--u 299.51g      0
  /dev/xvda3          lvm2 ---- 199.99g 199.99g

查看主分区磁盘

[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  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               299.51 GiB
  PE Size               4.00 MiB
  Total PE              76674
  Alloc PE / Size       76674 / 299.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               rSmKgF-EtfI-1ceP-DdJT-ggP3-xVtO-gDOs72

扩容 该磁盘:

[root@localhost ~]# vgextend VolGroup /dev/xvda3
 提示成功:Volume group "VolGroup" successfully extended

5. resize阶段

查看具体挂着点使用情况:

[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                56pQv3-mzU8-DM0t-4jRJ-0vBb-ys30-ArIGvV
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2018-01-21 23:25:19 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_home
  LV Name                lv_home

我们需要的是扩容 home 这个挂载点
输入扩容命令:

[root@localhost ~]# lvextend -l +100%FREE /dev/VolGroup/lv_home
[root@localhost ~]# resize2fs -p -F /dev/VolGroup/lv_home

稍等片刻 df -h 查看:

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  687M   46G   2% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/xvda1            477M   28M  425M   7% /boot
/dev/mapper/VolGroup-lv_home
                      439G   71M  417G   1% /home
[root@localhost ~]#

扩容成功!

扫描二维码关注公众号,回复: 1095802 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_25611295/article/details/79399996
今日推荐