1. 程式人生 > >LVM邏輯卷管理器

LVM邏輯卷管理器

LVM邏輯卷管理器

(一)、LVM簡介
LVM是 Logi cal Volume Manager(邏輯卷管理)的簡寫,它由Heinz Mauelshagen在Linux 2.4核心上實現。LVM是一種磁碟管理方式,將一個或多個硬碟的分割槽在邏輯上集合,相當於一個大硬碟來使用,當硬碟的空間不夠使用的時候,可以繼續將其它的硬碟的分割槽加入其中,這樣可以實現磁碟空間的動態管理,相對於普通的磁碟分割槽有很大的靈活性。

與傳統的磁碟與分割槽相比,LVM為計算機提供了更高層次的磁碟儲存。它使系統管理員可以更方便的為應用與使用者分配儲存空間。在LVM管理下的儲存卷可以按需要隨時可以隨意擴大和縮小分割槽大小與移除

(可能需對檔案系統工具進行升級)。LVM也允許按使用者組對儲存捲進行管理,允許管理員用更直觀的名稱(如”sales’、 ‘development’)代替物理磁碟名(如’sda’、’sdb’)來標識儲存卷,可以隨意擴充套件或者縮小某個分割槽的大小,前提這個分割槽是邏輯卷管理的。邏輯卷的功能也和物理分割槽差不多,一樣可以格式化成隨意的檔案系統,掛載到隨意的目錄。同時也支援磁碟配額

(二) 、LVM基本術語
LVM是在磁碟分割槽和檔案系統之間新增的一個邏輯層,來為檔案系統遮蔽下層磁碟分割槽佈局,提供一個抽象的盤卷,在盤捲上建立檔案系統。
物理儲存介質(The physical media):這裡指系統的儲存裝置:硬碟,如:/dev/hda1、/dev/sda等等,是儲存系統最低層的儲存單元。
物理卷(physical volume):物理卷就是指硬碟分割槽或從邏輯上與磁碟分割槽具有同樣功能的裝置(如RAID),是LVM的基本儲存邏輯塊,但和基本的物理儲存介質(如分割槽、磁碟等)比較,卻包含有與LVM相關的管理引數。
卷組(Volume Group):LVM卷組類似於非LVM系統中的物理硬碟,其由物理卷組成。可以在卷組上建立一個或多個“LVM分割槽”(邏輯卷),LVM卷組由一個或多個物理卷組成。
邏輯卷(logical volume):LVM的邏輯卷類似於非LVM系統中的硬碟分割槽,在邏輯卷之上可以建立檔案系統(比如/home或者/usr等)。
PE(physical extent):每一個物理卷被劃分為稱為PE(Physical Extents)的基本單元,具有唯一編號的PE是可以被LVM定址的最小單元。PE的大小是可配置的,預設為4MB。
LE(logical extent):邏輯卷也被劃分為被稱為LE(Logical Extents) 的可被定址的基本單位。在同一個卷組中,LE的大小和PE是相同的,並且一一對應。
簡單來說就是:
PV:是物理的磁碟分割槽
VG:LVM中的物理的磁碟分割槽,也就是PV,必須加入VG,可以將VG理解為一個倉庫或者是幾個大的硬碟。
LV:也就是從VG中劃分的邏輯分割槽
如下圖所示PV、VG、LV三者關係:
這裡寫圖片描述

由四個磁碟分割槽可以組成一個很大的空間,然後在這些空間上劃分一些邏輯分割槽,當一個邏輯分割槽的空間不夠用的時候,可以從剩餘空間上劃分一些空間給空間不夠用的分割槽使用。
(三)、 安裝LVM
首先確定系統中是否安裝了lvm工具:
[[email protected] root]# rpm –qa|grep lvm
lvm-1.0.3-4
(四)、 建立和管理LVM
建立邏輯卷的步驟:
1)通過pvcreate命令將linux分割槽或者物理磁碟處理成物理卷(PV);
2)通過vgcreate命令將建立好的物理卷處理成卷組(Vg);
3)通過lvcreate命令將卷組分成若干個邏輯卷(Lv);
之後我們可以對邏輯捲進行格式化,掛載,刪除等操作,我們可以動態的調整邏輯卷的大小,並且該操作不會影響我們在邏輯卷(Lv)上的資料。

