举例1:(新增块设备)
前提:磁盘已有内存900G,因业务需要,需增加1T内存
[root@hrmw-db-01 /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/lhxt-data 900G 821G 79G 92% /u01
一、lsblk 查看系统中的所有块设备,查看磁盘情况
[root@hrmw-db-01 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 128G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 127G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]
└─centos-home 253:3 0 69.1G 0 lvm /home
sdb 8:16 0 900G 0 disk
└─sdb1 8:17 0 900G 0 part
└─lhxt-data 253:2 0 900G 0 lvm /u01
sdc 8:32 0 1T 0 disk
sr0 11:0 1 1024M 0 rom
此时显示sdc有新增1T的内存
二、创建物理卷:pvcreate 物理卷名
[root@hrmw-db-01 /]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created.
[root@hrmw-db-01 /]# pvdisplay
"/dev/sdc" is a new physical volume of "1.00 TiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 1.00 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID IQzw5b-eEM8-rHgo-x0BE-m59R-wUdM-ARa5Il
三、将新建物理卷加到要加的磁盘卷组中:vgextend 卷组名 物理卷名
vgdisplay 确定卷组名字(VG name)
[root@hrmw-db-01 /]# vgdisplay
--- Volume group ---
VG Name lhxt
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <900.00 GiB
PE Size 4.00 MiB
Total PE 230399
Alloc PE / Size 230399 / <900.00 GiB
Free PE / Size 0 / 0
VG UUID HHGc5C-bQ8n-3FU7-uxXW-PJVh-duxa-xlctRk
[root@hrmw-db-01 /]# vgextend lhxt /dev/sdc
Volume group "lhxt" successfully extended
四、多余空间加到要加的逻辑卷中:lvextend -l +100%FREE 逻辑卷名
lvdisplay 确定逻辑卷名字 (LV Path)
[root@hrmw-db-01 /]# lvdisplay
--- Logical volume ---
LV Path /dev/lhxt/data
LV Name data
VG Name lhxt
LV UUID TfdMDP-VO5I-qOgb-8i0v-VbZG-kzVP-W5i1HM
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-05-09 09:26:42 +0800
LV Status available
# open 1
LV Size <900.00 GiB
Current LE 230399
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
[root@hrmw-db-01 /]# lvextend -l +100%FREE /dev/lhxt/data
Size of logical volume lhxt/data changed from <900.00 GiB (230399 extents) to <1.88 TiB (492542 extents).
Logical volume lhxt/data successfully resized.
五、同步磁盘信息:xfs_growfs 逻辑卷名
[root@hrmw-db-01 /]# xfs_growfs /dev/lhxt/data
meta-data=/dev/mapper/lhxt-data isize=512 agcount=4, agsize=58982144 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=235928576, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=115199, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 235928576 to 504363008
六、df -h 验证是否扩容成功
[root@hrmw-db-01 /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/lhxt-data 1.9T 822G 1.1T 43% /u01
举例2:(在已有块设备上增加分区)
前提:磁盘已有900多G,又新增了900多G
[root@sjk ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos_sjk-root xfs 50G 2.1G 48G 5% /
devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs tmpfs 7.8G 8.9M 7.8G 1% /run
tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 148M 867M 15% /boot
/dev/mapper/centos_sjk-home xfs 965G 965G 8.5M 100% /home ---现逻辑卷空间已满
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@sjk ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.9T 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 1023G 0 part
│ ├─centos_sjk-root 253:0 0 50G 0 lvm /
│ ├─centos_sjk-swap 253:1 0 7.9G 0 lvm [SWAP]
│ └─centos_sjk-home 253:2 0 965.1G 0 lvm /home ----------------原有的
└─sda3 8:3 0 921.6G 0 part ----------------------新增的
sr0 11:0 1 4.3G 0 rom
一、创建物理卷:pvcreate 物理卷名
[root@sjk ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@sjk ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos_sjk
PV Size <1023.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 261887
Free PE 1
Allocated PE 261886
PV UUID b4uYzm-4S2C-LZ3a-REZG-JeSa-68Uz-LwfXEt
"/dev/sda3" is a new physical volume of "<921.60 GiB"
--- NEW Physical volume --- ----------------新增的物理卷
PV Name /dev/sda3
VG Name
PV Size <921.60 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID aszKbj-oxnt-6iGd-LnRr-G4bc-9Fex-RVEdu4
二、确定原逻辑卷的卷组,将新创建的物理卷加到卷组中
[root@sjk ~]# vgdisplay
--- Volume group ---
VG Name centos_sjk
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <1023.00 GiB
PE Size 4.00 MiB
Total PE 261887
Alloc PE / Size 261886 / 1022.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID A02U8c-NrDf-d92q-zwk5-ERCg-G0Jf-D9snMg
[root@sjk ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos_sjk/home ----逻辑卷名
LV Name home
VG Name centos_sjk ----------------卷组
LV UUID HrSC3l-3vJD-F0Wv-bHYP-DBDd-UFCV-QvxF0C
LV Write Access read/write
LV Creation host, time sjk.slsh, 2022-07-27 20:03:43 +0800
LV Status available
# open 1
LV Size <965.12 GiB
Current LE 247070
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
[root@sjk ~]# vgextend centos_sjk /dev/sda3
Volume group "centos_sjk" successfully extended
三、确定原逻辑卷名,将新增的磁盘空间加到逻辑卷中
[root@sjk dev]# lvextend -l +100%FREE /dev/centos_sjk/home
Size of logical volume centos_sjk/home changed from <965.12 GiB (247070 extents) to 1.84 TiB (483000 extents).
Logical volume centos_sjk/home successfully resized.
[root@sjk dev]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.9T 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 1023G 0 part
│ ├─centos_sjk-root 253:0 0 50G 0 lvm /
│ ├─centos_sjk-swap 253:1 0 7.9G 0 lvm [SWAP]
│ └─centos_sjk-home 253:2 0 1.9T 0 lvm /home
└─sda3 8:3 0 921.6G 0 part
└─centos_sjk-home 253:2 0 1.9T 0 lvm /home
sr0 11:0 1 4.3G 0 rom
###此时加完后是同一个块设备,两个分区的逻辑卷名一样
四、同步磁盘信息:xfs_growfs 逻辑卷名
[root@sjk dev]# xfs_growfs /dev/centos_sjk/home
meta-data=/dev/mapper/centos_sjk-home isize=512 agcount=4, agsize=63249920 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=252999680, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=123535, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 252999680 to 494592000
[root@sjk dev]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos_sjk-root 50G 2.1G 48G 5% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.9M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 1014M 148M 867M 15% /boot
/dev/mapper/centos_sjk-home 1.9T 965G 922G 52% /home -------磁盘空间已增加
tmpfs 1.6G 0 1.6G 0% /run/user/0
总体思路:创建物理卷,加入卷组,内存加到逻辑卷中
扩展:
1、fdisk -l /dev/块设备名:查看某个设备的信息和类型
[root@xmz-12-72-fenxianjiance hesp-push-message]# fdisk -l /dev/vda
Disk /dev/vda:500 GiB,536870912000 字节,1048576000 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xab88ffb3
设备 启动 起点 末尾 扇区 大小 Id 类型
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 1048575999 1046476800 499G 8e Linux LVM
2、partprobe命令
用于重读分区表,将磁盘分区表变化信息通知内核,请求操作系统重新加载分区表。如果删除文件后,仍然提示占用空间,可以用partprobe在不重启的情况下重读分区