CentOS 7 LVM分区硬盘扩容

现有基于KVM的数据库服务器系统盘40G,因需要新增40G数据盘进行分区扩容调整。

[root@SRV205 ~]# df -h #扩容前
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/centos_srv205-root   34G  3.8G   31G  11% /
devtmpfs                        1.9G     0  1.9G   0% /dev
tmpfs                           1.9G     0  1.9G   0% /dev/shm
tmpfs                           1.9G  8.9M  1.9G   1% /run
tmpfs                           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2                       2.0G  145M  1.9G   8% /boot
tmpfs                           379M     0  379M   0% /run/user/1000

[root@SRV205 ~]# fdisk -l 

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004c40d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048        6143        2048   83  Linux
/dev/sda2   *        6144     4200447     2097152   83  Linux
/dev/sda3         4200448    83886079    39842816   8e  Linux LVM

Disk /dev/mapper/centos_srv205-root: 36.5 GB, 36503027712 bytes, 71294976 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/centos_srv205-swap: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@SRV205 ~]# fdisk /dev/sdb #加盘,格式创建新分区
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe055cd83.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-83886079, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079): 
Using default value 83886079
Partition 1 of type Linux and of size 40 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.

[root@SRV205 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004c40d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048        6143        2048   83  Linux
/dev/sda2   *        6144     4200447     2097152   83  Linux
/dev/sda3         4200448    83886079    39842816   8e  Linux LVM

Disk /dev/mapper/centos_srv205-root: 36.5 GB, 36503027712 bytes, 71294976 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/centos_srv205-swap: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe055cd83

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    83886079    41942016   83  Linux

[root@SRV205 ~]# pvcreate /dev/sdb #将新增的分区创建一个物理卷,失败用-ff参数强制创建
  Device /dev/sdb excluded by a filter.

[root@SRV205 ~]# lvs #查看vg名
  LV   VG            Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos_srv205 -wi-ao---- <34.00g                                                    
  swap centos_srv205 -wi-ao----   4.00g                                                    

[root@SRV205 ~]# vgextend centos_srv205 /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created.
  Volume group "centos_srv205" successfully extended

[root@SRV205 ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_srv205
  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               77.99 GiB
  PE Size               4.00 MiB
  Total PE              19966
  Alloc PE / Size       9727 / <38.00 GiB
  Free  PE / Size       10239 / <40.00 GiB
  VG UUID               s5K579-0ZtV-aiJJ-QAkE-x4Kp-Ejhn-kymXcj

[root@SRV205 mapper]# lvextend -l +100%FREE /dev/mapper/centos_srv205-root /dev/sdb1
  Size of logical volume centos_srv205/root changed from <34.00 GiB (8703 extents) to 73.99 GiB (18942 extents).
  Logical volume centos_srv205/root successfully resized.

[root@SRV205 mapper]# xfs_growfs /dev/mapper/centos_srv205-root
meta-data=/dev/mapper/centos_srv205-root isize=512    agcount=4, agsize=2227968 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=8911872, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4351, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 8911872 to 19396608

[root@SRV205 mapper]# df -h #扩容后
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/centos_srv205-root   74G  3.8G   71G   6% /
devtmpfs                        1.9G     0  1.9G   0% /dev
tmpfs                           1.9G     0  1.9G   0% /dev/shm
tmpfs                           1.9G  8.9M  1.9G   1% /run
tmpfs                           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2                       2.0G  145M  1.9G   8% /boot
tmpfs                           379M     0  379M   0% /run/user/1000
上一篇
下一篇