[[email protected] ~]# uname -r
3.10.0-693.el7.x86_64
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 3.8G 16G 20% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 9.0M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 197M 152M 46M 78% /boot
tmpfs 183M 44K 183M 1% /run/user/0
[[email protected] ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004af2f

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 41371647 20480000 83 Linux
/dev/sda3 41371648 45467647 2048000 82 Linux swap / Solaris
fdisk命令後面的Id這一列,
83 是代表EXT2、EXT3或ext4 xfs檔案系統
82 是代表SWAP分割槽
5 是代表擴充套件分割槽
b 是代表fat32檔案系統,所有的可以輸入t-l 檢視
1塊磁碟最多可以劃分4個主分割槽,如果要劃分4個以上的分割槽,最多劃3個主分割槽,一個擴充套件分割槽,注意擴充套件分割槽不能直接使用,需要在擴充套件分割槽裡面劃分邏輯分割槽。

[[email protected] ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004af2f

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 41371647 20480000 83 Linux
/dev/sda3 41371648 45467647 2048000 82 Linux swap / Solaris

Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e):
Using default response e
Selected partition 4
First sector (45467648-62914559, default 45467648):
Using default value 45467648
Last sector, +sectors or +size{K,M,G} (45467648-62914559, default 62914559): +2G
Partition 4 of type Extended and of size 2 GiB is set

Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (45469696-49661951, default 45469696):
Using default value 45469696
Last sector, +sectors or +size{K,M,G} (45469696-49661951, default 49661951): +2G
Value out of range.
Last sector, +sectors or +size{K,M,G} (45469696-49661951, default 49661951): +1G
Partition 5 of type Linux and of size 1 GiB is set

Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (47568896-49661951, default 47568896):
Using default value 47568896
Last sector, +sectors or +size{K,M,G} (47568896-49661951, default 49661951):
Using default value 49661951
Partition 6 of type Linux and of size 1022 MiB is set

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004af2f

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 41371647 20480000 83 Linux
/dev/sda3 41371648 45467647 2048000 82 Linux swap / Solaris
/dev/sda4 45467648 49661951 2097152 5 Extended
/dev/sda5 45469696 47566847 1048576 83 Linux
/dev/sda6 47568896 49661951 1046528 83 Linux

Command (m for help): t ###t改變分割槽ID
Partition number (1-6, default 6): 5
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): t
Partition number (1-6, default 6): 6
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[[email protected] ~]# partprobe
一、 建立邏輯捲過程

1、建立物理卷
將新建立的兩個分割槽/dev/sda5 /dev/sda6轉化成物理卷,主要是新增LVM屬性資訊並劃分PE儲存單元
[[email protected] ~]# pvcreate /dev/sda5 /dev/sda6
Physical volume “/dev/sda5” successfully created.
Physical volume “/dev/sda6” successfully created.
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 lvm2 — 1.00g 1.00g
/dev/sda6 lvm2 — 1022.00m 1022.00m
[[email protected] ~]# pvdisplay
“/dev/sda5” is a new physical volume of “1.00 GiB”
— NEW Physical volume —
PV Name /dev/sda5
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID dFtKfK-qB02-oS9i-SJdx-UOkV-wqOw-xoVkGf

“/dev/sda6” is a new physical volume of “1022.00 MiB”
— NEW Physical volume —
PV Name /dev/sda6
VG Name
PV Size 1022.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID qIxTFN-GN1n-Zcp3-8Hch-brRi-mgir-uWQhpl

