GaRy-Liang的linux成长日记7-LVM逻辑卷

GaRy-Liang的linux成长日记7-LVM逻辑卷
一、前言:
其实看书已经略过一遍了,但是技术这条路它就需要你练习,练习才会发现报错,报错才会去找答案,其实这里也是挺多很好很详细的答案文档,很多问题都能从这里找到答案,就是有种感觉就是你巴不得把知识都一次性全部塞到自己的脑袋里面,然后就想电影情节一样,巴拉巴拉巴拉的敲上一堆,很酷,也很高大上,ok~走它!
二、学习内容
(1)LVM的简单介绍
物理卷(PV):就个人理解为硬盘分区后对应的物理卷,有可能几块硬盘一起对应一个PV,有可能一块硬盘几个分区对应一块PV,大概大概了。
卷组(VG):就是可以把几个PV弄成一个卷组,也就是大概大概了,
逻辑卷(LV):就是把一个大的VG卷组再分区,然后给linux挂载使用,大概大概了
物理长度(PE):这个大概就是正组成VG后所划分的最小单元格,嗯!我自己也没能 很清楚理解出来,大概大概了,
这么多的大概大概就是这样了,好像没说一样!
(2)虚拟机增加一块硬盘,然后开机挂载,实验是用一块硬盘的,先分好区
[root@liangGaRy ~]# ls /dev/sdb*
/dev/sdb
[root@liangGaRy ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G

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

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

Command (m for help): p

Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
/dev/sdb2 655 1308 5253255 83 Linux
/dev/sdb3 1309 2610 10458315 83 Linux

Command (m for help): w
[root@liangGaRy ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3
[root@liangGaRy ~]# partprobe /dev/sdb

(3)创建物理卷(PV)
[root@liangGaRy ~]# pvcreate /dev/sdb{1,2,3}
Physical volume “/dev/sdb1” successfully created
Physical volume “/dev/sdb2” successfully created
Physical volume “/dev/sdb3” successfully created
[root@liangGaRy ~]# pvdisplay
“/dev/sdb1” is a new physical volume of “5.01 GiB”
— NEW Physical volume —
PV Name /dev/sdb1
VG Name
PV Size 5.01 GiB
Allocatable NO
PE Size 0

(4)创建卷组(VG)
[root@liangGaRy ~]# vgcreate hi-vg /dev/sdb{1,2,3}
Volume group “hi-vg” successfully created
[root@liangGaRy ~]# vgdisplay
— Volume group —
VG Name hi-vg
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 19.99 GiB
PE Size 4.00 MiB
Total PE 5117
Alloc PE / Size 0 / 0
Free PE / Size 5117 / 19.99 GiB
VG UUID i6jWmN-2Y00-gFt9-0kbr-6zxE-1vaU-I1nLwL

(5)创建逻辑卷(LV)
[root@liangGaRy ~]# lvcreate -n hi-lv2 -l 1000 hi-vg
Logical volume “hi-lv2” created
[root@liangGaRy ~]# lvdisplay
— Logical volume —
LV Path /dev/hi-vg/hi-lv
LV Name hi-lv
VG Name hi-vg
LV UUID EIQQ2U-fRmr-Ei5j-uBjB-vKEb-MYro-fRXRE1
LV Write Access read/write
LV Creation host, time liangGaRy.test, 2020-04-06 18:35:20 +0800
LV Status available

open 0

LV Size 10.00 GiB
Current LE 2560
Segments 2
Allocation inherit
Read ahead sectors auto

  • currently set to 256
    Block device 253:0

    (6)格式化并挂载逻辑卷(LV)
    [root@liangGaRy ~]# mkfs.ext4 /dev/hi-vg/hi-lv2
    [root@liangGaRy ~]# mkfs.ext4 /dev/hi-vg/hi-lv
    [root@liangGaRy ~]# mkdir /test ; mkdir /data
    [root@liangGaRy ~]# mount /dev/hi-vg/hi-lv2 /data
    [root@liangGaRy ~]# mount /dev/hi-vg/hi-lv /test
    [root@liangGaRy ~]# df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/sda2 9.7G 1.8G 7.5G 19% /
    tmpfs 503M 0 503M 0% /dev/shm
    /dev/sda1 194M 28M 157M 15% /boot
    /dev/sda5 8.0G 147M 7.4G 2% /home
    /dev/mapper/hi–vg-hi–lv 9.9G 151M 9.2G 2% /test
    /dev/mapper/hi–vg-hi–lv2 3.9G 72M 3.6G 2% /data
    [root@liangGaRy ~]# mount -a
    (7)修改LVM分区容量增加或者减少实验
    [root@liangGaRy ~]# lvreduce -L -2G /dev/hi-vg/hi-lv2
    WARNING: Reducing active and open logical volume to 1.91 GiB
    THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce hi-lv2? [y/n]: y
    Reducing logical volume hi-lv2 to 1.91 GiB
    Logical volume hi-lv2 successfully resized
    [root@liangGaRy ~]# resize2fs /dev/hi-vg/hi-lv2
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/hi-vg/hi-lv2 is mounted on /data; on-line resizing required
    On-line shrinking from 1024000 to 499712 not supported.
    [root@liangGaRy ~]# df -h

[root@liangGaRy ~]# lvextend -L 12G /dev/hi-vg/hi-lv
Extending logical volume hi-lv to 12.00 GiB
Logical volume hi-lv successfully resized
[root@liangGaRy ~]# resize2fs /dev/hi-vg/hi-lv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/hi-vg/hi-lv is mounted on /test; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/hi-vg/hi-lv to 3145728 (4k) blocks.
The filesystem on /dev/hi-vg/hi-lv is now 3145728 blocks long.

[root@liangGaRy ~]# df -h

(8)卸载LVM分区
步骤就倒着来
先取消挂载
在移除逻辑卷
再移除卷组
再移除物理卷
[root@liangGaRy ~]# umount -a
umount: /: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@liangGaRy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 1.8G 7.5G 19% /
[root@liangGaRy ~]# lvre
lvreduce lvremove lvrename lvresize
[root@liangGaRy ~]# lvremove /dev/hi-vg/hi-lv ;lvremove /dev/hi-vg/hi-lv2
Do you really want to remove active logical volume hi-lv? [y/n]: y
Logical volume “hi-lv” successfully removed
Do you really want to remove active logical volume hi-lv2? [y/n]: y
Logical volume “hi-lv2” successfully removed
[root@liangGaRy ~]# vgremove hi-vg
Volume group “hi-vg” successfully removed
[root@liangGaRy ~]# pvremove /dev/sdb{1,2,3}
Labels on physical volume “/dev/sdb1” successfully wiped
Labels on physical volume “/dev/sdb2” successfully wiped
Labels on physical volume “/dev/sdb3” successfully wiped
[root@liangGaRy ~]# mount -a
[root@liangGaRy ~]# df -h

三、LAST
小小心得,创建这个LVM逻辑卷,我自己个人记住三个步骤,先创建物理卷(PV)----再创建卷组(VG)---------最后再创建这个逻辑卷(LV)----然后就根据分区挂载操作进行
然后卸载的步骤和创建的倒过来
命令的话记不住,但是很好记,都是了tab键补全然后在想想用哪个,这个是书本的上实验,应该没有这么简单,还有很多知识没有琢磨透的,就是一个大概大概。好歹也知道这个LVM逻辑卷是怎么搞出来,哈哈哈
那就这样的吧。技术路不好走,最后给自己灌点鸡汤让自己坚持去做一件事情,让架构师这个名字早点挂载到我的身上。
1、 不想输,就别懒!
2、趁着年轻就多点折腾,老了再折腾也折腾不动了。
3、投资自己大脑,就不会像行尸走肉一般的活着!

你可能感兴趣的:(GaRy-Liang的linux成长日记7-LVM逻辑卷)