邏輯卷管理LVM是一個(gè)多才多藝的硬盤系統(tǒng)工具。無論在Linux或者其他類似的系統(tǒng),都是非常的好用。傳統(tǒng)分區(qū)使用固定大小分區(qū),重新調(diào)整大小十分麻煩。但是,LVM可以創(chuàng)建和管理“邏輯”卷,而不是直接使用物理硬盤??梢宰尮芾韱T彈性的管理邏輯卷的擴(kuò)大縮小,操作簡(jiǎn)單,而不損壞已存儲(chǔ)的數(shù)據(jù)。可以隨意將新的硬盤添加到LVM,以直接擴(kuò)展已經(jīng)存在的邏輯卷。LVM并不需要重啟就可以讓內(nèi)核知道分區(qū)的存在。

概念
DM:Device Mapper
邏輯設(shè)備
MD:multip Device
/dev/md#
meta device
linux系統(tǒng)一切皆文件,所有的設(shè)備都映射成文件在 /dev/目錄下。
DM:邏輯設(shè)備
lvm2
DM:LVM2
快照
lincar
mirror
多路徑(線路管理)實(shí)現(xiàn)數(shù)據(jù)的尋路多路徑。
動(dòng)態(tài)增減(邏輯設(shè)備)
多個(gè)物理磁盤組織成一個(gè)邏輯設(shè)備,可以中間增添。
物理設(shè)備 ---> 物理卷 physical volume PV
卷組 volume Group VG(取決于物理設(shè)備)
邏輯卷 logical volume LV
邏輯卷可以有多個(gè),可以動(dòng)態(tài)增減。(邏輯卷之和不能超過物理容量)
物理邊界,邏輯邊界(文件系統(tǒng)邊界)
邏輯卷相當(dāng)于文件系統(tǒng),對(duì)邏輯卷創(chuàng)建快照??煺站肀仨毢瓦壿嬀碓谕粋€(gè)卷組。要預(yù)留空間。
快照:
訪問同一數(shù)據(jù)的另一個(gè)路徑(如軟鏈接)(小于原數(shù)據(jù))
恢復(fù)原來的數(shù)據(jù),快照區(qū)是有數(shù)據(jù)備份的(發(fā)生修改的數(shù)據(jù))
實(shí)現(xiàn)數(shù)據(jù)備份:線上的數(shù)據(jù)
RAID 1 RAID5 已經(jīng)備份(硬件上備份防止硬件的損壞)
數(shù)據(jù)訪問 --->進(jìn)程 磁盤 數(shù)據(jù)在線數(shù)據(jù)實(shí)時(shí)(備份耗時(shí))
快照瞬間完成
zfs
chunk 和pe相同
PE:physical extend 物理盤區(qū) 加入卷組之后才有PE的概念,pe大小由卷組決定。
邏輯存儲(chǔ)單元邏輯卷:LE :logiacal Extend 邏輯盤區(qū)(角度不同)
擴(kuò)展空間邊界:增加pe 減小空間邊界:減少pe
邏輯卷也可以創(chuàng)建成鏡像的形式。
包含邏輯關(guān)系
pv ---> vg ---> lv
pv即可以示磁盤,分區(qū),raid
創(chuàng)建,刪除,查看
- pv
pvcreate,pvremove(刪除數(shù)據(jù)),pvscan,pvdisplay,pvmove(磁盤上數(shù)據(jù)移動(dòng)到其他磁盤上)
pvs:pvdisplay
linux lvm :8e
pvmove - move physical extents
- vg
vgcreate,vgremove,vgextend,vgreduce
vgdisplay,vgscan
vgcreate -s
vgcreatee vg_name /path/to/pv
刪除vg
vgremove
vgremove - remove a volume group
vgreduce
vgreduce - reduce a volume group
pvmove /dev/sdb1
vgreduce myvg /dev/sdb1
pvremove /dev/sdb1
vgextend - add physical volumes to a volume group
- lv
lvcreate,lvremove,lvextend,lvreduce,lvs,lvdisplay
創(chuàng)建lv
lvcreate -n lv_name -L size#G VG_name
lvcreate -l 50M -n testlv myvg
lvs
lvdisplay
lvremove
操作過程
創(chuàng)建10G的vg
fdisk 只能創(chuàng)建15個(gè)
partprobe
cat /proc/partions
pvcreate /dev/sda{1,2}
pvs
pvdisplay 詳細(xì)顯示
pvdisplay /dev/sda1
pvscan 掃描系統(tǒng)上所有的pv
vgcreate
vgcreate myvg /dev/sda{1,2}
vgs
pvdisplay /dev/sda10
pvcreate /dev/sdb2
vgextend myvg /dev/sda2
創(chuàng)建lv
lv
創(chuàng)建分區(qū):是創(chuàng)建物理邊界
文件系統(tǒng):邏輯邊界
lvm:先擴(kuò)展物理邊界,在擴(kuò)展邏輯邊界。 先縮減邏輯邊界,再縮減物理邊界。
一、擴(kuò)展邏輯卷
擴(kuò)展物理邊界:
lvextend
-L [+]# /path/to/lv 擴(kuò)展到或擴(kuò)展了。。。
擴(kuò)展邏輯邊界:
resize2fs /path/to/lv 大小 設(shè)備擴(kuò)展到多大
resize2fs -p /path/to/lv
lvcreate -L 2G -n testlv mylv
mke2fs -j /dev/myvg/testlv
mkdir /users
mount /dev/myvg/testlv /users
df -lh
lvextend -L 5G /dev/myvg/testlv
df -lh
resize2fs -p /dev/myvg/testlv
df -lh
二、縮減邏輯卷
先縮減邏輯邊界,再縮減物理邊界。
注意:1.不能在線縮減,得先卸載。
2.確??s減后的空間大小依然能存儲(chǔ)原有的所有數(shù)據(jù)。
3.在縮減前應(yīng)該強(qiáng)行檢查文件,以確保文件系統(tǒng)處于一致性狀態(tài)。
resize2fs
ressize2fs /path/to/lv #G
lvreduce -L [-]# /path/to/lv
重新掛載。
df -lh
umount /users
e2fsck -f /dev/myvg/testlv
resize2fs /dev/myvg/testlv 3G
lvreduce -L 3G /dev/myvg/testlv
mount /dev/myvg/testlv /user
三、快照卷
1.快照卷的生命周期為整個(gè)數(shù)據(jù)時(shí)長(zhǎng),在這段時(shí)長(zhǎng)內(nèi),數(shù)據(jù)的增長(zhǎng)量不能超出快照卷大小。
2.快照卷應(yīng)該為只讀。
3.和原卷在同一卷組內(nèi)。
lvcreate
-s
-p r|w
lvcreate -L #
lvcreate -L # -n slv_name -p r /path/to/slv
lvcreate -L 50M -n testlv-snap -s -p r /dev/myvg/testlv
lvs
mount /dev/myvg/testlv-snap /snap
cd /snap
ls
cd /users
tar -jcf /tmp/users.tar.bz2 /users/inittab
umount /snap
lvremove /dev/myvg/testlv-snap
完全備份,增量備份
tar xf /tmp/users.tar.bz2 -C /users
lvm的配置文件
ubuntu@youdi > /etc/lvm > vim /etc/lvm/lvm.conf
lvm相關(guān)命令
COMMANDS
The following commands implement the core LVM functionality.
pvchange Change attributes of a Physical Volume.
pvck Check Physical Volume metadata.
pvcreate Initialize a disk or partition for use by LVM.
pvdisplay Display attributes of a Physical Volume.
pvmove Move Physical Extents.
pvremove Remove a Physical Volume.
pvresize Resize a disk or partition in use by LVM2.
pvs Report information about Physical Volumes.
pvscan Scan all disks for Physical Volumes.
vgcfgbackup Backup Volume Group descriptor area.
vgcfgrestore Restore Volume Group descriptor area.
vgchange Change attributes of a Volume Group.
vgck Check Volume Group metadata.
vgconvert Convert Volume Group metadata format.
vgcreate Create a Volume Group.
vgdisplay Display attributes of Volume Groups.
vgexport Make volume Groups unknown to the system.
vgextend Add Physical Volumes to a Volume Group.
vgimport Make exported Volume Groups known to the system.
vgimportclone Import and rename duplicated Volume Group (e.g. a hardware snapshot).
vgmerge Merge two Volume Groups.
vgmknodes Recreate Volume Group directory and Logical Volume special files
vgreduce Reduce a Volume Group by removing one or more Physical Volumes.
vgremove Remove a Volume Group.
vgrename Rename a Volume Group.
vgs Report information about Volume Groups.
vgscan Scan all disks for Volume Groups and rebuild caches.
vgsplit Split a Volume Group into two, moving any logical volumes from one Volume Group to another by moving entire Physical Volumes.
lvchange Change attributes of a Logical Volume.
lvconvert Convert a Logical Volume from linear to mirror or snapshot.
lvcreate Create a Logical Volume in an existing Volume Group.
lvdisplay Display attributes of a Logical Volume.
lvextend Extend the size of a Logical Volume.
lvmchange Change attributes of the Logical Volume Manager.
lvmconfig Display the configuration information after loading lvm.conf(5) and any other configuration files.
lvmdiskscan Scan for all devices visible to LVM2.
lvmdump Create lvm2 information dumps for diagnostic purposes.
lvreduce Reduce the size of a Logical Volume.
lvremove Remove a Logical Volume.
lvrename Rename a Logical Volume.
lvresize Resize a Logical Volume.
lvs Report information about Logical Volumes.
lvscan Scan (all disks) for Logical Volumes.
查看幫助使用 man
man lvm
man vgscan