Linux “/“ 分区扩容

转载自:https://blog.csdn.net/zyqash/article/details/123685343

前言

扩容是一项很简单的工作,但是有时候因为长时间没有操作过扩容,指令会比较生疏,因此写一篇扩容的文档,方便在再次失忆的情况下能快速回忆起操作流程。

逻辑卷扩容的流程:创建PV-->扩容VG-->扩容LV。

以下是扩容的详细流程。

1、查看当前 / 分区大小


  
  
  1. [root @rt7_node03 ~] # df -Th
  2. Filesystem Type Size Used Avail Use% Mounted on
  3. /dev/mapper /cl-root xfs 7.1G 1.2G 6.0G 16% /
  4. devtmpfs devtmpfs 486M 0 486M 0% /dev
  5. tmpfs tmpfs 496M 0 496M 0% /dev /shm
  6. tmpfs tmpfs 496M 6.7M 490M 2% /run
  7. tmpfs tmpfs 496M 0 496M 0% /sys/fs /cgroup
  8. /dev /vda1 xfs 1014M 139M 876M 14% /boot
  9. tmpfs tmpfs 100M 0 100M 0% /run/user /0

2、添加一块磁盘,查看新磁盘的大小


  
  
  1. [root@rt7_node03 ~] # lsblk
  2. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  3. sr 0 11: 0 1 1024M 0 rom
  4. vda 252: 0 0 9G 0 disk
  5. |-vda1 252: 1 0 1G 0 part /boot
  6. `-vda2 252:2 0 8G 0 part
  7. |-cl-swap 253:0 0 924M 0 lvm [SWAP]
  8. `-cl-root 253: 1 0 7.1G 0 lvm /
  9. vdb 252: 16 0 20G 0 disk

