熱搜:win11繞過(guò)硬件限制安裝 一鍵重裝Win10系統(tǒng) 最干凈的u盤(pán)啟動(dòng)盤(pán) 真正純凈版的win7系統(tǒng)
時(shí)間:2015-02-12 17:35:12 作者:qipeng 來(lái)源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問(wèn): https://m.xitongzhijia.net/xtjc/20150212/38335.html 手機(jī)查看 評(píng)論 反饋
LVM是邏輯卷管理,是Linux下對(duì)磁盤(pán)分區(qū)管理的一種機(jī)制,相信不少人想要知道Linux如何創(chuàng)建LVM和LVM的使用方法,因此小編將針對(duì)LVM的創(chuàng)建和使用做個(gè)詳細(xì)介紹,一起來(lái)學(xué)習(xí)下吧。
LVM講解:
圖像大綱:
1)LVM是什么,作用:
LVM稱(chēng)為邏輯卷管理,作用是提高磁盤(pán)分區(qū)的管理和使用靈活性。
通過(guò)邏輯卷LVM可以有效的管理和分配磁盤(pán)空間,可以把分散的小分區(qū)組合成一個(gè)大的卷組,從卷組中分出需要的空間做出邏輯卷,這樣使得磁盤(pán)擴(kuò)容和縮減方便易用。還有著備份的功能,指的就是lvm快照。
2)創(chuàng)建實(shí)例:
磁盤(pán)-》分區(qū)-》ID修改8e-》保存。
我用來(lái)一個(gè)磁盤(pán)通過(guò)分區(qū)來(lái)做的。還可以每個(gè)磁盤(pán)分一個(gè)區(qū)來(lái)做。
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 8e Linux LVM
/dev/sdb2 1307 2612 10490445 8e Linux LVM
/dev/sdb3 2613 3918 10490445 8e Linux LVM
3)創(chuàng)建物理卷:通過(guò)pvcreate命令。
pvcreate /dev/sdb1
pvcreate /dev/sdb2
pvcreate /dev/sdb3
[root@station106 ~]# pvs(查看創(chuàng)建的物理卷)。
PV VG Fmt Attr PSize PFree
/dev/sda2 vg0 lvm2 a-- 59.99g 7.99g
/dev/sdb1 lvm2 a-- 10.00g 10.00g
/dev/sdb2 lvm2 a-- 10.00g 10.00g
/dev/sdb3 lvm2 a-- 10.00g 10.00g
pvdisplay 查看更加詳細(xì)的內(nèi)容。
。踨oot@station106 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name myvg
PV Size 10.00 GiB / not usable 4.54 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID XP8QfA-WQDd-1v9p-QKxk-AztZ-Nr9e-QbN6Gu
--- Physical volume ---
PV Name /dev/sdb2
VG Name myvg
PV Size 10.00 GiB / not usable 4.58 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID f8Dtdd-fV9e-1yB7-1B8P-21mU-CU2f-fQDAxe
--- Physical volume ---
PV Name /dev/sdb3
VG Name myvg
PV Size 10.00 GiB / not usable 4.58 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID rKNL0x-WXq2-gHYD-T27r-Gf05-a4y3-f4zqzt
4)創(chuàng)建邏輯卷:通過(guò)vgcreate。
。踨oot@station106 ~]# vgcreate myvg /dev/sdb{1,2,3}
Volume group “myvg” successfully created
[root@station106 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 3 0 0 wz--n- 30.00g 30.00g
5)創(chuàng)建邏輯卷,lvcreate。
[root@station106 ~]# lvcreate -L 10G -n test myvg
Logical volume “test” created
-L:空間大小。
-n:邏輯卷名稱(chēng)。
[root@station106 ~]# lvdisplay /dev/myvg/test
--- Logical volume ---
LV Path /dev/myvg/test
LV Name test
VG Name myvg
LV UUID wY1YUF-f0o6-jzu1-mtTL-64p0-qvfC-3QfF8y
LV Write Access read/write
LV Creation host, time station106.magelinux.com, 2014-02-10 11:18:43 +0800
LV Status available
# open 0
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4
6)掛載使用創(chuàng)建好的邏輯卷。
mke2fs -t ext4 /dev/myvg/test 格式化。
mount /dev/myvg/test /mnt/掛載使用。
7)假如有一天邏輯卷不夠用了。怎么從卷組擴(kuò)展呢?如下分析。
邏輯卷擴(kuò)展的大致步驟:
1,先確定擴(kuò)展的大小,并確保所屬的卷組有足夠的剩余空間。
我現(xiàn)在要擴(kuò)展5G,本身是10G的大小。命令如下:
。踨oot@station106 ~]# lvextend -L +5G /dev/myvg/test
Extending logical volume test to 15.00 GiB
Logical volume test successfully resized
2,擴(kuò)展物理邊界。物理邊界指的是本身的物理邊緣大小。
。踨oot@station106 ~]# lvdisplay /dev/myvg/test
--- Logical volume ---
LV Path /dev/myvg/test
LV Name test
VG Name myvg
LV UUID wY1YUF-f0o6-jzu1-mtTL-64p0-qvfC-3QfF8y
LV Write Access read/write
LV Creation host, time station106.magelinux.com, 2014-02-10 11:18:43 +0800
LV Status available
# open 1
LV Size 15.00 GiB
Current LE 3840
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4
當(dāng)擴(kuò)展完物理邊界后你會(huì)發(fā)現(xiàn),掛載中的邏輯卷還是本身的大小。
[root@station106 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-root
ext4 20G 387M 19G 3% /
tmpfs tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 ext4 194M 29M 156M 16% /boot
/dev/mapper/vg0-usr
ext4 9.9G 1.9G 7.6G 20% /usr
/dev/mapper/vg0-var
ext4 20G 288M 19G 2% /var
/dev/mapper/myvg-test
ext4 9.9G 151M 9.2G 2% /mnt
擴(kuò)展邏輯邊界,邏輯邊界指的是掛載后,在使用中的邏輯卷也直接識(shí)別了。
。踨oot@station106 ~]# resize2fs /dev/myvg/test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/test is mounted on /mnt; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/myvg/test to 3932160 (4k) blocks.
The filesystem on /dev/myvg/test is now 3932160 blocks long.
。踨oot@station106 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-root
ext4 20G 387M 19G 3% /
tmpfs tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 ext4 194M 29M 156M 16% /boot
/dev/mapper/vg0-usr
ext4 9.9G 1.9G 7.6G 20% /usr
/dev/mapper/vg0-var
ext4 20G 288M 19G 2% /var
/dev/mapper/myvg-test
ext4 15G 153M 14G 2% /mnt
上述就是擴(kuò)展邏輯卷部分。
實(shí)例演示:縮小邏輯卷。首先為了測(cè)試我去原先掛載的錄下創(chuàng)建一些文件,測(cè)試一下縮小后會(huì)不會(huì)導(dǎo)致文件消失。
縮小邏輯卷的步驟如下:
1)先卸載之前的掛載,并執(zhí)行強(qiáng)制檢測(cè)。
[root@station106 ~]# umount /mnt/
。踨oot@station106 ~]# e2fsck -f /dev/myvg/test
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/myvg/test: 13/983040 files (0.0% non-contiguous), 100864/3932160 blocks
2)縮減邏輯邊界。
。踨oot@station106 ~]# resize2fs /dev/myvg/test 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/test to 2621440 (4k) blocks.
The filesystem on /dev/myvg/test is now 2621440 blocks long.
3)縮減物理邊界。
[root@station106 ~]# lvreduce -L 10G /dev/myvg/test
WARNING: Reducing active logical volume to 10.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce test? [y/n]: y
Reducing logical volume test to 10.00 GiB
Logical volume test successfully resized
縮減后查看:
。踨oot@station106 ~]# lvdisplay /dev/myvg/test
--- Logical volume ---
LV Path /dev/myvg/test
LV Name test
VG Name myvg
LV UUID wY1YUF-f0o6-jzu1-mtTL-64p0-qvfC-3QfF8y
LV Write Access read/write
LV Creation host, time station106.magelinux.com, 2014-02-10 11:18:43 +0800
LV Status available
# open 0
LV Size 10.00 GiB-》這里又變成了10G。
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4
掛載繼續(xù)使用并且查看文件是否存在。
。踨oot@station106 ~]# mount /dev/myvg/test /mnt/
[root@station106 ~]# cd /mnt/
。踨oot@station106 mnt]# ls
accp benet lost+found--》查看還是存在。未丟失。
[root@station106 mnt]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-root
ext4 20G 387M 19G 3% /
tmpfs tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 ext4 194M 29M 156M 16% /boot
/dev/mapper/vg0-usr
ext4 9.9G 1.9G 7.6G 20% /usr
/dev/mapper/vg0-var
ext4 20G 288M 19G 2% /var
/dev/mapper/myvg-test
ext4 9.9G 151M 9.2G 2% /mnt
假設(shè)VG卷組有一天,被邏輯卷用完了,怎么繼續(xù)擴(kuò)展卷組?
1)創(chuàng)建一個(gè)物理卷。
。踨oot@station106 mnt]# pvcreate /dev/sdb5
Physical volume “/dev/sdb5” successfully created
2)把新的物理機(jī)加入到卷組中。
。踨oot@station106 mnt]# vgextend myvg /dev/sdb5
Volume group “myvg” successfully extended
查看增加到的卷組。
[root@station106 mnt]# vgextend myvg /dev/sdb5
Volume group “myvg” successfully extended
。踨oot@station106 mnt]# vgdisplay myvg
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 4
Act PV 4
VG Size 40.00 GiB--》從30G到40G了。
PE Size 4.00 MiB
Total PE 10240
Alloc PE / Size 2560 / 10.00 GiB
Free PE / Size 7680 / 30.00 GiB
VG UUID KyFWJg-BU15-KrOA-uef4-Cckf-eoTz-oM38nu
有擴(kuò)展卷組,就必須有縮減?s減過(guò)程如下。
。踨oot@station106 mnt]# vgreduce myvg /dev/sdb5
Removed “/dev/sdb5” from volume group “myvg”
[root@station106 mnt]# vgdisplay myvg
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 30.00 GiB
PE Size 4.00 MiB
Total PE 7680
Alloc PE / Size 2560 / 10.00 GiB
Free PE / Size 5120 / 20.00 GiB
VG UUID KyFWJg-BU15-KrOA-uef4
-Cckf-eoTz-oM38nu
LVM做快照。
快照是一種邏輯卷,通常為只讀。通俗化說(shuō):“快照大小決定于備份的大小”
作用,能保持快照之前的操作,如后續(xù)操作有了影響,可以恢復(fù)之前的一些操作,也相當(dāng)于快照之前做了備份,創(chuàng)建快照后,后續(xù)的操作隊(duì)快照之前的無(wú)任何影響。
[root@station106 mnt]# lvcreate -s -L 50M -n snap -p r /dev/myvg/test
Rounding up size to full physical extent 52.00 Mi
創(chuàng)建的快照名稱(chēng)snap。
-L 設(shè)置大小。
-p:permission,設(shè)置生成快照的讀寫(xiě)權(quán)限,默認(rèn)為RW;r為只讀。
-s:指定lvcreate生成的是一個(gè)快照。
-n:指定快照名稱(chēng)
掛載快照:下面是備份的內(nèi)容。
mount /dev/myvg/snap /me
。踨oot@station106 me]# ls
accp benet lost+found
然后備份處快照中文件即可,備份后及時(shí)刪除快照。
。踨oot@station106 ~]# lvremove /dev/myvg/snap
Do you really want to remove active logical volume snap? [y/n]: y
Logical volume “snap” successfully removed
上面就是LVM的創(chuàng)建和使用的介紹了,本文通過(guò)幾個(gè)實(shí)例詳細(xì)介紹了LVM的創(chuàng)建,包括邏輯卷的創(chuàng)建、掛載和擴(kuò)展,希望對(duì)你有所幫助。
發(fā)表評(píng)論
共0條
評(píng)論就這些咯,讓大家也知道你的獨(dú)特見(jiàn)解
立即評(píng)論以上留言?xún)H代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)