将对磁盘 vdc 500G 的磁盘配置逻辑卷
关键步骤:
创建物理卷
创建卷组
建立逻辑卷
创建文件系统
格式化逻辑卷
--检查/etc/fstab
root@HKSZF-ZW-172-19-146-173:~# cat /etc/fstab | grep -v "#"
/dev/disk/by-id/dm-uuid-LVM-WNVtbR1dtC8WlK2V3SeSmdSppOoGWiXpld8jgmbhwHlvGAYg2yAZMKEg8UBAyly9 / ext4 defaults 0 0
/dev/disk/by-uuid/2baa10ff-7c55-4f6c-ba28-14f465c76860 /boot ext4 defaults 0 0
/swap.img none swap sw 0 0
避免盘未挂载把掉盘给格式了了
--查看分区前磁盘空间
root@HKSZF-ZW-172-19-146-173:~# df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 3.2G 772K 3.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 24G 5.6G 18G 25% /
tmpfs tmpfs 16G 0 16G 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda2 ext4 976M 77M 832M 9% /boot
tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0
--查看磁盘
root@HKSZF-ZW-172-19-146-173:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 49G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 24.5G 0 lvm /
vdb 252:16 0 64M 0 disk
└─vdb1 252:17 0 63M 0 part
vdc 252:32 0 500G 0 disk
fdisk /dev/vdc
8e 类型
分区后查看
--分区
root@HKSZF-ZW-172-19-146-173:~# fdisk /dev/vdc
--查看
root@HKSZF-ZW-172-19-146-177:~# fdisk -l /dev/vdc1
Disk /dev/vdc1: 500 GiB, 536869863424 bytes, 1048573952 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
将物理分区/dev/vdc1转为物理卷
--创建物理卷
root@ubuntu:~# pvcreate /dev/vdc1
Physical volume "/dev/vdc1" successfully created.
--查看物理卷
root@HKSZF-ZW-172-19-146-173:~# pvs
PV VG Fmt Attr PSize PFree
/dev/vda3 ubuntu-vg lvm2 a-- <49.00g <24.50g
/dev/vdc1 lvm2 --- <500.00g <500.00g
以上面添加的sdb物理盘为基础,创建逻辑卷组
--创建卷组
root@HKSZF-ZW-172-19-146-173:~# vgcreate vgdb /dev/vdc1
Volume group "vgdb" successfully created
--查看卷组
root@HKSZF-ZW-172-19-146-173:~# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz--n- <49.00g <24.50g
vgdb 1 0 0 wz--n- <500.00g <500.00g
在被激活之前,VG与LV是无法访问的,需进行激活
--激活所要使用的卷组
root@HKSZF-ZW-172-19-146-173:~# vgchange -a y vgdb
0 logical volume(s) in volume group "vgdb" now active
需要LV使用整个VG,可首先用vgdisplay 查找 Total PE 值,然后在运行lvcreate时指定
--用vgdisplay 查找 Total PE 值
root@HKSZF-ZW-172-19-146-173:~# vgdisplay vgdb | grep "Total PE"
Total PE 127999
--建立逻辑卷 -n 逻辑名称 vgdb:上面创建的卷组的名称
root@HKSZF-ZW-172-19-146-173:~# lvcreate -l 127999 vgdb -n lvdb
Logical volume "lvdb" created.
--查看逻辑卷
root@HKSZF-ZW-172-19-146-173:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
ubuntu-lv ubuntu-vg -wi-ao---- 24.50g
lvdb vgdb -wi-a----- <500.00g
--查看逻辑卷的全路径
root@HKSZF-ZW-172-19-146-173:~# ls -l /dev/vgdb/lvdb
lrwxrwxrwx 1 root root 7 Jan 18 08:49 /dev/vgdb/lvdb -> ../dm-1
root@HKSZF-ZW-172-19-146-173:~# mkfs.xfs /dev/vgdb/lvdb
meta-data=/dev/vgdb/lvdb isize=512 agcount=4, agsize=32767744 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=0, rmapbt=0, reflink=0
data = bsize=4096 blocks=131070976, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=63999, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
#查看逻辑卷的uuid
root@HKSZF-ZW-172-19-146-173:~# blkid /dev/vgdb/lvdb
/dev/vgdb/lvdb: UUID="6bb9b26c-95c0-4237-9f7b-18afc922756d" TYPE="xfs"
#创建挂载目录
查看目录是否存在,避免已有目录同名
root@HKSZF-ZW-172-19-146-177:~# ls -ld /topsoft
ls: cannot access '/topsoft': No such file or directory
root@HKSZF-ZW-172-19-146-173:~# mkdir -p /topsoft
#挂载
root@HKSZF-ZW-172-19-146-173:~# mount /dev/vgdb/lvdb /topsoft/
#查看挂载后的情况
root@HKSZF-ZW-172-19-146-173:~# df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 3.2G 780K 3.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 24G 5.6G 18G 25% /
tmpfs tmpfs 16G 0 16G 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda2 ext4 976M 77M 832M 9% /boot
tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0
/dev/mapper/vgdb-lvdb xfs 500G 543M 500G 1% /topsoft
设置开机挂载
#设置开机挂载
备份/etc/fstab
cp /etc/fstab /etc/fstab_bak_20240118
#添加挂载信息至/etc/fstab
echo "UUID=6bb9b26c-95c0-4237-9f7b-18afc922756d /topsoft xfs defaults 0 0" >> /etc/fstab