22. LVM实际应用:扩容LV

 用LVM扩展系统的 /home 分区

(1)扩容前,/home 分区只有455MB

​​​​[root@localhost ~]# lsblk -f
NAME            FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda
├─sda1          xfs                         9be4187c-0d1e-40e9-b858-9e19a6b93445   /boot
└─sda2          LVM2_member                 jFYd2k-mpJ3-vfX3-NCnp-GGiB-KfEt-p5oyNO
  ├─centos-root xfs                         929eb6b2-1a4b-4271-83f5-962f573954a7   /
  ├─centos-swap swap                        7ca240cd-fc22-4efe-9d4d-2bbce981a464   [SWAP]
  └─centos-home xfs                         bce8fb0d-6907-433d-b682-5f67626ca380   /home
sdb
sr0             iso9660     CentOS 7 x86_64 2020-11-04-11-36-43-00

 (2)准备工作:

1)首先在虚拟机设置里面添加任意大小的磁盘(硬盘)

使用 fdisk -l 命令可查看我们添加的磁盘是 /dev/sdb (根据本机的情况按照字母顺序排序的)

[root@localhost ~]# lsblk -f
NAME            FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda
├─sda1          xfs                         9be4187c-0d1e-40e9-b858-9e19a6b93445   /boot
└─sda2          LVM2_member                 jFYd2k-mpJ3-vfX3-NCnp-GGiB-KfEt-p5oyNO
  ├─centos-root xfs                         929eb6b2-1a4b-4271-83f5-962f573954a7   /
  ├─centos-swap swap                        7ca240cd-fc22-4efe-9d4d-2bbce981a464   [SWAP]
  └─centos-home xfs                         bce8fb0d-6907-433d-b682-5f67626ca380   /home
sdb
sr0             iso9660     CentOS 7 x86_64 2020-11-04-11-36-43-00

 2)其次对sdb进行分区:fdisk /dev/sdb

分区:(对整个sdb)
[root@localhost ~]# 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 0x1dcfef12.

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-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):
Using default value 2097151
Partition 1 of type Linux and of size 1023 MiB is set

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x1dcfef12

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2097151     1047552   83  Linux

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

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

3)格式化(xfs格式):mkfs.xfs /dev/sdb1

格式化
[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65472 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=261888, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

4)最后使用partx /dev/sdb1 或者 partprobe加载到内核

[root@localhost ~]# partx /dev/sdb1
NR START     END SECTORS  SIZE NAME UUID
 1  2048 2097151 2095104 1023M

(3)把刚才新加的硬盘创建为物理卷:pvcreate /dev/sdb1

[root@localhost ~]# pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize    PFree
  /dev/sda2  centos lvm2 a--    19.53g    8.00m
  /dev/sdb1         lvm2 ---  1023.00m 1023.00m

(4)查看卷组,把物理卷添加到卷组里:vgextend centos /dev/sdb1

原因:逻辑卷/home 本就在centos卷组里面

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   3   0 wz--n- 19.53g 8.00m
[root@localhost ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   2   3   0 wz--n- <20.53g 1.00g

发现centos的VG卷组里增加了1G

(5)将VG卷组新增空余的空间(1G)全部扩容到 /home 里面,即扩容LV。(注意,可按照自己需求增加百分比)

lvextend -l +100%FREE /dev/mapper/centos-home

[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao---- 476.00m
  root centos -wi-ao---- <17.06g
  swap centos -wi-ao----   2.00g
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-home
  Size of logical volume centos/home changed from 476.00 MiB (119 extents) to <1.47 GiB (376 extents).
  Logical volume centos/home successfully resized.
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao----  <1.47g
  root centos -wi-ao---- <17.06g
  swap centos -wi-ao----   2.00g

发现/home 里面已经增加了1G的存储空间

(6)扩容文件系统:xfs_growfs /dev/mapper/centos-home

[root@localhost ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  470M     0  470M   0% /dev
tmpfs                   tmpfs     487M     0  487M   0% /dev/shm
tmpfs                   tmpfs     487M  8.4M  478M   2% /run
tmpfs                   tmpfs     487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        18G  4.6G   13G  27% /
/dev/sda1               xfs       473M  164M  310M  35% /boot
/dev/mapper/centos-home xfs       473M   29M  445M   6% /home
tmpfs                   tmpfs      98M   12K   98M   1% /run/user/42
tmpfs                   tmpfs      98M     0   98M   0% /run/user/0
[root@localhost ~]# xfs_growfs /dev/mapper/c
centos-home  centos-root  centos-swap  control
[root@localhost ~]# xfs_growfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512    agcount=4, agsize=30464 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=121856, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 121856 to 385024
[root@localhost ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  470M     0  470M   0% /dev
tmpfs                   tmpfs     487M     0  487M   0% /dev/shm
tmpfs                   tmpfs     487M  8.4M  478M   2% /run
tmpfs                   tmpfs     487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        18G  4.7G   13G  27% /
/dev/sda1               xfs       473M  164M  310M  35% /boot
/dev/mapper/centos-home xfs       1.5G   29M  1.5G   2% /home
tmpfs                   tmpfs      98M   12K   98M   1% /run/user/42
tmpfs                   tmpfs      98M     0   98M   0% /run/user/0

发现/home 的文件系统相比之前增加了1G

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值