歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 磁盤管理之LVM

磁盤管理之LVM

日期:2017/2/28 14:29:04   编辑:Linux教程

LVM是邏輯盤卷管理(Logical Volume Manager)的簡稱,它是Linux環境下對磁盤分區進行管理的一種機制,LVM是建立在硬盤和分區之上的一個邏輯層,從而提高磁盤分區管理的靈活性。接下來通過實驗來詳細了解LVM的使用。

Linux入門教程:使用LVM邏輯卷管理器管理靈活存儲 http://www.linuxidc.com/Linux/2014-07/104443.htm

CentOS 6.3下配置LVM(邏輯卷管理) http://www.linuxidc.com/Linux/2014-06/103839.htm

Linux LVM簡明教程 http://www.linuxidc.com/Linux/2014-06/103390.htm

Linux的LVM(Logical Volume Manager) 學習筆記 http://www.linuxidc.com/Linux/2014-05/101880.htm

RHCE認證筆記:LVM實驗 http://www.linuxidc.com/Linux/2014-04/99685.htm

Linux系統管理之LVM案例 http://www.linuxidc.com/Linux/2014-02/96987.htm

1.實驗環境准備.添加一塊未使用過的磁盤/dev/sdb,使用fdisk從其中分出兩個5G的分區,並且將其分區類型該為8e

[root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0f199ec4

Device Boot Start End Blocks Id System

/dev/sdb1 1 654 5253223+ 8e Linux LVM

/dev/sdb2 655 1308 5253255 8e Linux LVM


2.創建物理卷:

[root@localhost ~]# pvcreate /dev/sdb1

Physical volume "/dev/sdb1" successfully created

[root@localhost ~]# pvcreate /dev/sdb2

dev_is_mpath: failed to get device for 8:18

Physical volume "/dev/sdb2" successfully created

[root@localhost ~]# pvscan

PV /dev/sda2 VG vg0 lvm2 [59.99 GiB / 7.99 GiB free]

PV /dev/sdb1 lvm2 [5.01 GiB]

PV /dev/sdb2 lvm2 [5.01 GiB]

Total: 3 [70.01 GiB] / in use: 1 [59.99 GiB] / in no VG: 2 [10.02 GiB]


3.在物理卷的基礎上創建卷組,將/dev/sdb1加入卷組

[root@localhost ~]# vgcreate test /dev/sdb1

Volume group "test" successfully create

[root@localhost ~]# vgscan #可以看到卷組test已經創建成功

Reading all physical volumes. This may take a while...

Found volume group "test" using metadata type lvm2

Found volume group "vg0" using metadata type lvm2


4.在卷組test中創建一個大小為4G的邏輯卷test1

[root@localhost ~]# lvcreate -L 4G -n test1 test

Logical volume "test1" created

[root@localhost ~]# lvscan

ACTIVE '/dev/test/test1' [4.00 GiB] inherit #test1已經創建成功

ACTIVE '/dev/vg0/root' [20.00 GiB] inherit

ACTIVE '/dev/vg0/swap' [2.00 GiB] inherit

ACTIVE '/dev/vg0/usr' [10.00 GiB] inherit

ACTIVE '/dev/vg0/var' [20.00 GiB] inherit


5.接下來就可以按照普通分區,對test1進行格式化,並且掛載使用了

[root@localhost ~]# mkfs.ext4 /dev/test/test1

mke2fs 1.41.12 (17-May-2010)

......

This filesystem will be automatically checked every 34 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@localhost ~]# mkdir /test

[root@localhost ~]# mount /dev/test/test1 /test/

[root@localhost ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg0-root 20G 428M 19G 3% /

tmpfs 246M 0 246M 0% /dev/shm

/dev/sda1 194M 30M 155M 16% /boot

/dev/mapper/vg0-usr 9.9G 2.3G 7.2G 24% /usr

/dev/mapper/vg0-var 20G 361M 19G 2% /var

/dev/mapper/test-test1 4.0G 136M 3.7G 4% /test #邏輯卷成功創建


6.在/test下放入一個文件,測試可否使用

[root@localhost test]# echo "lv test" >a.txt

[root@localhost test]# cat a.txt

lv test

更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2014-08/105381p2.htm

Copyright © Linux教程網 All Rights Reserved