新拿到一个主机,挂载磁盘,但是之前实在是没做过,这里也算是学了点东西,挂载分pv vg lv
这些,这里第一个坑就是直接挂载这个后续没办法扩容,如果挂载的盘上装的数据库那就惨了,只能把数据迁移走再扩容了,下面是可扩容的操作建议全部按下面的步骤来。
查看磁盘
vdb
盘就是要挂载的盘,可以看到vda
是已经被别人挂载了,这个vda1
是不能动态扩容的,你看他的类型是part
,不建议这个干
[root@-8-32-200-d ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 730K 0 rom
vda 253:0 0 200G 0 disk
└─vda1 253:1 0 200G 0 part /
vdb 253:16 0 300G 0 disk
查看文件
可以看到vda1
已经被挂在了根目录下,下面就要把vdb
挂载出去
[root@-8-32-200-d ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 17G 0 17G 0% /dev
tmpfs tmpfs 17G 0 17G 0% /dev/shm
tmpfs tmpfs 17G 476k 17G 1% /run
tmpfs tmpfs 17G 0 17G 0% /sys/fs/cgroup
/dev/vda1 xfs 215G 4.1G 211G 2% /
tmpfs tmpfs 3.4G 0 3.4G 0% /run/user/0
创建一个目录给磁盘挂载用
mkdir /data
创建pv
[root@-8-32-200-c /]# pvcreate /dev/vdb -y
Physical volume "/dev/vdb" successfully created.
创建vg
[root@-8-32-200-c /]# vgcreate vgdata /dev/vdb
Volume group "vgdata" successfully created
[root@-8-32-200-c /]# vgchange -a y vgdata
0 logical volume(s) in volume group "vgdata" now active
创建lv
[root@-8-32-200-c /]# lvcreate -L 1G -n lvdata01 vgdata
Logical volume "lvdata01" created.
[root@-8-32-200-c /]# lvextend -l +100%FREE -n /dev/vgdata/lvdata01
Size of logical volume vgdata/lvdata01 changed from 1.00 GiB (256 extents) to <300.00 GiB (76799 extents).
Logical volume vgdata/lvdata01 successfully resized.
格式化
[root@-8-32-200-c /]# mkfs.xfs /dev/vgdata/lvdata01
meta-data=/dev/vgdata/lvdata01 isize=512 agcount=4, agsize=19660544 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=78642176, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=38399, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
查看磁盘
/dev/mapper/vgdata-lvdata01: UUID="db9de997-929c-4e15-bdc7-a68ccca99e03"
就是创建出来的逻辑卷,写入下面的fstab
文件中永久挂载
[root@-8-32-200-c /]# blkid
/dev/vda1: UUID="a67f0b20-00bf-45b8-85bf-00791d6a68b2" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="ab4e6aa3-01"
/dev/sr0: BLOCK_SIZE="2048" UUID="2024-05-24-16-14-53-00" LABEL="config-2" TYPE="iso9660"
/dev/vdb: UUID="UeywxB-2stE-RAIf-82rE-l4YZ-7q4R-wxeTny" TYPE="LVM2_member"
/dev/mapper/vgdata-lvdata01: UUID="db9de997-929c-4e15-bdc7-a68ccca99e03" BLOCK_SIZE="512" TYPE="xfs"
永久挂载
[root@-8-32-200-c /]# echo "UUID=db9de997-929c-4e15-bdc7-a68ccca99e03 /data xfs defaults 0 0" >> /etc/fstab
[root@-8-32-200-c /]# mount -a
查看挂载效果
[root@-8-32-200-d ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 17G 0 17G 0% /dev
tmpfs tmpfs 17G 0 17G 0% /dev/shm
tmpfs tmpfs 17G 488k 17G 1% /run
tmpfs tmpfs 17G 0 17G 0% /sys/fs/cgroup
/dev/vda1 xfs 215G 4.1G 211G 2% /
/dev/mapper/vgdata-lvdata01 xfs 322G 2.3G 320G 1% /data
tmpfs tmpfs 3.4G 0 3.4G 0% /run/user/0
[root@-8-32-200-d ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 730K 0 rom
vda 253:0 0 200G 0 disk
└─vda1 253:1 0 200G 0 part /
vdb 253:16 0 300G 0 disk
└─vgdata-lvdata01 252:0 0 300G 0 lvm /data
[root@-8-32-200-d ~]# blkid
/dev/vda1: UUID="a67f0b20-00bf-45b8-85bf-00791d6a68b2" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="ab4e6aa3-01"
/dev/sr0: BLOCK_SIZE="2048" UUID="2024-05-24-16-14-53-00" LABEL="config-2" TYPE="iso9660"
/dev/vdb: UUID="UeywxB-2stE-RAIf-82rE-l4YZ-7q4R-wxeTny" TYPE="LVM2_member"
/dev/mapper/vgdata-lvdata01: UUID="db9de997-929c-4e15-bdc7-a68ccca99e03" BLOCK_SIZE="512" TYPE="xfs"
[root@-8-32-200-d ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Apr 6 06:35:10 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=a67f0b20-00bf-45b8-85bf-00791d6a68b2 / xfs defaults 0 0
# UUID是创建出来的卷
UUID=db9de997-929c-4e15-bdc7-a68ccca99e03 /data xfs defaults 0 0
至此挂载完成