LVM:逻辑卷管理,可以动态的管理分区,任意扩容
准备磁盘分区
1、[root@test76 ~]# fdisk /dev/sdb
2、命令n 创建3个分区为1G
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 396 1060290 83 Linux
3、命令t 更改分区类型为8e
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): p
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: 0x3cdb107b
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 8e Linux LVM
/dev/sdb2 133 264 1060290 8e Linux LVM
/dev/sdb3 265 396 1060290 8e Linux LVM
4、准备物理卷
[root@test76 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@test76 ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@test76 ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created
5、列出当前的物理卷
[root@test76 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup lvm2 a-- 9.51g 0
/dev/sdb1 lvm2 --- 1.01g 1.01g
/dev/sdb2 lvm2 --- 1.01g 1.01g
/dev/sdb3 lvm2 --- 1.01g 1.01g
删除物理卷
[root@test76 ~]# pvremove /dev/sdb3
6、准备卷组
[root@test76 ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
Volume group "vg1" successfully created
7、列出卷组
[root@test76 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz--n- 9.51g 0
vg1 3 0 0 wz--n- 3.02g 3.02g
8、删除
[root@test76 ~]# vgremove vg1
9、创建逻辑卷
[root@test76 ~]# lvcreate -L 200M -n lv1 vg1
Logical volume "lv1" created.
10、列出逻辑卷
[root@test76 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg1/lv1
LV Name lv1
VG Name vg1
LV UUID RVgYEp-6wM3-YFq5-C69S-Crp7-53ec-YoQh8S
LV Write Access read/write
LV Creation host, time test76, 2017-10-19 08:20:09 +0800
LV Status available
# open 0
LV Size 200.00 MiB
Current LE 50
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID NOtLqX-KqlD-cGnO-mqhm-eAj1-dMUe-31JACU
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-09-03 07:24:07 +0800
LV Status available
# open 1
LV Size 8.54 GiB
Current LE 2186
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/VolGroup/lv_swap
LV Name lv_swap
VG Name VolGroup
LV UUID 0LUNef-xqk6-NKRJ-6Kfm-AOoX-wEhw-exYwo2
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-09-03 07:24:09 +0800
LV Status available
# open 1
LV Size 992.00 MiB
Current LE 248
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
11、格式化,再挂载
meta-data=/dev/vg1/lv1 isize=256 agcount=4, agsize=12800 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=51200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=1200, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载:
[root@test76 ~]# mount /dev/vg1/lv1 /newbackup/
[root@test76 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 246M 0 246M 0% /dev/shm
/dev/sda1 477M 33M 419M 8% /boot
/dev/mapper/vg1-lv1 196M 11M 186M 6% /newbackup
[root@test76 ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/vg1-lv1 on /newbackup type xfs (rw)
12、删除逻辑卷
[root@test76 ~]# lvremove /dev/vg1/lv1
扩展逻辑卷
1、重新设置卷大小
[root@test76 ~]# lvresize -L 300M /dev/vg1/lv1
2、这个是xfs文件系统下执行
更新操作
[root@test76 ~]# xfs_growfs /dev/vg1/lv1
meta-data=/dev/mapper/vg1-lv1 isize=256 agcount=4, agsize=12800 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=51200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=1200, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 51200 to 76800
[root@test76 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
8.3G 4.2G 3.8G 53% /
tmpfs 246M 0 246M 0% /dev/shm
/dev/sda1 477M 33M 419M 8% /boot
/dev/mapper/vg1-lv1 296M 11M 286M 4% /newbackup #变为300M
ext4下执行:
resize2fs /dev/vg1/lv1 更新逻辑卷信息(ext4执行)
缩减逻辑卷(xfs不支持)
1、umount
2、
e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext)
resize2fs /dev/vg1/lv1 100M 更新逻辑卷信息(ext)
lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
磁盘故障小案例
故障
Give root password for maintenance(or type Control-D to continue)
解决:输入root密码
1、fsck 检测磁盘
2、reboot
本文转自方向对了,就不怕路远了!51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1977511 ,如需转载请自行联系原作者