溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Linux中如何創建邏輯卷管理LVM

發布時間:2021-07-28 15:55:41 來源:億速云 閱讀:273 作者:Leah 欄目:系統運維

Linux中如何創建邏輯卷管理LVM,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

  LVM講解:

  圖像大綱:

Linux中如何創建邏輯卷管理LVM

  1)LVM是什么,作用:

  LVM稱為邏輯卷管理,作用是提高磁盤分區的管理和使用靈活性。

  通過邏輯卷LVM可以有效的管理和分配磁盤空間,可以把分散的小分區組合成一個大的卷組,從卷組中分出需要的空間做出邏輯卷,這樣使得磁盤擴容和縮減方便易用。還有著備份的功能,指的就是lvm快照。

  2)創建實例:

  磁盤-》分區-》ID修改8e-》保存。

  我用來一個磁盤通過分區來做的。還可以每個磁盤分一個區來做。

  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)創建物理卷:通過pvcreate命令。

  pvcreate /dev/sdb1

  pvcreate /dev/sdb2

  pvcreate /dev/sdb3

 ?。踨oot@station106 ~]# pvs(查看創建的物理卷)。

  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 查看更加詳細的內容。

 ?。踨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)創建邏輯卷:通過vgcreate。

 ?。踨oot@station106 ~]# vgcreate myvg /dev/sdb{1,2,3}

  Volume group “myvg” successfully created

Linux中如何創建邏輯卷管理LVM 

 ?。踨oot@station106 ~]# vgs

  VG #PV #LV #SN Attr VSize VFree

  myvg 3 0 0 wz--n- 30.00g 30.00g

  5)創建邏輯卷,lvcreate。

 ?。踨oot@station106 ~]# lvcreate -L 10G -n test myvg

  Logical volume “test” created

  -L:空間大小。

  -n:邏輯卷名稱。

 ?。踨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

  Current LE 2560

  Segments 1

  Allocation inherit

  Read ahead sectors auto

  - currently set to 256

  Block device 253:4

  6)掛載使用創建好的邏輯卷。

  mke2fs -t ext4 /dev/myvg/test 格式化。

  mount /dev/myvg/test /mnt/掛載使用。

  7)假如有一天邏輯卷不夠用了。怎么從卷組擴展呢?如下分析。

  邏輯卷擴展的大致步驟:

  1,先確定擴展的大小,并確保所屬的卷組有足夠的剩余空間。

  我現在要擴展5G,本身是10G的大小。命令如下:

 ?。踨oot@station106 ~]# lvextend -L +5G /dev/myvg/test

  Extending logical volume test to 15.00 GiB

  Logical volume test successfully resized

  2,擴展物理邊界。物理邊界指的是本身的物理邊緣大小。

 ?。踨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

  當擴展完物理邊界后你會發現,掛載中的邏輯卷還是本身的大小。

 ?。踨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 9.9G 151M 9.2G 2% /mnt

  擴展邏輯邊界,邏輯邊界指的是掛載后,在使用中的邏輯卷也直接識別了。

 ?。踨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

  上述就是擴展邏輯卷部分。

  實例演示:縮小邏輯卷。首先為了測試我去原先掛載的錄下創建一些文件,測試一下縮小后會不會導致文件消失。

  縮小邏輯卷的步驟如下:

  1)先卸載之前的掛載,并執行強制檢測。

 ?。踨oot@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)縮減物理邊界。

 ?。踨oot@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

  掛載繼續使用并且查看文件是否存在。

 ?。踨oot@station106 ~]# mount /dev/myvg/test /mnt/

 ?。踨oot@station106 ~]# cd /mnt/

 ?。踨oot@station106 mnt]# ls

  accp benet lost+found--》查看還是存在。未丟失。

 ?。踨oot@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 

  假設VG卷組有一天,被邏輯卷用完了,怎么繼續擴展卷組?

  1)創建一個物理卷。

 ?。踨oot@station106 mnt]# pvcreate /dev/sdb5

  Physical volume “/dev/sdb5” successfully created

  2)把新的物理機加入到卷組中。

 ?。踨oot@station106 mnt]# vgextend myvg /dev/sdb5

  Volume group “myvg” successfully extended

  查看增加到的卷組。

 ?。踨oot@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

  有擴展卷組,就必須有縮減??s減過程如下。

 ?。踨oot@station106 mnt]# vgreduce myvg /dev/sdb5

  Removed “/dev/sdb5” from volume group “myvg”

 ?。踨oot@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做快照。

  快照是一種邏輯卷,通常為只讀。通俗化說:“快照大小決定于備份的大小”

  作用,能保持快照之前的操作,如后續操作有了影響,可以恢復之前的一些操作,也相當于快照之前做了備份,創建快照后,后續的操作隊快照之前的無任何影響。

 ?。踨oot@station106 mnt]# lvcreate -s -L 50M -n snap -p r /dev/myvg/test

  Rounding up size to full physical extent 52.00 Mi

  創建的快照名稱snap。

  -L 設置大小。

  -p:permission,設置生成快照的讀寫權限,默認為RW;r為只讀。

  -s:指定lvcreate生成的是一個快照。

  -n:指定快照名稱

  掛載快照:下面是備份的內容。

  mount /dev/myvg/snap /me

 ?。踨oot@station106 me]# ls

  accp benet lost+found

  然后備份處快照中文件即可,備份后及時刪除快照。

 ?。踨oot@station106 ~]# lvremove /dev/myvg/snap

  Do you really want to remove active logical volume snap? [y/n]: y

  Logical volume “snap” successfully removed

看完上述內容,你們掌握Linux中如何創建邏輯卷管理LVM的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女