2、建立卷組
建立卷組 vgdata ,並將剛才建立好的兩個物理卷加入該卷組.可以看出預設PE大小為4MB,PE是卷組的最小儲存單元.可以通過 –s引數修改大小。
[[email protected] ~]# vgcreate vgdata /dev/sda5 /dev/sda6
Volume group “vgdata” successfully created
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vgdata 2 0 0 wz–n- 1.99g 1.99g
[[email protected] ~]# vgdisplay
— Volume group —
VG Name vgdata
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 1.99 GiB
PE Size 4.00 MiB
Total PE 510
Alloc PE / Size 0 / 0
Free PE / Size 510 / 1.99 GiB
VG UUID KVOR4H-jKHt-PLGf-ferq-t7uq-NK6u-BqGEvr

3、建立邏輯卷
從物理卷vgdata上面分割500M給新的邏輯卷lvdata1.
[[email protected] ~]# lvcreate -L 500M -n lvdata1 vgdata
Logical volume “lvdata1” created.
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvdata1 vgdata -wi-a—– 500.00m
[[email protected] ~]# lvdisplay
— Logical volume —
LV Path /dev/vgdata/lvdata1
LV Name lvdata1
VG Name vgdata
LV UUID BT28Ks-OyPp-7RCw-jV8d-k3Pa-iQAl-GbSd2o
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-08-17 08:55:18 +0800
LV Status available
# open 0
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

使用mkfs.ext4命令在邏輯卷lvdata1上建立ext4檔案系統
[[email protected] ~]# mkfs.ext4 /dev/vgdata/lvdata1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

將建立好的檔案系統/data1掛載到/data1上.(建立好之後,會在/dev/mapper/生成一個軟連線名字為”卷組-邏輯卷”)
[[email protected] ~]# mkdir /data1
[[email protected] ~]# mount /dev/vgdata/lvdata1 /data1
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 3.8G 16G 20% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 9.1M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 197M 152M 46M 78% /boot
tmpfs 183M 44K 183M 1% /run/user/0
/dev/mapper/vgdata-lvdata1 477M 2.3M 445M 1% /data1

便於以後伺服器重啟自動掛載,需要將建立好的檔案系統掛載資訊新增到/etc/fstab裡面.UUID可以通過 blkid命令查詢.
[[email protected] ~]# blkid
/dev/sda2: UUID=”87bc230a-4739-465e-8a67-2eb7ba0565b0” TYPE=”xfs”
/dev/sda1: UUID=”f6ea0c65-3d35-4bfa-9434-45c22a182cb1” TYPE=”xfs”
/dev/sda3: UUID=”ec6a7d0a-8458-4e1c-906b-14769eae6479” TYPE=”swap”
/dev/sda5: UUID=”dFtKfK-qB02-oS9i-SJdx-UOkV-wqOw-xoVkGf” TYPE=”LVM2_member”
/dev/sda6: UUID=”qIxTFN-GN1n-Zcp3-8Hch-brRi-mgir-uWQhpl” TYPE=”LVM2_member”
/dev/mapper/vgdata-lvdata1: UUID=”c3589ba4-0a99-4221-8b41-c05305250023” TYPE=”ext4”
[[email protected] ~]# vim /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Aug 17 00:41:57 2018
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=87bc230a-4739-465e-8a67-2eb7ba0565b0 / xfs defaults 0 0
UUID=f6ea0c65-3d35-4bfa-9434-45c22a182cb1 /boot xfs defaults 0 0
UUID=ec6a7d0a-8458-4e1c-906b-14769eae6479 swap swap defaults 0 0
UUID=c3589ba4-0a99-4221-8b41-c05305250023 /data1 ext4 defaults 0 0

為了檢視/etc/fstab是否設定正確,可以先解除安裝邏輯卷data1,然後使用mount –a 使核心重新讀取/etc/fstab,看是否能夠自動掛載.
[[email protected] ~]# mount |grep data1
/dev/mapper/vgdata-lvdata1 on /data1 type ext4 (rw,relatime,data=ordered)

