邏輯卷管理LVM是一個多才多藝的硬碟系統工具。無論在Linux或者其他類似的系統,都是非常的好用。傳統分區使用固定大小分區,重新調整大小十分麻煩。但是,LVM可以建立和管理“邏輯”卷,而不是直接使用實體硬碟。可以讓管理者彈性的管理邏輯卷的擴大縮小,操作簡單,而不損壞已存儲的資料。可以随意将新的硬碟添加到LVM,以直接擴充已經存在的邏輯卷。LVM并不需要重新開機就可以讓核心知道分區的存在。
lvm架構
概念
DM:Device Mapper
邏輯裝置
MD:multip Device
/dev/md#
meta device
linux系統一切皆檔案,所有的裝置都映射成檔案在 /dev/目錄下。
DM:邏輯裝置
lvm2
DM:LVM2
快照
lincar
mirror
多路徑(線路管理)實作資料的尋路多路徑。
動态增減(邏輯裝置)
多個實體磁盤組織成一個邏輯裝置,可以中間增添。
實體裝置 ---> 實體卷 physical volume PV
卷組 volume Group VG(取決于實體裝置)
邏輯卷 logical volume LV
邏輯卷可以有多個,可以動态增減。(邏輯卷之和不能超過實體容量)
實體邊界,邏輯邊界(檔案系統邊界)
邏輯卷相當于檔案系統,對邏輯卷建立快照。快照卷必須和邏輯卷在同一個卷組。要預留白間。
快照:
通路同一資料的另一個路徑(如軟連結)(小于原資料)
恢複原來的資料,快照區是有資料備份的(發生修改的資料)
實作資料備份:線上的資料
RAID 1 RAID5 已經備份(硬體上備份防止硬體的損壞)
資料通路 --->程序 磁盤 資料線上資料實時(備份耗時)
快照瞬間完成
zfs
chunk 和pe相同
-
PE:physical extend 實體盤區 加入卷組之後才有PE的概念,pe大小由卷組決定。
邏輯存儲單元
-
邏輯卷:LE :logiacal Extend 邏輯盤區(角度不同)
擴充空間邊界:增加pe 減小空間邊界:減少pe
邏輯卷也可以建立成鏡像的形式。
包含邏輯關系
pv ---> vg ---> lv
pv即可以示磁盤,分區,raid
建立,删除,檢視
- pv
pvcreate,pvremove(删除資料),pvscan,pvdisplay,pvmove(磁盤上資料移動到其他磁盤上)
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
建立lv
lvcreate -n lv_name -L size#G VG_name
lvcreate -l 50M -n testlv myvg
lvs
lvdisplay
lvremove
操作過程
建立10G的vg
fdisk 隻能建立15個
partprobe
cat /proc/partions
pvcreate /dev/sda{1,2}
pvs
pvdisplay 詳細顯示
pvdisplay /dev/sda1
pvscan 掃描系統上所有的pv
vgcreate
vgcreate myvg /dev/sda{1,2}
vgs
pvdisplay /dev/sda10
pvcreate /dev/sdb2
vgextend myvg /dev/sda2
建立lv
lv
建立分區:是建立實體邊界
檔案系統:邏輯邊界
lvm:先擴充實體邊界,在擴充邏輯邊界。 先縮減邏輯邊界,再縮減實體邊界。
一、擴充邏輯卷
擴充實體邊界:
lvextend
-L [+]# /path/to/lv 擴充到或擴充了。。。
擴充邏輯邊界:
resize2fs /path/to/lv 大小 裝置擴充到多大
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.確定縮減後的空間大小依然能存儲原有的所有資料。
3.在縮減前應該強行檢查檔案,以確定檔案系統處于一緻性狀态。
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.快照卷的生命周期為整個資料時長,在這段時長内,資料的增長量不能超出快照卷大小。
2.快照卷應該為隻讀。
3.和原卷在同一卷組内。
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相關指令
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