1、建立并查看物理磁盘
#fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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
2、建立物理卷
#pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
3、建立卷组
#vgcreate vgdisk /dev/sdb
Volume group "vgdisk" successfully created
4、建立逻辑卷 (-L 150M逻辑卷大小为150M)
#lvcreate -L 150M -n lvdisk vgdisk
Rounding up size to full physical extent 152.00 MiB
Logical volume "lvdisk" created.
5、查看逻辑卷信息
#lvs
lvdisk vgdisk -wi-a----- 152.00m
6、格式化逻辑卷
#mkfs.xfs /dev/vgdisk/lvdisk
meta-data=/dev/vgdisk/lvdisk isize=256 agcount=4, agsize=9728 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=38912, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0,
7、扩展逻辑卷大小 (原大小上增加500m)
#lvextend -L +500M /dev/vgdisk/lvdisk
Size of logical volume vgdisk/lvdisk changed from 152.00 MiB (38 extents) to 652.00 MiB (163 extents).
Logical volume lvdisk successfully resized
8、查看/dev/sdb的UUID,挂载逻辑卷并同步系统空间大小
#blikd
/dev/sdb: UUID="jTbW6E-X2sr-dGfb-1iDs-aUbI-rmNW-Udcv5w" TYPE="LVM2_member"
/dev/mapper/vgdisk-lvdisk: UUID="794ca76a-8bc5-4f3b-934b-916a9e621a1d" TYPE="xfs"
#vim /etc/fstab
UUID=794ca76a-8bc5-4f3b-934b-916a9e621a1d /lv-disk xfs defaults 0 0
#mount -a挂载生效
[# lvdisplay /dev/vgdisk/lvdisk 查看逻辑卷详细信息
--- Logical volume ---
LV Path /dev/vgdisk/lvdisk
LV Name lvdisk
VG Name vgdisk
LV UUID 6l1XUv-3NEH-QxOx-vw6t-KXDc-9C2q-yBG37I
LV Write Access read/write
LV Creation host, time boaili, 2017-02-26 20:52:32 +0800
LV Status available
# open 1
LV Size 652.00 MiB
Current LE 163
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
#xfs_growfs /dev/vgdisk/lvdisk
meta-data=/dev/mapper/vgdisk-lvdisk isize=256 agcount=4, agsize=9728 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=38912, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 38912 to 166912
9、缩小逻辑卷空间大小到200M
#umount /lv-disk
#e2fsck -f /dev/vgdisk/lvdisk 扫描逻辑卷
#resize2fs /dev/vgdisk/lvdisk 200M 缩小文件系统大小
#lvreduce -L 200M /dev/vgdisk/lvdisk 缩小逻辑卷大小
WARNING: Reducing active logical volume to 200.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvdisk? [y/n]:
Size of logical volume vgdisk/lvdisk changed from 652.00 MiB (163 extents) to 200.00 MiB (50 extents).
Logical volume lvdisk successfully resized
# lvdisplay /dev/vgdisk/lvdisk
--- Logical volume ---
LV Path /dev/vgdisk/lvdisk
LV Name lvdisk
VG Name vgdisk
LV UUID 6l1XUv-3NEH-QxOx-vw6t-KXDc-9C2q-yBG37I
LV Write Access read/write
LV Creation host, time boaili, 2017-02-26 20:52:32 +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 8192
Block device 253:2
10、挂载swap
#fdisk /dev/sdb
#mkswap /dev/sdb
#swapon /dev/sdb