linux系统磁盘扩容
1.linux逻辑卷管理(LVM)结构图
2.查看磁盘资源
fdisk -l
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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 /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0001085b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
/dev/sda3 4810752 41943039 18566144 83 Linux
3.将新增的磁盘进行格式化
mkfs.xfs /dev/sdb
meta-data=/dev/sdb isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
4.创建物理卷
pvcreate /dev/sdb
WARNING: xfs signature detected on /dev/sdb at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sdb.
Physical volume "/dev/sdb" successfully created.
5.查看物理卷
"/dev/sdb" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
6.查看卷组vg
vgdisplay
--- Volume group ---
VG Name datavg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <5.00 GiB
PE Size 4.00 MiB
Total PE 1279
Alloc PE / Size 0 / 0
Free PE / Size 1279 / <5.00 GiB
VG UUID xwTffG-qmey-HAFh-pdtU-VyNb-p7o5-Q0x3qc
7.新增卷组vg
若vg不存在,则将pv添加到vg中
vgcreate datavg /dev/sdb
重新查看vg
vgdisplay
8.vg扩容
若vg已存在,则将pv添加到vg中
vgextend datavg /dev/sdb
8.查看逻辑卷lv
lvdisplay
--- Logical volume ---
LV Path /dev/datavg/datalv
LV Name datalv
VG Name datavg
LV UUID N270Fm-Npyf-Uctm-KuDf-Bacz-hLMk-wcT2nU
LV Write Access read/write
LV Creation host, time k8s-node2, 2024-07-12 01:01:35 -0700
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
9.新增逻辑卷lv
若lv不存在,则创建lv
lvcreate -L 2G -n datalv datavg
格式化lv
mkfs -t ext4 /dev/datavg/datalv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
将lv挂载到系统中
mount /dev/datavg/datalv /data
10.逻辑卷lv扩容
若lv存在,则扩容lv
lvextend -L +1G /dev/datavg/datalv
Size of logical volume datavg/datalv changed from 2.00 GiB (512 extents) to 3.00 GiB (768 extents).
Logical volume datavg/datalv successfully resized.
查看逻辑盘使用情况
df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 895M 0 895M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 12M 898M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda3 18G 11G 7.4G 59% /
/dev/sda1 297M 163M 134M 55% /boot
/dev/mapper/datavg-datalv 2.9G 9.0M 2.8G 1% /data
更新文件系统
Xfs 用:
xfs_growfs /dev/datavg/datalv
Ext4用:
resize2fs /dev/datavg/datalv
重新查看逻辑盘使用情况
df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 895M 0 895M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 12M 898M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda3 18G 11G 7.4G 59% /
/dev/sda1 297M 163M 134M 55% /boot
/dev/mapper/datavg-datalv 3.9G 9.0M 2.8G 1% /data
11.加入开机自启
vi /etc/rc.d/rc.local
在最后一行添加如下命令
mount /dev/mapper/datavg-datalv /data
退出后chmod一下
chmod 755 /etc/rc.d/rc.local
重启机器查看挂载情况
12.逻辑卷lv卸载
卸载挂载点
umount /data
卸载lv
lvremove /dev/mapper/datavg-datalv
13.vg卸载
vgremove datavg