Linux lvm分区扩容、给sda2扩容

初始创建服务器未将所有磁盘空间进行分配,数据目录、swap需要扩容

[root@yhcs /]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  600G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part 
  ├─centos-root 253:0    0   40G  0 lvm  /
  ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
  └─centos-data 253:2    0 51.1G  0 lvm  /data
sr0              11:0    1 1024M  0 rom  

[root@yhcs /]# fdisk /dev/sda
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (209715200-1258291199, default 209715200): 
Using default value 209715200
Last sector, +sectors or +size{K,M,G} (209715200-1258291199, default 1258291199): 
Using default value 1258291199
Partition 3 of type Linux and of size 500 GiB is set

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

[root@yhcs webapps]# partprobe
[root@yhcs webapps]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  600G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   99G  0 part 
│ ├─centos-root 253:0    0   40G  0 lvm  /
│ ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
│ └─centos-data 253:2    0 51.1G  0 lvm  /data
└─sda3            8:3    0  500G  0 part 
sr0              11:0    1 1024M  0 rom  
[root@yhcs webapps]# pvcreate /dev/sda3    #创建物理卷
  Physical volume "/dev/sda3" successfully created.
[root@yhcs webapps]# pvs                   #查看物理卷
  PV         VG     Fmt  Attr PSize   PFree  
  /dev/sda2  centos lvm2 a--  <99.00g   8.00m
  /dev/sda3         lvm2 ---  500.00g 500.00g

[root@yhcs webapps]# partprobe             #重新加载分区表     
[root@yhcs webapps]# vgextend centos /dev/sda3     #向卷组中添加物理卷来增加卷组的容量
  Volume group "centos" successfully extended
[root@yhcs webapps]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  600G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   99G  0 part 
│ ├─centos-root 253:0    0   40G  0 lvm  /
│ ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
│ └─centos-data 253:2    0 51.1G  0 lvm  /data
└─sda3            8:3    0  500G  0 part 
sr0              11:0    1 1024M  0 rom  
[root@yhcs webapps]# pvdisplay             查看卷组信息
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <99.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25343
  Free PE               2
  Allocated PE          25341
  PV UUID               JxGLDc-yWyX-nXI1-0LXr-UO5E-fYB3-dTrRLT
   
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               500.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              127999
  Free PE               127999
  Allocated PE          0
  PV UUID               4USdXd-hRFa-naJ8-KNaU-dZjH-m0hC-qrIKGY
   
[root@yhcs webapps]#  lvextend -L +60G /dev/mapper/centos-root     #扩展逻辑卷的大小
  Size of logical volume centos/root changed from 40.00 GiB (10240 extents) to 100.00 GiB (25600 extents).
  Logical volume centos/root successfully resized.
[root@yhcs webapps]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  600G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   99G  0 part 
│ ├─centos-root 253:0    0  100G  0 lvm  /
│ ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
│ └─centos-data 253:2    0 51.1G  0 lvm  /data
└─sda3            8:3    0  500G  0 part 
  └─centos-root 253:0    0  100G  0 lvm  /
sr0              11:0    1 1024M  0 rom  
[root@yhcs webapps]#  lvextend -L +8G /dev/mapper/centos-swap
  Size of logical volume centos/swap changed from <7.88 GiB (2016 extents) to <15.88 GiB (4064 extents).
  Logical volume centos/swap successfully resized.
  
[root@yhcs webapps]#  lvextend -l +100%FREE /dev/mapper/centos-data   #将剩余空间扩展给逻辑卷
  Size of logical volume centos/data changed from 51.11 GiB (13085 extents) to <483.12 GiB (123678 extents).
  Logical volume centos/data successfully resized.
You have new mail in /var/spool/mail/root

[root@yhcs webapps]# xfs_growfs /dev/mapper/centos-root   #刷新分区,如果是 ext4 文件系统(包括 2、3),使用 resize2fs 命令

[root@yhcs webapps]# xfs_growfs /dev/mapper/centos-data

[root@yhcs webapps]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  100G  7.7G   93G   8% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  186M  3.7G   5% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/centos-data  484G   38G  446G   8% /data
/dev/sda1               1014M  142M  873M  14% /boot
tmpfs                    783M     0  783M   0% /run/user/0
172.27.119.146:/aaa/epg  8.0T  3.1T  5.0T  39% /data/epgms_static
[root@yhcs webapps]# free -m
              total        used        free      shared  buff/cache   available
Mem:           7820        2504         137         101        5178        4833
Swap:          8063         317        7746
You have new mail in /var/spool/mail/root

[root@yhcs webapps]# swapoff /dev/mapper/centos-swap      
[root@yhcs webapps]# mkswap /dev/mapper/centos-swap       #格式化swap分区
[root@yhcs webapps]# mkswap  -f /dev/mapper/centos-swap   # 强制执行操作设置交换分区
mkswap: /dev/mapper/centos-swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 16646140 KiB
no label, UUID=00e752d3-e823-40b5-b19f-63c6244bad23
[root@yhcs webapps]# swapon /dev/mapper/centos-swap
[root@yhcs webapps]# free -m
              total        used        free      shared  buff/cache   available
Mem:           7820        2705         130         185        4985        4549
Swap:         16255           0       16255
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值