3、给新磁盘分区


  
  
  1. [ root@rt7_node03 ~] # fdisk /dev/vdb
  2. Welcome to fdisk (util-linux 2.23.2).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. Device does not contain a recognized partition table
  6. Building a new DOS disklabel with disk identifier 0x67c61676.
  7. Command (m for help): n
  8. Partition type:
  9. p primary (0 primary, 0 extended, 4 free)
  10. e extended
  11. Select (default p):
  12. Using default response p
  13. Partition number (1-4, default 1):
  14. First sector (2048-41943039, default 2048):
  15. Using default value 2048
  16. Last sector, +sectors or +size{K,M,G} ( 2048 -41943039, default 41943039):
  17. Using default value 41943039
  18. Partition 1 of type Linux and of size 20 GiB is set
  19. Command (m for help): w
  20. The partition table has been altered!
  21. Calling ioctl() to re-read partition table.
  22. Syncing disks.
  23. [root@rt7_node03 ~]# lsblk
  24. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  25. sr0 11:0 1 1024M 0 rom
  26. vda 252:0 0 9G 0 disk
  27. |-vda1 252:1 0 1G 0 part /boot
  28. `-vda2 252:2 0 8G 0 part
  29. |-cl-swap 253:0 0 924M 0 lvm [SWAP]
  30. `-cl-root 253:1 0 7.1G 0 lvm /
  31. vdb 252:16 0 20G 0 disk
  32. `-vdb1 252:17 0 20G 0 part

4、安装所需的软件包

[root@rt7_node03 ~]# yum install -y lvm2-2.02.166-1.el7.x86_64

  
  

5、创建pv物理卷


  
  
  1. [root @rt7_node03 ~] # pvcreate /dev/vdb1
  2. Physical volume "/dev/vdb1" successfully created.

6、查看新创建的物理卷


  
  
  1. [root @rt7_node03 ~]# pvdisplay
  2. --- Physical volume ---
  3. PV Name /dev /vda2
  4. VG Name cl
  5. PV Size 8.00 GiB / not usable 3.00 MiB
  6. Allocatable yes (but full)
  7. PE Size 4.00 MiB
  8. Total PE 2047
  9. Free PE 0
  10. Allocated PE 2047
  11. PV UUID KToRtg -Mwyz -bkxt -Erln -a5Ro -HJDw -orTvQo
  12. "/dev/vdb1" is a new physical volume of "20.00 GiB"
  13. --- NEW Physical volume ---
  14. PV Name /dev /vdb1
  15. VG Name
  16. PV Size 20.00 GiB
  17. Allocatable NO
  18. PE Size 0
  19. Total PE 0
  20. Free PE 0
  21. Allocated PE 0
  22. PV UUID po26cZ -PVjR -NZxG -UkDw -wzcC -yJ7z -EnXlGa

7、查看VG


  
  
  1. [root @rt7_node03 ~]# vgdisplay
  2. --- Volume group ---
  3. VG Name cl
  4. System ID
  5. Format lvm2
  6. Metadata Areas 1
  7. Metadata Sequence No 3
  8. VG Access read /write
  9. VG Status resizable
  10. MAX LV 0
  11. Cur LV 2
  12. Open LV 2
  13. Max PV 0
  14. Cur PV 1
  15. Act PV 1
  16. VG Size 8.00 GiB
  17. PE Size 4.00 MiB
  18. Total PE 2047
  19. Alloc PE / Size 2047 / 8.00 GiB
  20. Free PE / Size 0 / 0
  21. VG UUID U8mInR -Xnzq -hTka -AE2D -Y5fV -r3Qx -LLbdi9
  22. [root @rt7_node03 ~]# vgs
  23. VG #PV #LV #SN Attr VSize VFree
  24. cl 1 2 0 wz --n- 8.00g 0

8、扩展VG


  
  
  1. [ root@rt7_node03 ~] # vgextend cl /dev/vdb1
  2. Volume group "cl" successfully extended

9、查看VG


  
  
  1. [root @rt7_node03 ~]# vgs
  2. VG #PV #LV #SN Attr VSize VFree
  3. cl 2 2 0 wz --n- 27.99g 20.00g
  4. [root @rt7_node03 ~]# vgdisplay
  5. --- Volume group ---
  6. VG Name cl
  7. System ID
  8. Format lvm2
  9. Metadata Areas 2
  10. Metadata Sequence No 4
  11. VG Access read /write
  12. VG Status resizable
  13. MAX LV 0
  14. Cur LV 2
  15. Open LV 2
  16. Max PV 0
  17. Cur PV 2
  18. Act PV 2
  19. VG Size 27.99 GiB
  20. PE Size 4.00 MiB
  21. Total PE 7166
  22. Alloc PE / Size 2047 / 8.00 GiB
  23. Free PE / Size 5119 / 20.00 GiB
  24. VG UUID U8mInR -Xnzq -hTka -AE2D -Y5fV -r3Qx -LLbdi9

10、查看LV


  
  
  1. [root @rt7_node03 ~]# lvs
  2. LV VG Attr LSize Pool Origin Data % Meta % Move Log Cpy %Sync Convert
  3. root cl -wi -ao ---- 7.09g
  4. swap cl -wi -ao ---- 924.00m

11、扩展LV


  
  
  1. [ root@rt7_node03 ~] # lvextend -L +19G /dev/cl/root
  2. Size of logical volume cl/root changed from 7.09 GiB ( 1816 extents) to 26.09 GiB ( 6680 extents).
  3. Logical volume cl/root successfully resized.

12、使用xfs_growfs命令使扩容生效


  
  
  1. [root@rt7_node03 ~]# xfs_growfs /dev/cl/root
  2. meta- data=/dev/mapper/cl-root isize=512 agcount=4, agsize=464896 blks
  3. = sectsz= 512 attr= 2, projid32bit= 1
  4. = crc= 1 finobt= 0 spinodes= 0
  5. data = bsize=4096 blocks=1859584, imaxpct=25
  6. = sunit= 0 swidth= 0 blks
  7. naming =version 2 bsize= 4096 ascii-ci= 0 ftype= 1
  8. log =internal bsize= 4096 blocks= 2560, version= 2
  9. = sectsz= 512 sunit= 0 blks, lazy-count= 1
  10. realtime =none extsz= 4096 blocks= 0, rtextents= 0
  11. data blocks changed from 1859584 to 6840320

13、查看 / 分区的大小


  
  
  1. [root @rt7_node03 ~] # df -Th
  2. Filesystem Type Size Used Avail Use% Mounted on
  3. /dev/mapper /cl-root xfs 27G 1.2G 25G 5% /
  4. devtmpfs devtmpfs 486M 0 486M 0% /dev
  5. tmpfs tmpfs 496M 0 496M 0% /dev /shm
  6. tmpfs tmpfs 496M 6.7M 490M 2% /run
  7. tmpfs tmpfs 496M 0 496M 0% /sys/fs /cgroup
  8. /dev /vda1 xfs 1014M 139M 876M 14% /boot
  9. tmpfs tmpfs 100M 0 100M 0% /run/user /0

可以看到 / 分区已新增了19G。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值