标签:
1. 添加新的物理磁盘
2. 创建新的分区,最多可分配【3个主分区,1个扩展分区】 或 【4个主分区】,扩展分区又可以有多个分区;
window常见的分配方式:
方式1:[1个主分区(C盘)+1个扩展分区(包括3个分区,D,E,F盘)]
方式2:[4个主分区,分别作为:C、D、E、F盘]
若是使用LVM方式分区,分区时最好选择LVM分区方式;
3. 创建PV;
4. 创建VG;
5. 创建LV;
6. 格式化LV,ext3,ext4等格式;
7. 挂载LV到指定目录;
8. 将挂载信息写入:/etc/fstab;
9. LVM扩容操作
9.1 LV的扩容;
(1) 使用VG的Free空间,对LV扩容;
(2) 完成后需要在对文件系统扩容;
9.2 VG的扩容
方式1: 通过增加PV来实现
方式2: 通过扩展raid(磁盘阵列)设备的容量来间接对VG扩容
10. LVM缩减操作
10.1 LV的缩减
10.2 VG的缩减
11. 删除LVM
# fdisk -l
[root@localhost ~]# fdisk -l
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 1.3G 46G 3% /
devtmpfs 911M 0 911M 0% /dev
tmpfs 921M 0 921M 0% /dev/shm
tmpfs 921M 8.5M 912M 1% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/sda1 477M 142M 310M 32% /boot
/dev/mapper/centos-home 47G 251M 44G 1% /home
tmpfs 185M 0 185M 0% /run/user/0
[root@localhost ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 209592319 104283136 8e Linux LVM
--------LVM分区测试时,主要使用了sd{b,c,d,e,f,g}等----
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sdd: 16.1 GB, 16106127360 bytes, 31457280 sectors
Disk /dev/sde: 16.1 GB, 16106127360 bytes, 31457280 sectors
Disk /dev/sdf: 16.1 GB, 16106127360 bytes, 31457280 sectors
Disk /dev/sdg: 10.7 GB, 10737418240 bytes, 20971520 sectors
-----下面是系统安装后存在的,为方便说明,后面将其显示省略-----
Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Disk /dev/mapper/centos-home: 50.9 GB, 50944016384 bytes, 99500032 sectors
# fdisk /dev/sdb
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 (分区号选择1)
First sector (2048-31457279, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279):
Using default value 31457279
Partition 1 of type Linux and of size 15 GiB is set
Command (m for help): p (查看已经创建的分区)
Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 sectors
Device Boot Start End Blocks Id System
/dev/sdb1 2048 31457279 15727616 83 Linux (系统默认为83,即:Linux)
Command (m for help): t (修改分区格式)
Selected partition 1
Hex code (type L to list all codes): 8e (8e为Linux LVM格式)
Changed type of partition ‘Linux‘ to ‘Linux LVM‘
Command (m for help): p
Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 sectors
Device Boot Start End Blocks Id System
/dev/sdb1 2048 31457279 15727616 8e Linux LVM
Command (m for help): w
# pvcreate /dev/sdb1 (创建PV)
# pvdisplay
"/dev/sdb1" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID dZRM2W-X2Lz-I3Jz-i4S4-E8fN-BF4K-oZqhd3
# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 10.00g 10.00g
# pvscan
PV /dev/sdb1 lvm2 [10.00 GiB]
# vgcreate vg0 /dev/sdb1 /dev/sdc -s 64M
Physical volume "/dev/sdc" successfully created
Volume group "vg0" successfully created
使用分区/dev/sdb1 和 磁盘/dev/sdc 来创建vg,并设置PE大小为64M
# pvsPV VG Fmt Attr PSize PFree/dev/sdb1 vg0 lvm2 a-- 10.00g 10.00g/dev/sdc vg0 lvm2 a-- 10.00g 10.00g
# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 0 0 wz--n- 19.99g 19.99g
上面知道:/dev/sdb1和/dev/sdb都是10G,所以vg0的大小为19.99G;
- # vgdisplay vg0
--- Volume group ---
VG Name vg0
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 19.99 GiB
PE Size 64.00 MiB
Total PE 320
Alloc PE / Size 0 / 0
Free PE / Size 5118 / 19.99 GiB
VG UUID m58K2q-eIsC-1Z3T-DySZ-cgKb-Sd3L-UbrW2z
# lvcreate -L 8G -n lv1 vg0
Logical volume "lv1" created.
从vg0中分出8G的空间给lv1使用
# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 1 0 wz--n- 19.99g 11.99g
由于分出了8G给lv1,所以VFree之剩下:11.99G
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg0 -wi-a----- 8.00g
# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/lv1
LV Name lv1
VG Name vg0
LV UUID wevRbf-Iy3b-wPfa-mK4a-DFoq-A24w-8q5axT
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-09-08 09:58:34 +0800
LV Status available
# open 0
LV Size 8.00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
# mkfs.ext3 /dev/vg0/lv1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
# mkdir /mnt/lv1
# mount /dev/vg0/lv1 /mnt/lv1
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv1 ext3 7.8G 19M 7.4G 1% /mnt/lv1
# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 1 0 wz--n- 19.99g 11.99g
现在还有11.99G可用
# lvextend -L +3G /dev/vg0/lv1
Size of logical volume vg0/lv1 changed from 8.00 GiB (2048 extents) to 11.00 GiB (2816 extents).
Logical volume lv1 successfully resized.
将lv1添加3G容量
# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- 99.45g 4.00m
vg0 2 1 0 wz--n- 19.99g 8.99g
由原先的11.99G可用变为8.99G可用
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg0 -wi-ao---- 11.00g
由原先的8G增加到了11G
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv1 ext3 7.8G 19M 7.4G 1% /mnt/lv1
可是发现实际容量并没有变化,还是7.8G
这时需要对文件系统进行扩容
# resize2fs /dev/vg0/lv1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg0/lv1 is mounted on /mnt/lv1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg0/lv1 is now 2883584 blocks long.
对文件系统扩容
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv1 ext3 11G 21M 11G 1% /mnt/lv1
发现此时lv1的容量变为了11G
# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created
创建PV
# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg0 lvm2 a-- 10.00g 0
/dev/sdc vg0 lvm2 a-- 10.00g 8.99g
/dev/sdd lvm2 --- 15.00g 15.00g
新增加的PV有15G
# vgextend vg0 /dev/sdd
Volume group "vg0" successfully extended
使用PV对VG扩容
# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 3 1 0 wz--n- 34.99g 23.99g
扩容后的vg0由19.99G变为了34.99G
标签:
原文地址:http://www.cnblogs.com/ssslinppp/p/5853312.html