[root@localhost ~]# lsblk 查看分区
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 127G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 10G 0 part /boot
└─sda3 8:3 0 114.6G 0 part
├─centos-root 253:0 0 102.5G 0 lvm /
├─centos-swap 253:1 0 1G 0 lvm [SWAP]
├─centos-home 253:2 0 10G 0 lvm /home
└─centos-var 253:3 0 1G 0 lvm /var
sdb 8:16 0 100G 0 disk 未分区
sr0 11:0 1 52K 0 rom
[root@localhost ~]# fdisk /dev/sdb 分区
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x80650761 创建新的 DOS 磁盘标签。
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:dos
磁盘标识符:0x80650761
设备 Boot Start End Blocks Id System
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-209715199,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-209715199,默认为 209715199):
将使用默认值 209715199
分区 1 已设置为 Linux 类型,大小设为 100 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:dos
磁盘标识符:0x80650761
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 209715199 104856576 83 Linux
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 127G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 10G 0 part /boot
└─sda3 8:3 0 114.6G 0 part
├─centos-root 253:0 0 102.5G 0 lvm /
├─centos-swap 253:1 0 1G 0 lvm [SWAP]
├─centos-home 253:2 0 10G 0 lvm /home
└─centos-var 253:3 0 1G 0 lvm /var
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 100G 0 part 这个是刚刚分的区
sr0 11:0 1 52K 0 rom
[root@localhost ~]# pvcreate /dev/sdb1 创建pv
Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 4 0 wz--n- 214.53g 100.00g
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID B07Wwr-26Ay-1gHE-uD35-Or1m-Ge10-axgwvp
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-06-16 23:05:06 +0800
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/var
LV Name var
VG Name centos
LV UUID FDn63c-2Qxh-WJgE-lBGc-YR6R-OxiR-8LRe0s
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-06-16 23:05:07 +0800
LV Status available
# open 1
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID Ldfd6E-tuoK-1e9i-qrO5-Vge6-lFka-C8D9ml
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-06-16 23:05:07 +0800
LV Status available
# open 2
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID dbljUq-AKR4-5Uxv-Ejvc-fEYi-r34E-Q02lSd
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-06-16 23:05:08 +0800
LV Status available
# open 1
LV Size 102.53 GiB
Current LE 26248
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- 10.00g
root centos -wi-ao---- 102.53g
swap centos -wi-ao---- 1.00g
var centos -wi-ao---- 1.00g
[root@localhost ~]# lvextend -L +100G /dev/mapper/centos-var
Size of logical volume centos/var changed from 1.00 GiB (512 extents) to 101.00 GiB (25856 extents).
Logical volume centos/var successfully resized.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- 10.00g
root centos -wi-ao---- 102.53g
swap centos -wi-ao---- 1.00g
var centos -wi-ao---- 101.00g
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 103G 958M 102G 1% /
devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs tmpfs 7.8G 8.7M 7.8G 1% /run
tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda2 xfs 10G 145M 9.9G 2% /boot
/dev/mapper/centos-home xfs 10G 33M 10G 1% /home
/dev/mapper/centos-var xfs 1014M 472M 543M 47% /var
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@localhost ~]# xfs_growfs /dev/mapper/centos-var
meta-data=/dev/mapper/centos-var isize=512 agcount=4, agsize=65536 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=262144, 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=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 262144 to 26476544
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 103G 958M 102G 1% /
devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs tmpfs 7.8G 8.7M 7.8G 1% /run
tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda2 xfs 10G 145M 9.9G 2% /boot
/dev/mapper/centos-home xfs 10G 33M 10G 1% /home
/dev/mapper/centos-var xfs 101G 496M 101G 1% /var
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
history
[root@localhost ~]# history
1 lsblk
2 df -Th
3 lsblk
4 fdisk /dev/sdb
5 lsblk
6 pvcreate /dev/sdb1
7 pvs
8 vgs
9 vgextend centos /dev/sdb1
10 vgs
11 lvdisplay
12 df -Th
13 lvs
16 lvextend -L +100G /dev/mapper/centos-var
17 lvs
18 df -Th
19 xfs_growfs /dev/mapper/centos-var
20 df -Th
21 cat /etc/fstab
22 reboot
24 history
Linux lvextend命令的作用是在线扩展逻辑卷的空间大小,而不中断应用程序对逻辑卷的访问。
使用lvextend命令动态在线扩展磁盘空间,整个空间扩展过程对于应用程序来说是完全透明的。
语法格式 : lvextend [参数] [逻辑卷]
常用参数:
-L | 指定逻辑卷的大小,单位为“kKmMgGtT”字节 |
---|---|
-l | 指定逻辑卷的大小(LE数) |