DM设备的创建与管理
DM(Device Mapper)即设备映射(逻辑设备)。
MD和DM是Linux内核上2种工作机制(实现逻辑设备)不同的模块。
Physical Volume(PV): 物理卷 底层
Volume Group(VG): 卷组 中间层
Logical Volume(LV):逻辑卷 第一层(可伸缩)
Physical Extend(PE):物理盘区 类似于RAID的chunk
Logical Extend(LE):逻辑盘区 PE在逻辑卷层面上的称谓
各层的管理命令:
pv
pvcreate, pvremove, pvmove, pvdisplay, pvs, pvscan
vg
vgcreate, vgremove, vgextend, vgreduce, vgdisplay, pvs, vgscan
lv
lvcreate, lvremove, lvextend, lvreduce, lvresize, lvdisplay, lvs,lvscan
以下是实现过程(10G的卷组):
1、创建Linux LVM分区
[root@ant-colonies ~]# fdisk /dev/sda
...
Command (m for help): t
Partition number (1-13): 13
Hex code (type L to list codes): 8e
Changed system type of partition 13 to 8e (Linux LVM)
...
/dev/sda11 4210 4602 3156741 8e Linux LVM
/dev/sda12 4603 5517 7349706 8e Linux LVM
/dev/sda13 5518 6171 5253223+ 8e Linux LVM
[root@ant-colonies ~]# cat /proc/partitions
major minor #blocks name
...
8 11 3156741 sda11
8 12 7349706 sda12
8 13 5253223 sda13
2、创建物理卷(Physical Volume)
[root@ant-colonies ~]# pvcreate /dev/sda{11,12}
Physical volume "/dev/sda11" successfully created
Physical volume "/dev/sda12" successfully created
[root@ant-colonies ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda11 lvm2 --- 3.01g 3.01g
/dev/sda12 lvm2 --- 7.01g 7.01g
/dev/sda6 myvg lvm2 a-- 7.01g 6.95g
/dev/sda7 myvg lvm2 a-- 5.01g 5.01g
[root@ant-colonies ~]# pvdisplay
...
"/dev/sda11" is a new physical volume of "3.01 GiB"
--- NEW Physical volume ---
PV Name /dev/sda11
VG Name
PV Size 3.01 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID D0KinO-K7pw-rkIh-GsY1-dxDZ-d1MO-zBfjMZ
"/dev/sda12" is a new physical volume of "7.01 GiB"
--- NEW Physical volume ---
PV Name /dev/sda12
VG Name
PV Size 7.01 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID XJRRp1-awM3-qfDW-Qv46-ho2i-MS45-PmcxzG
[root@ant-colonies ~]# pvscan
PV /dev/sda6 VG myvg lvm2 [7.01 GiB / 6.95 GiB free]
PV /dev/sda7 VG myvg lvm2 [5.01 GiB / 5.01 GiB free]
PV /dev/sda11 lvm2 [3.01 GiB]
PV /dev/sda12 lvm2 [7.01 GiB]
Total: 4 [22.04 GiB] / in use: 2 [12.02 GiB] / in no VG: 2 [10.02 GiB]
3、创建卷组(Volume Group)
[root@ant-colonies ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 2 1 0 wz--n- 12.02g 11.96g
[root@ant-colonies ~]# vgcreate MYVG /dev/sda{11,12}
Volume group "MYVG" successfully created
[root@ant-colonies ~]# vgs
VG #PV #LV #SN Attr VSize VFree
MYVG 2 0 0 wz--n- 10.02g 10.02g
myvg 2 1 0 wz--n- 12.02g 11.96g
[root@ant-colonies ~]# vgdisplay MYVG
--- Volume group ---
VG Name MYVG
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 10.02 GiB
PE Size 4.00 MiB
Total PE 2564
Alloc PE / Size 0 / 0
Free PE / Size 2564 / 10.02 GiB
VG UUID 8mp6sm-1Wj4-p82x-d7LG-OWSt-8i2q-BZmGKA
4、删除卷组创建指定PE大小的卷组
[root@ant-colonies ~]# vgremove MYVG
Volume group "MYVG" successfully removed
[root@ant-colonies ~]# vgcreate -s 8M MYVG /dev/sda{11,12}
Volume group "MYVG" successfully created
[root@ant-colonies ~]# vgdisplay MYVG
--- Volume group ---
VG Name MYVG
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 10.02 GiB
PE Size 8.00 MiB
Total PE 1282
Alloc PE / Size 0 / 0
Free PE / Size 1282 / 10.02 GiB
VG UUID RI4sJU-OI6d-CSva-HBes-gfzP-MMu8-E2QPWu
5、移除物理卷成员“三部曲”
[root@ant-colonies ~]# vgs
VG #PV #LV #SN Attr VSize VFree
MYVG 2 0 0 wz--n- 10.02g 10.02g
myvg 2 1 0 wz--n- 12.02g 11.96g
[root@ant-colonies ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda11 MYVG lvm2 a-- 3.01g 3.01g
/dev/sda12 MYVG lvm2 a-- 7.01g 7.01g
/dev/sda6 myvg lvm2 a-- 7.01g 6.95g
/dev/sda7 myvg lvm2 a-- 5.01g 5.01g
1)将要移除的物理卷/dev/sda11的数据移动到同组其他物理卷
[root@ant-colonies ~]# pvmove /dev/sda11
No data to move for MYVG
2)将/dev/sda11从卷组中移除
[root@ant-colonies ~]# vgreduce MYVG /dev/sda11
Removed "/dev/sda11" from volume group "MYVG"
[root@ant-colonies ~]# vgs
VG #PV #LV #SN Attr VSize VFree
MYVG 1 0 0 wz--n- 7.01g 7.01g
myvg 2 1 0 wz--n- 12.02g 11.96g
[root@ant-colonies ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda11 lvm2 --- 3.01g 3.01g
/dev/sda12 MYVG lvm2 a-- 7.01g 7.01g
/dev/sda6 myvg lvm2 a-- 7.01g 6.95g
/dev/sda7 myvg lvm2 a-- 5.01g 5.01g
3)将物理卷/dev/sda11移除
[root@ant-colonies ~]# pvremove /dev/sda11
Labels on physical volume "/dev/sda11" successfully wiped
[root@ant-colonies ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda12 MYVG lvm2 a-- 7.01g 7.01g
/dev/sda6 myvg lvm2 a-- 7.01g 6.95g
/dev/sda7 myvg lvm2 a-- 5.01g 5.01g
6、添加新的物理卷到卷组
[root@ant-colonies ~]# pvcreate /dev/sda13
Physical volume "/dev/sda13" successfully created
[root@ant-colonies ~]# vgextend MYVG /dev/sda13
Volume group "MYVG" successfully extended
[root@ant-colonies ~]# vgs
VG #PV #LV #SN Attr VSize VFree
MYVG 2 0 0 wz--n- 12.02g 12.02g
myvg 2 1 0 wz--n- 12.02g 11.96g
[root@ant-colonies ~]# pvdisplay /dev/sda13
--- Physical volume ---
PV Name /dev/sda13
VG Name MYVG
PV Size 5.01 GiB / not usable 2.10 MiB
Allocatable yes
PE Size 8.00 MiB #与卷组的PE大小一致
Total PE 641
Free PE 641
Allocated PE 0
PV UUID DJyRRk-NnZb-dqHt-pqUy-T83d-SkQO-e4S4U2
7、创建逻辑卷(Logical Volume)
[root@ant-colonies ~]# lvcreate -L 50M -n TESTLV MYVG
Rounding up size to full physical extent 56.00 MiB
Logical volume "TESTLV" created.
[root@ant-colonies ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
TESTLV MYVG -wi-a----- 56.00m
testlv myvg -wi-a----- 56.00m
[root@ant-colonies ~]# lvdisplay
--- Logical volume ---
LV Path /dev/MYVG/TESTLV
LV Name TESTLV
VG Name MYVG
LV UUID r41vKB-XplG-PCwV-q8C4-gaAT-Rxh1-ydSQFh
LV Write Access read/write
LV Creation host, time ant-colonies, 2017-01-20 18:15:31 +0800
LV Status available
# open 0
LV Size 56.00 MiB
Current LE 7
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
...
8、格式化
[root@ant-colonies ~]# mke2fs -j /dev/MYVG/TESTLV
...
9、挂载
[root@ant-colonies ~]# mount /dev/MYVG/TESTLV /user
[root@ant-colonies ~]# cp /etc/inittab /user
[root@ant-colonies ~]# cd /user
[root@ant-colonies user]# ls -l
total 14
-rw-r--r--. 1 root root 884 Jan 21 00:03 inittab
drwx------. 2 root root 12288 Jan 20 23:12 lost+found
[root@ant-colonies user]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/MYVG-TESTLV on /user type ext3 (rw)
说明/dev/mapper/MYVG-TESTLV 和 /dev/MYVG/TESTLV均为/dev/dm-1的字符链接。
10、卸载
[root@ant-colonies user]# lvremove /dev/mapper/MYVG-TESTLV
Logical volume MYVG/TESTLV contains a filesystem in use.
[root@ant-colonies /]# umount /user
[root@ant-colonies /]# lvremove /dev/mapper/MYVG-TESTLV
Do you really want to remove active logical volume TESTLV? [y/n]: y
Logical volume "TESTLV" successfully removed # 意味着数据也被删除
[root@ant-colonies ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv myvg -wi-a----- 56.00m
再次创建、格式化并挂载逻辑卷
[root@ant-colonies ~]# lvcreate -L 50M -n TESTLV MYVG
[root@ant-colonies ~]# mke2fs -j -b 4096 -E stride=16 /dev/mapper/MYVG-TESTLV
...
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=16 blocks, Stripe width=0 blocks
14336 inodes, 14336 blocks
...
[root@ant-colonies ~]# mount /dev/mapper/MYVG-TESTLV /user
[root@ant-colonies ~]# ls -l /user
total 16
drwx------. 2 root root 16384 Jan 21 00:24 lost+found
[root@ant-colonies ~]# cp /etc/inittab /user
[root@ant-colonies ~]# cd /user
[root@ant-colonies user]# ls -l
total 24
-rw-r--r--. 1 root root 884 Jan 21 00:29 inittab
drwx------. 2 root root 16384 Jan 21 00:24 lost+found
11、扩展逻辑卷
[root@ant-colonies user]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda12 MYVG lvm2 a-- 7.01g 6.95g
/dev/sda13 MYVG lvm2 a-- 5.01g 5.01g
/dev/sda6 myvg lvm2 a-- 7.01g 6.95g
/dev/sda7 myvg lvm2 a-- 5.01g 5.01g
[root@ant-colonies user]# vgs
VG #PV #LV #SN Attr VSize VFree
MYVG 2 1 0 wz--n- 12.02g 11.96g
myvg 2 1 0 wz--n- 12.02g 11.96g
[root@ant-colonies user]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
TESTLV MYVG -wi-ao---- 56.00m
testlv myvg -wi-a----- 56.00m
[root@ant-colonies user]# lvextend -L 5G /dev/mapper/MYVG-TESTLV
Size of logical volume MYVG/TESTLV changed from 56.00 MiB (7 extents) to 5.00 GiB (640 extents).
Logical volume TESTLV successfully resized
[root@ant-colonies user]# resize2fs -p /dev/mapper/MYVG-TESTLV
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/MYVG-TESTLV is mounted on /user; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/MYVG-TESTLV to 1310720 (4k) blocks.
The filesystem on /dev/mapper/MYVG-TESTLV is now 1310720 blocks long.
[root@ant-colonies user]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
TESTLV MYVG -wi-ao---- 5.00g
testlv myvg -wi-a----- 56.00m
[root@ant-colonies user]# ls -l
total 24
-rw-r--r--. 1 root root Jan 21 00:29 inittab
drwx------. 2 root root 16384 Jan 21 00:24 lost+found
12、缩减逻辑卷(至2G)
[root@ant-colonies ~]# df -Ph # 查看逻辑卷大小
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.8G 2.1G 7.2G 23% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 190M 36M 145M 20% /boot
/dev/mapper/MYVG-TESTLV 5.0G 4.2M 4.7G 1% /user
[root@ant-colonies ~]# umount /user # 卸载
[root@ant-colonies ~]# e2fsck -f /dev/mapper/MYVG-TESTLV # 强行检查逻辑卷
e2fsck 1.41.12 (17-May-2010)
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/mapper/MYVG-TESTLV: 12/573440 files (0.0% non-contiguous), 19073/1310720 blocks
[root@ant-colonies ~]# resize2fs /dev/mapper/MYVG-TESTLV 2G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/MYVG-TESTLV to 524288 (4k) blocks.
The filesystem on /dev/mapper/MYVG-TESTLV is now 524288 blocks long.
[root@ant-colonies ~]# lvreduce -L -3G /dev/mapper/MYVG-TESTLV
WARNING: Reducing active logical volume to 2.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce TESTLV? [y/n]: y
Size of logical volume MYVG/TESTLV changed from 5.00 GiB (640 extents) to 2.00 GiB (256 extents).
Logical volume TESTLV successfully resized
[root@ant-colonies ~]# mount /dev/mapper/MYVG-TESTLV /user
[root@ant-colonies ~]# cd /user
[root@ant-colonies user]# ls -l
total 24
-rw-r--r--. 1 root root Jan 21 00:29 inittab #文件未发生改变
drwx------. 2 root root 16384 Jan 21 00:24 lost+found
13、创建快照
[root@ant-colonies user]# lvcreate -L 50M -n TESTLV-SNAP -s -p r /dev/mapper/MYVG-TESTLV
Rounding up size to full physical extent 56.00 MiB
Logical volume "TESTLV-SNAP" created.
[root@ant-colonies user]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
TESTLV MYVG owi-aos--- 2.00g
TESTLV-SNAP MYVG sri-a-s--- 56.00m TESTLV 0.02
testlv myvg -wi-a----- 56.00m
[root@ant-colonies user]# mount /dev/mapper/MYVG-TESTLV /mnt
[root@ant-colonies user]# cd /mnt
[root@ant-colonies mnt]# ls -l
total 24
-rw-r--r--. 1 root root 884 Jan 21 00:29 inittab
drwx------. 2 root root 16384 Jan 21 00:24 lost+found
[root@ant-colonies mnt]# wc -l inittab
26 inittab
[root@ant-colonies mnt]# (之后的操作,在系统中修改数据,快照也发生改变,原因不明?????)
DM设备的创建与管理的更多相关文章
- Hyper-V1:创建和管理虚拟机
Hyper-V是微软的管理虚拟机(Virtual Machine)的服务,在安装Hyper-V功能之后,系统自动安装可视化的虚拟机管理工具:Hyper-V Manager.在同一台物理机上,能够使用H ...
- 使用virt-manager创建和管理虚拟机
1.虚拟机管理程序和虚拟机管理 一个服务器上只安装单一操作系统的时代已经过去,单个服务器可通过安装多个虚拟机来运行不同操作系统.虚拟机的大量使用减少了所需的服务其硬件,降低了服务器的功耗,但却带来了另 ...
- 利用Delphi的File Of Type创建并管理属于你自己的数据库
http://www.360doc.com/content/16/1128/19/28222077_610249962.shtml 利用Delphi的File Of Type创建并管理属于你自己的数据 ...
- 了解linux下RAID(磁盘阵列)创建和管理
现在的操作系统,不论是windows 还是linux都具有raid的功能,RAID 分为硬件 RAID 和软件 RAID, 硬件 RAID 是通过 RAID 卡来实现的,软件RAID是通过软件实现的, ...
- 【Linux卷管理】LVM创建与管理
安装LVM 首先确定系统中是否安装了lvm工具: [root@jetsen ~]# rpm -qa|grep lvm system-config-lvm-1.1.5-1.0.el5 lvm2-2.02 ...
- Oracle_创建和管理表
创建和管理表 常见的数据库对象 Oracle 数据库中的表 查询数据字典 命名规则 CREATE TABLE 语句 数据类型 使用子查询创建表 ALTER TABLE 语句 删除表 清空表 改变对象的 ...
- 《HiWind企业快速开发框架实战》(3)使用HiWind创建和管理菜单
<HiWind企业快速开发框架实战>(3)使用HiWind创建和管理菜单 关于HiWind HiWind企业快速开发框架,是基于.NET+EasyUi(支持各种前端扩展,后面将扩展Boot ...
- 无法为目标平台“Microsoft.Data.Tools.Schema.Sql.Sql120DatabaseSchemaProvider”创建扩展管理器
很久没写博客了,这段时间情绪不那么稳定,还是心态的问题... 就简单写个问题的解决方法吧,其实最近遇到的问题蛮多的,就拿这个解决过后又遇到的来写吧. 正如标题一样:VS2013 无法为目标平台“Mic ...
- linux 用户创建、管理、权限分配
(1)su与sudo su:通过su可以在用户之间切换,如果超级权限用户root向普通或虚拟用户切换不需要密码,什么是权力?这就是!而普通用户切换到其它任何用户都需要密码验证: sudo: sudo扮 ...
随机推荐
- Poj 1316 Self Numbers(水题)
一.Description In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called se ...
- nginx的安装及基本配置
在CentOS7(mini)上安装: [root@~ localhost]#lftp 172.16.0.1 lftp 172.16.0.1:/pub/Sources/7.x86_64/nginx> ...
- python变量、类型、运算、输出
1.变量.类型.运算.输出等 # -*- coding: utf-8 -*- a=2 b=3 c=a+b print u'结果是=%i'%c #加u显示中文 str=unicode(s,"u ...
- 11、perl语言的记录分割符$/ $\
参考:https://www.jianshu.com/p/8ffd53b1bd41 perl自带的perldoc文档.perldoc -v '$/' :perldoc -f join $/ #输入记 ...
- Centos6.8下yum安装python2.7
下载 ius-release.rpm包 wget https://centos6.iuscommunity.org/ius-release.rpm 安装ius-release.rpm包 rpm -Uv ...
- Entity Framework Code-First(2):What is Code-First?
What is Code-First?: Entity Framework introduced Code-First approach from Entity Framework 4.1. Code ...
- url中传中文
function gotoPage(code,name){//name为中文 window.location.href="upload.jsp?bigCategoryCode="+ ...
- hdu1068
#include<stdio.h>#include<string.h>const int MAXN=1000;int map[MAXN][MAXN];int n;int lin ...
- IOS 完成来电归属地
首先是一个库:(有时间在上传) 然后设置一个工具类 .h @interface HMFoundLocation : NSObject AS_SINGLETON(HMFoundLocation) @pr ...
- Mathematics Base - 期望、方差、协方差、相关系数总结
参考:<深度学习500问> 期望 在概率论和统计学中,数学期望(或均值,亦简称期望)是试验中每次可能结果的概率乘以其结果的总和.它反映随机变量平均取值的大小. 线性运算: \(E(ax+ ...