LVM挂载,步骤总结

一,LVM概念

需要理解的几个概念:
PV(Physical Volume):物理空间的意思,其实就是指一个分区(如/dev/sdb1 )或者是一个盘(如/dev/sdb)
VG(Volume Group):相当于一个Pool,由多个PV组成的pool
LV(Logical Volume):用来建立一个文件系统的空间,这个空间来源于VG,大小随意,可以扩展。(比如/dev/mapper/rhel-root这个目录其实是一个文件系统挂载点,这个点就是承载在一个LV上,这个文件系统的大小就是这个LV的大小。 )

二,实际操作

1、使用fdisk -l查看磁盘情况,可以看到我有两块未分区的磁盘,分别是/dev/sdb /dev/sdc,我们先用一块磁盘/dev/sdb进行测试。
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00084311

Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 430 3145728 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 430 3917 28003328 83 Linux

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

2.对dev/sdb进行分区
第一步:标准分区
[root@localhost Desktop]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xdeb58d83.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).

Command (m for help): n
Command action
e extended
p primary partition (1-4)
1
Invalid partition number for type `1’
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6527, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):
Using default value 6527

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
第二步使用vgdisplay查看已经存在的卷组名称(在我的环境上没有已存在的卷组)
[root@localhost Desktop]# vgdisplay
No volume groups found
第三步开始lvm处理
创建物理卷(PV)
[root@localhost Desktop]# pvcreate /dev/sdb1
dev_is_mpath: failed to get device for 8:17
Physical volume “/dev/sdb1” successfully created
创建卷组(VG)
@localhost Desktop]# vgcreate vg01 /dev/sdb1
Volume group “vg01” successfully created
查看创建的物理卷及卷组
[root@localhost Desktop]# pvdisplay
— Physical volume —
PV Name /dev/sdb1
VG Name vg01
PV Size 50.00 GiB / not usable 3.31 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12799
Free PE 12799
Allocated PE 0
PV UUID K7fO31-ouKc-dKCv-Kc5R-BxHC-ROgN-of213l

[root@localhost Desktop]# vgdisplay
— Volume group —
VG Name vg01
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 50.00 GiB
PE Size 4.00 MiB
Total PE 12799
Alloc PE / Size 0 / 0
Free PE / Size 12799 / 50.00 GiB
VG UUID iB6KO0-sVeb-HRj1-v0jT-9it6-VV3s-abEynt

在卷组vg01上创建名为data,大小为1000M的逻辑卷LV(逻辑卷可扩展)
[root@localhost Desktop]# lvcreate -L 1000M -n data vg01
Logical volume “data” created
[root@localhost Desktop]# lvscan
ACTIVE ‘/dev/vg01/data’ [1000.00 MiB] inherit

3,格式化分区
[root@localhost Desktop]# mkfs.ext4 /dev/vg01/data
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
64000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

4.挂载分区
[root@localhost Desktop]# cd ~
[root@localhost ~]# mkdir /u01
[root@localhost ~]# mount /dev/vg01/data /u01
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 27G 7.1G 18G 29% /
tmpfs 931M 228K 931M 1% /dev/shm
/dev/sda1 291M 39M 238M 14% /boot
/dev/mapper/vg01-data 985M 18M 918M 2% /u01
5,设置开机自动挂载(vi /etc/fstab)
[root@localhost ~]# cat /etc/fstab

/etc/fstab

Created by anaconda on Tue Jun 2 09:29:29 2020

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

UUID=b1a280f3-537d-4eb7-a035-3060b77f9653 / ext4 defaults 1 1
UUID=618de965-9962-42dc-99e6-0a9774c0aea7 /boot ext4 defaults 1 2
UUID=a3c5cfaa-5a5c-4f9d-8a64-bf77bed181db swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/vg01/data /u01 ext4 defaults 0 0
6.逻辑券扩展
[root@localhost ~]# lvextend -L +10G -f -r /dev/vg01/data

三、PV扩容
流程总结:新接入磁盘、磁盘分区、新建物理卷(pv)、卷组(vg)扩容、扩展逻辑卷(LV)将新建卷组加入进来
1、首先进行标准分区

复制代码
root@test_iptables ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x114bf00d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
复制代码
2、创建物理卷

[root@test_iptables ~]# pvcreate /dev/sdc1
Physical volume “/dev/sdc1” successfully created
3、VG扩容

将新的物理卷加入卷组

[root@test_iptables ~]# vgextend vg01 /dev/sdc1
Volume group “vg01” successfully extended
扩展逻辑卷 并resize2fs加载逻辑卷

复制代码
[root@test_iptables ~]# lvextend -l +100%FREE /dev/vg01/data
Extending logical volume data to 1.98 GiB
Logical volume data successfully resized
[root@test_iptables ~]# resize2fs /dev/vg01/data
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg01/data is mounted on /u01; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg01/data to 520192 (4k) blocks.
The filesystem on /dev/vg01/data is now 520192 blocks long.
复制代码
至此,以上就是整个流程,成功扩展为2G。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值