linux 磁盘分区以及物理卷PV,卷组VG,逻辑券LV相关命令学习整理
1.磁盘分区
fdisk -l 查看磁盘分区情况
fdisk /dev/sdb* f最某个磁盘进行分区
df -h 查看磁盘分区后信息
2.创建物理卷PV
pvcreate 设备名称
[root@localhost Desktop]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created
pvdisplay 产看详细物理卷信息
root@localhost Desktop]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID aK2Fc8-CdE3-fNm5-HvD4-OYNf-efGB-EZGjiQ
--- Physical volume ---
PV Name /dev/sdb1
VG Name vgnew
PV Size 200.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 49
Free PE 40
Allocated PE 9
PV UUID ukTCyL-09v8-Bs6C-tDYs-JpNQ-vrG3-2iRUDG
--- Physical volume ---
PV Name /dev/sdb2
VG Name vgnew
PV Size 120.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 29
Free PE 29
Allocated PE 0
PV UUID fVstso-ytGO-Y7Qw-ndkJ-E1Pt-aR65-aViPdz
"/dev/sdb3" is a new physical volume of "20.00 MiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size 20.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 1Tyiu2-xzt0-3Kw6-9Gmg-5CSl-1mHT-kIq5k2
pvscan/pvs 查看扼要物理券信息
[root@localhost Desktop]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- 19.51g 0
/dev/sdb1 vgnew lvm2 a-- 196.00m 160.00m
/dev/sdb2 vgnew lvm2 a-- 116.00m 116.00m
/dev/sdb3 lvm2 a-- 20.00m 20.00m
可以看到设备sdb3 没有VG ,没有券组,下面来创建卷组
3.创建卷组 vgcreate
[root@localhost Desktop]# vgcreate vg001 /dev/sdb3
Volume group "vg001" successfully created
[root@localhost Desktop]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- 19.51g 0
vg001 1 0 0 wz--n- 16.00m 16.00m
vgnew 2 1 0 wz--n- 312.00m 276.00m
vgcreat -s xxM 指定PE值大小,默认为4M 。
4.创建逻辑券 lvcreate
[root@localhost Desktop]# lvcreate -n lv001 -L 4M vg001
Logical volume "lv001" created
[root@localhost Desktop]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 17.51g
swap rhel -wi-ao---- 2.00g
lv001 vg001 -wi-a----- 4.00m
newlv vgnew -wi-ao---- 36.00m
lvcreate -n 逻辑券名 -L xxM 逻辑卷大小 卷组
5.挂载逻辑卷,只有挂载之后才能使用逻辑卷
挂载之前先要对逻辑券进行格式化,这里先格式化成为ext4格式
[root@localhost Desktop]# mkfs.ext4 /dev/vg001/lv001
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
1024 inodes, 4096 blocks
204 blocks (4.98%) reserved for the super user
First data block=1
Maximum filesystem blocks=4194304
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost Desktop]# mkdir /mkd //新建文件夹
[root@localhost /]# mount /dev/vg001/lv001 /mkd //挂载
[root@localhost /]# df -h //产看挂载信息
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.3G 15G 19% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 144K 914M 1% /dev/shm
tmpfs 914M 8.9M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M 204K 9.6M 3% /media
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv001 2.9M 45K 2.6M 2% /mkd
[root@localhost /]# vim /etc/fstab //编辑/etc/fstab 文件设置开机自动挂载
6.扩展逻辑卷
[root@localhost /]# vgdisplay vg001 ----查看逻辑卷所在的卷组信息
--- Volume group ---
VG Name vg001
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 16.00 MiB
PE Size 4.00 MiB
Total PE 4
Alloc PE / Size 1 / 4.00 MiB
Free PE / Size 3 / 12.00 MiB
VG UUID 0IGKxv-NQRG-PNue-UbR3-1O7S-yW4K-f10I3E
卷组还有剩余 12M 可以直接扩展
首先在 /mkd文件夹下建立一个简单的文件,测试文件会不会丢失,建立文件省略。。。。
[root@localhost mkd]# ll
total 14
drwx------. 2 root root 12288 May 30 02:26 lost+found
-rw-r--r--. 1 root root 8 May 30 03:15 test.txt
[root@localhost mkd]# lvextend -l +1 /dev/vg001/lv001 ---扩展加1个PE大小的值
Extending logical volume lv001 to 8.00 MiB
Logical volume lv001 successfully resized
[root@localhost mkd]# df -h --查看逻辑卷 ,可以看到该逻辑券并没有增加,
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.3G 15G 19% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 144K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M 204K 9.6M 3% /media
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv001 2.9M 47K 2.6M 2% /mkd
[root@localhost mkd]# resize2fs /dev/vg001/lv001 ---使逻辑卷扩展生效
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg001/lv001 is mounted on /mkd; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg001/lv001 is now 8192 blocks long.
[root@localhost mkd]# df -h ---重新查看逻辑卷大小,成功扩展
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.3G 15G 19% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 144K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M 204K 9.6M 3% /media
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv001 6.9M 47K 6.6M 1% /mkd
文件无损坏
7.逻辑卷缩减
首先需要卸载挂载点
[root@localhost /]# umount /mkd --卸载挂载点
[root@localhost /]# resize2fs /dev/vg001/lv001 4M --调整文件系统大小
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vg001/lv001' first.
[root@localhost /]# e2fsck -f /dev/vg001/lv001 --先执行这个
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg001/lv001: 12/1024 files (8.3% non-contiguous), 1204/8192 blocks
[root@localhost /]# resize2fs /dev/vg001/lv001 4M --重新调整文件系统大小
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg001/lv001 to 4096 (1k) blocks.
The filesystem on /dev/vg001/lv001 is now 4096 blocks long.
[root@localhost /]# e2fsck -f /dev/vg001/lv001 --重新检查文件系统
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg001/lv001: 12/1024 files (8.3% non-contiguous), 1204/4096 blocks
[root@localhost /]# lvreduce -l -1 /dev/vg001/lv001 --缩减一个逻辑券为1个PE值大小
WARNING: Reducing active logical volume to 4.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv001? [y/n]: y
Reducing logical volume lv001 to 4.00 MiB
Logical volume lv001 successfully resized
8.删除逻辑卷 lvremove
[root@localhost /]# lvremove /dev/vg001/lv001
Do you really want to remove active logical volume lv001? [y/n]: y
Logical volume "lv001" successfully removed
9.删除卷组,缩减券组
vgreduce 若一个卷组包含多个PV,缩减是删除PV得到的
vgremove 删除一个卷组
10.删除物理券
pvremove