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工具:
[root@www root]# rpm –qa|grep lvm
lvm-1.0.3-4
(四)、 创建和管理LVM
创建逻辑卷的步骤:
1)通过pvcreate命令将linux分区或者物理磁盘处理成物理卷(PV);
2)通过vgcreate命令将创建好的物理卷处理成卷组(Vg);
3)通过lvcreate命令将卷组分成若干个逻辑卷(Lv);
之后我们可以对逻辑卷进行格式化,挂载,删除等操作,我们可以动态的调整逻辑卷的大小,并且该操作不会影响我们在逻辑卷(Lv)上的数据。

[root@localhost ~]# uname -r
3.10.0-693.el7.x86_64
[root@localhost ~]# 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
[root@localhost ~]# 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个主分区,一个扩展分区,注意扩展分区不能直接使用,需要在扩展分区里面划分逻辑分区。

[root@localhost ~]# 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.
[root@localhost ~]# partprobe
一、 创建逻辑卷过程

1、创建物理卷
将新创建的两个分区/dev/sda5 /dev/sda6转化成物理卷,主要是添加LVM属性信息并划分PE存储单元
[root@localhost ~]# pvcreate /dev/sda5 /dev/sda6
Physical volume “/dev/sda5” successfully created.
Physical volume “/dev/sda6” successfully created.
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 lvm2 — 1.00g 1.00g
/dev/sda6 lvm2 — 1022.00m 1022.00m
[root@localhost ~]# 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参数修改大小。
[root@localhost ~]# vgcreate vgdata /dev/sda5 /dev/sda6
Volume group “vgdata” successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vgdata 2 0 0 wz–n- 1.99g 1.99g
[root@localhost ~]# 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.
[root@localhost ~]# lvcreate -L 500M -n lvdata1 vgdata
Logical volume “lvdata1” created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvdata1 vgdata -wi-a—– 500.00m
[root@localhost ~]# 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文件系统
[root@localhost ~]# 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/生成一个软连接名字为”卷组-逻辑卷”)
[root@localhost ~]# mkdir /data1
[root@localhost ~]# mount /dev/vgdata/lvdata1 /data1
[root@localhost ~]# 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命令查询.
[root@localhost ~]# 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”
[root@localhost ~]# 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,看是否能够自动挂载.
[root@localhost ~]# mount |grep data1
/dev/mapper/vgdata-lvdata1 on /data1 type ext4 (rw,relatime,data=ordered)

二、逻辑卷lvdata1扩展
给逻辑卷增加空间并不会影响以前空间的使用,所以无需卸载文件系统。设置完成之后,使用resize2fs命令来同步文件系统。
[root@localhost ~]# 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.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvdata1 vgdata -wi-ao—- 1000.00m

[root@localhost ~]# 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命令查看是否成功。
[root@localhost ~]# 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.
[root@localhost ~]# partprobe
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume “/dev/sdb1” successfully created.
[root@localhost ~]# 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
[root@localhost ~]# vgextend vgdata /dev/sdb1
Volume group “vgdata” successfully extended
[root@localhost ~]# 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。
注意:文件系统大小和逻辑卷大小一定要保持一致才行。如果逻辑卷大于文件系统,由于部分区域未格式化成文件系统会造成空间的浪费。如果逻辑卷小于文件系统,那数据就出问题了
[root@localhost ~]# umount /data1
[root@localhost ~]# 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
[root@localhost ~]# 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.

[root@localhost ~]# 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.
[root@localhost ~]# mount /dev/vgdata/lvdata1 /data1/
[root@localhost ~]# mount |grep data1
/dev/mapper/vgdata-lvdata1 on /data1 type ext4 (rw,relatime,data=ordered)
五、如果某一块磁盘或者分区故障了,将数据快速转移到相同的卷组其他的空间去。
1、通过pvmove命令转移空间数据
2、通过vgreduce命令将即将坏的磁盘或者分区从卷组vgdata里面移除除去。
3、通过pvremove命令将即将坏的磁盘或者分区从系统中删除掉
[root@localhost ~]# 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
[root@localhost ~]# pvmove /dev/sda5 /dev/sda6
/dev/sda5: Moved: 1.14%
/dev/sda5: Moved: 100.00%
[root@localhost ~]# 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
[root@localhost ~]# vgreduce vgdata /dev/sda5
Removed “/dev/sda5” from volume group “vgdata”
[root@localhost ~]# pvremove /dev/sda5
Labels on physical volume “/dev/sda5” successfully wiped.
[root@localhost ~]# 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 将物理卷转化成普通分区
[root@localhost ~]# umount /data1/
[root@localhost ~]# lvremove /dev/vgdata/lvdata1
Do you really want to remove active logical volume vgdata/lvdata1? [y/n]: y
Logical volume “lvdata1” successfully removed
[root@localhost ~]# vgremove vgdata
Volume group “vgdata” successfully removed
[root@localhost ~]# pvremove /dev/sda6 /dev/sdb1
Labels on physical volume “/dev/sda6” successfully wiped.
Labels on physical volume “/dev/sdb1” successfully wiped.
[root@localhost ~]# pvs
[root@localhost ~]# lvs
修改分区的id标识。修改成普通Linux分区即可
[root@localhost ~]# 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.
[root@localhost ~]# partprobe
[root@localhost ~]# 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.
[root@localhost ~]# partprobe
总结:
创建逻辑卷的顺序:创建Linux分区(或者磁盘)—物理卷—卷组—逻辑卷—格式化—挂载分区
删除逻辑卷的顺序:卸载分区—删除逻辑卷—删除卷组—-删除物理卷—删除分区

猜你喜欢

转载自blog.csdn.net/weixin_42859372/article/details/81774507