centos系统xfs系统盘lvm扩容

前情提要:备份数据,备份数据,备份数据

当前系统磁盘挂载情况

[root@db2 tmpuser]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/center-root   14G  2.1G   12G  16% /
devtmpfs              16G     0   16G   0% /dev
tmpfs                 16G     0   16G   0% /dev/shm
tmpfs                 16G  8.5M   16G   1% /run
tmpfs                 16G     0   16G   0% /sys/fs/cgroup
/dev/sda1           1014M  138M  877M  14% /boot
tmpfs                3.2G     0  3.2G   0% /run/user/1000

查看当前文件系统树状信息

[root@db2 tmpuser]# lsblk  -f
NAME        FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                  
├─sda1      xfs               f3e7dd36-9501-4c90-9449-5fed5ace62a3   /boot
└─sda2      LVM2_member       PGTG3k-7LUa-6TlF-oOBx-RIu6-71dB-R3yoL1 
  ├─center-root xfs               bd3b1947-6db4-4546-9008-fffcc6f1c9e1   /
  └─center-swap swap              d3d9c5ef-e552-4b1f-8107-8a3aad03d731   [SWAP]
sr0

我们需要扩展系统盘,可以看到系统/ 路径挂在/dev/sda2上,所以需要先对sda2重新进行分区,分区时务必注意起始的扇区位置和之前保持一致

[root@db2 tmpuser]#  fdisk /dev/sda
WARNING: The size of this disk is 2.7 TB (2684354560000 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 
partition table format (GPT).

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.


Command (m for help): p

Disk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 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: 0x00024d66

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): p

Disk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 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: 0x00024d66

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux

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

Command (m for help): t
Partition number (1,2, default 2): 
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 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: 0x00024d66
**加粗样式**
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   180357119    89128960   8e  Linux LVM

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

同步分区表,这里报错说旧的分区正在使用,我们应该重启再进行后续操作

[root@db2 tmpuser]# partprobe 

Error: Partition(s) 2 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
[root@db2 tmpuser]# reboot

[root@db2 tmpuser]# partprobe           ##同步分区表

如果没有报错说明分区表同步成功,接下来进行LVM扩容,pvs查看,pv的大小并没有发生变化,因此我们需要使用pvresize命令重置pv大小

[root@db2 tmpuser]# pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sda2  center lvm2 a--  <15.00g    0 
[root@db2 tmpuser]#  pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@db2 tmpuser]# pvs   ##此时pv大小已改变
  PV         VG Fmt  Attr PSize   PFree 
  /dev/sda2  center lvm2 a--  <85.00g 70.00g

##执行vg时报错,根据报错/dev/sda2已经在VG 逻辑卷组中,(分析:VG一旦创建,会自动管理/dev/sda2中的PE单元,即使扩缩容,自己的理解,懂得大神可以评论区说明下,谢谢)

[root@db2 tmpuser]# vgextend center  /dev/sda2   
   Physical volume '/dev/sda2' is already in volume group 'center'
   Unable to add physical volume '/dev/sda2' to volume group 'center'
  /dev/sda2: physical volume not initialized.

既然已经存在,接下来直接进行LV扩展

[root@db2 tmpuser]#  lvextend -l 100%FREE  /dev/center/root      ##扩展LV
  Size of logical volume center/root changed from 13.39 GiB (3429 extents) to 70.00 GiB (17920 extents).
  Logical volume center/root successfully resized.

扩展文件系统 如果是ext4格式用resize2fs /dev/mapper/center-root

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

查看挂载情况,已经扩容成功

[root@db2 tmpuser]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/center-root   70G  2.1G   68G   3% /
devtmpfs              16G     0   16G   0% /dev
tmpfs                 16G     0   16G   0% /dev/shm
tmpfs                 16G  8.5M   16G   1% /run
tmpfs                 16G     0   16G   0% /sys/fs/cgroup
/dev/sda1           1014M  138M  877M  14% /boot
tmpfs                3.2G     0  3.2G   0% /run/user/1000
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值