Linux中的創建PV-VG-LV

操作系統爲Linux5.5

LVM是邏輯盤卷管理(Logical Volume Manager)的簡稱,他是磁盤管理的另一種工具,就目前基本上所有操作系統均支持,LVM是建立在硬盤和分區之上的一個邏輯層,來提高磁盤分區管理的靈活性。通過LVM系統管理員可以輕鬆管理磁盤分區,如:將若干個磁盤分區連接爲一個整塊的卷組(volume group),形成一個存儲池。管理員可以在卷組上隨意創建邏輯卷組(logical volumes),並進一步在邏輯卷組上創建文件系統。管理員通過LVM可以方便的調整存儲卷組的大小,並且可以對磁盤存儲按照組的方式進行命名、管理和分配,例如按照使用用途進行定義:“DBdata”和“DBSoft”,而不是使用物理磁盤名“sda”和“sdb”或”hda”和”hdb”。而且當系統添加了新的磁盤,通過LVM管理員就不必將磁盤的文件移動到新的磁盤上以充分利用新的存儲空間,而是直接擴展文件系統跨越磁盤即可,架構可以參考如下圖:

(1)給/dev/sdb分區,分成兩個區

[root@ENMOEDU ~]# fdisk -l

[root@ENMOEDU ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-2610, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +3G

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 2

First cylinder (367-2610, default 367):

Using default value 367

Last cylinder or +size or +sizeM or +sizeK (367-2610, default 2610):

Using default value 2610

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@ENMOEDU ~]# fdisk -l

/dev/sdb1 1 366 2939863+ 83 Linux

/dev/sdb2 367 2610 18024930 83 Linux

(2)將/dev/sdb1設置成LVM;

[root@ENMOEDU ~]# fdisk /dev/sdb

 

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): t

Partition number (1-4): 1

 

Hex code (type L to list codes): 8e

Changed system type of partition 1 to 8e (Linux LVM)

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

(3)創建PV

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

(4)創建VG存儲池

[root@ENMOEDU ~]# vgcreate VolGroup01 /dev/sdb1

[root@ENMOEDU ~]# vgdisplay

--- Volume group ---

VG Name VolGroup01

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 1

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 1

Act PV 1

VG Size 2.80 GB

PE Size 4.00 MB

Total PE 717

Alloc PE / Size 0 / 0

Free PE / Size 717 / 2.80 GB

VG UUID fhg0w0-2J1E-tduQ-r6HR-OCiQ-Jkkx-egbcq0

 

(5)增大VG存儲池
[root@ENMOEDU ~]#vgextend VolGroup01 /dev/adb2

(6)分配LV邏輯卷

[root@ENMOEDU ~]# lvcreate -L 500M -n LogVol07 VolGroup01

Logical volume "LogVol07" created

[root@ENMOEDU ~]# lvdisplay

--- Logical volume ---

LV Name /dev/VolGroup01/LogVol07

VG Name VolGroup01

LV UUID UAKz2h-jhTv-8oF0-R71E-NhSB-jFfp-wdvqnl

LV Write Access read/write

LV Status available

# open 0

LV Size 500.00 MB

Current LE 125

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:7

(7)格式化分區

[root@ENMOEDU ~]# mkfs.ext3 /dev/VolGroup01/LogVol07

8)添加/u02掛載點

[root@ENMOEDU ~]# mkdir /u02

[root@ENMOEDU ~]# vi /etc/fstab

/*添加下面的命令*/

/dev/VolGroup01/LogVol07 /u02 ext3 defaults 1 2

[root@ENMOEDU ~]# mount -a

[root@ENMOEDU ~]# mount

 

9)刪除LV中的/dev/mapper/VolGroup01-LogVol07

Umount對象;

[root@ENMOEDU ~]# umount /u02

刪除對象LV

[root@ENMOEDU ~]# lvremove /dev/mapper/VolGroup01-LogVol07

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

: y

Logical volume "LogVol07" successfully removed

查看刪除成功;

[root@ENMOEDU ~]# lvdisplay

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章