二、邏輯卷lvdata1擴充套件
給邏輯卷增加空間並不會影響以前空間的使用,所以無需解除安裝檔案系統。設定完成之後,使用resize2fs命令來同步檔案系統。
[[email protected] ~]# lvextend -L +500M /dev/vgdata/lvdata1
Size of logical volume vgdata/lvdata1 changed from 500.00 MiB (125 extents) to 1000.00 MiB (250 extents).
Logical volume vgdata/lvdata1 successfully resized.
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvdata1 vgdata -wi-ao—- 1000.00m

[[email protected] ~]# resize2fs /dev/vgdata/lvdata1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vgdata/lvdata1 is mounted on /data1; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 8
The filesystem on /dev/vgdata/lvdata1 is now 1024000 blocks long.
如果是xfs檔案系統 使用xfs_growfs /dev/wahaha/wahaha1 系統重新識別

三、當卷組不夠用的情況下
新增一塊磁碟/dev/sdb,並將建立好的分割槽加入到已經存在的卷組vgdata中。通過pvs命令檢視是否成功。
[[email protected] ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x394a63e9.

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux’ to ‘Linux LVM’
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[[email protected] ~]# partprobe
[[email protected] ~]# pvcreate /dev/sdb1
Physical volume “/dev/sdb1” successfully created.
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 vgdata lvm2 a– 1020.00m 20.00m
/dev/sda6 vgdata lvm2 a– 1020.00m 1020.00m
/dev/sdb1 lvm2 — 2.00g 2.00g
[[email protected] ~]# vgextend vgdata /dev/sdb1
Volume group “vgdata” successfully extended
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 vgdata lvm2 a– 1020.00m 20.00m
/dev/sda6 vgdata lvm2 a– 1020.00m 1020.00m
/dev/sdb1 vgdata lvm2 a– <2.00g <2.00g
四、當硬碟空間不夠用的情況下,減少邏輯卷的空間釋放給其他邏輯卷使用
減少邏輯卷空間,步驟如下
1、 先解除安裝邏輯卷lvdata
2、 然後通過e2fsck命令檢測邏輯捲上空餘的空間。
3、 使用resize2fs將檔案系統減少到700M。
4、 再使用lvreduce命令將邏輯卷減少到700M。
注意:檔案系統大小和邏輯卷大小一定要保持一致才行。如果邏輯卷大於檔案系統,由於部分割槽域未格式化成檔案系統會造成空間的浪費。如果邏輯卷小於檔案系統,那資料就出問題了
[[email protected] ~]# umount /data1
[[email protected] ~]# e2fsck -f /dev/mapper/vgdata-lvdata1
e2fsck 1.42.9 (28-Dec-2013)
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/mapper/vgdata-lvdata1: 11/254000 files (0.0% non-contiguous), 42817/1024000 blocks
[[email protected] ~]# resize2fs /dev/mapper/vgdata-lvdata1 700M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper//vgdata-lvdata1 to 716800 (1k) blocks.
The filesystem on /dev/mapper//vgdata-lvdata1 is now 716800 blocks long.

[[email protected] ~]# lvreduce -L 700M /dev/vgdata/lvdata1
WARNING: Reducing active logical volume to 700.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vgdata/lvdata1? [y/n]: y
Size of logical volume vgdata/lvdata1 changed from 1000.00 MiB (250 extents) to 700.00 MiB (175 extents).
Logical volume vgdata/lvdata1 successfully resized.
[[email protected] ~]# mount /dev/vgdata/lvdata1 /data1/
[[email protected] ~]# mount |grep data1
/dev/mapper/vgdata-lvdata1 on /data1 type ext4 (rw,relatime,data=ordered)
五、如果某一塊磁碟或者分割槽故障了,將資料快速轉移到相同的卷組其他的空間去。
1、通過pvmove命令轉移空間資料
2、通過vgreduce命令將即將壞的磁碟或者分割槽從卷組vgdata裡面移除除去。
3、通過pvremove命令將即將壞的磁碟或者分割槽從系統中刪除掉
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 vgdata lvm2 a– 1020.00m 320.00m
/dev/sda6 vgdata lvm2 a– 1020.00m 1020.00m
/dev/sdb1 vgdata lvm2 a– <2.00g <2.00g
[[email protected] ~]# pvmove /dev/sda5 /dev/sda6
/dev/sda5: Moved: 1.14%
/dev/sda5: Moved: 100.00%
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 vgdata lvm2 a– 1020.00m 1020.00m
/dev/sda6 vgdata lvm2 a– 1020.00m 320.00m
/dev/sdb1 vgdata lvm2 a– <2.00g <2.00g
[[email protected] ~]# vgreduce vgdata /dev/sda5
Removed “/dev/sda5” from volume group “vgdata”
[[email protected] ~]# pvremove /dev/sda5
Labels on physical volume “/dev/sda5” successfully wiped.
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda6 vgdata lvm2 a– 1020.00m 320.00m
/dev/sdb1 vgdata lvm2 a– <2.00g <2.00g

六、刪除整個邏輯卷
1、先通過umount命令解除安裝掉邏輯卷lvdata1
2、修改/etc/fstab裡面邏輯卷的掛載資訊,否則系統有可能啟動不起來。
3、通過lvremove 刪除邏輯卷lvdata1
4、通過vgremove 刪除卷組vgdata
5、通過pvremove 將物理卷轉化成普通分割槽
[[email protected] ~]# umount /data1/
[[email protected] ~]# lvremove /dev/vgdata/lvdata1
Do you really want to remove active logical volume vgdata/lvdata1? [y/n]: y
Logical volume “lvdata1” successfully removed
[[email protected] ~]# vgremove vgdata
Volume group “vgdata” successfully removed
[[email protected] ~]# pvremove /dev/sda6 /dev/sdb1
Labels on physical volume “/dev/sda6” successfully wiped.
Labels on physical volume “/dev/sdb1” successfully wiped.
[[email protected] ~]# pvs
[[email protected] ~]# lvs
修改分割槽的id標識。修改成普通Linux分割槽即可
[[email protected] ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004af2f

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 41371647 20480000 83 Linux
/dev/sda3 41371648 45467647 2048000 82 Linux swap / Solaris
/dev/sda4 45467648 49661951 2097152 5 Extended
/dev/sda5 45469696 47566847 1048576 8e Linux LVM
/dev/sda6 47568896 49661951 1046528 8e Linux LVM

Command (m for help): t
Partition number (1-6, default 6): 5
Hex code (type L to list all codes): 83
Changed type of partition ‘Linux LVM’ to ‘Linux’

Command (m for help): t
Partition number (1-6, default 6): 6
Hex code (type L to list all codes): 83
Changed type of partition ‘Linux LVM’ to ‘Linux’

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004af2f

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 41371647 20480000 83 Linux
/dev/sda3 41371648 45467647 2048000 82 Linux swap / Solaris
/dev/sda4 45467648 49661951 2097152 5 Extended
/dev/sda5 45469696 47566847 1048576 83 Linux
/dev/sda6 47568896 49661951 1046528 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[[email protected] ~]# partprobe
[[email protected] ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x394a63e9

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 8e Linux LVM

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 83
Changed type of partition ‘Linux LVM’ to ‘Linux’

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# partprobe
總結:
建立邏輯卷的順序:建立Linux分割槽(或者磁碟)—物理卷—卷組—邏輯卷—格式化—掛載分割槽
刪除邏輯卷的順序:解除安裝分割槽—刪除邏輯卷—刪除卷組—-刪除物理卷—刪除分割槽