环境:CentOS 6.7
一、新建并挂载目录 /u01 和 /data
1.创建目录挂节点/u01,/data
mkdir -p /{u01,data}
2.创建lv,名称是lv_u01,大小10g,从vg_jydb中划分空间,这里的vg_jydb是vg的名称。
lvcreate -L 10g -n lv_u01 vg_jydb
3.格式化为ext4文件系统
mkfs.ext4 /dev/mapper/vg_jydb-lv_u01
4.同样的,创建lv_data
lvcreate -L 10g -n lv_data vg_jydb
mkfs.ext4 /dev/mapper/vg_jydb-lv_data
5.在/etc/fstab中添加挂载信息,实现开机自动挂载
vi /etc/fstab
/dev/mapper/vg_jydb-lv_u01 /u01 ext4 defaults 1 1
/dev/mapper/vg_jydb-lv_data /data ext4 defaults 1 1
二、lv扩容:
第一种方法:直接增大5G,写“+5G”
1.lv扩容5G
lvresize -L +5G /dev/mapper/vg_jydb-lv_root
2.文件系统大小变更
resize2fs /dev/mapper/vg_jydb-lv_root
第二种方法:原来是10G,增大5G就是“15G”
1.lv扩容到15G
lvresize -L 15G /dev/mapper/vg_jydb-lv_u01
2.文件系统大小变更
resize2fs /dev/mapper/vg_jydb-lv_u01
注:以上的lvresize命令操作也可以通过lvextend命令实现。
三、lv缩减:
1.需要先卸载目录
umount /u01
2.这一步是否有根据执行下一步的执行返回决定,看下面的例子
e2fsck -f /dev/mapper/vg_jydb-lv_u01
3.文件系统大小变更
resize2fs /dev/mapper/vg_jydb-lv_u01 10G
4.lv缩减
lvresize -L 10G /dev/mapper/vg_jydb-lv_u01
5.挂载所有/etc/fstab中记录的目录
mount -a
附:lv缩减的一个实际操作过程:
[root@JY-DB ~]# umount /u01
[root@JY-DB ~]# resize2fs /dev/mapper/vg_jydb-lv_u01 10G
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mapper/vg_jydb-lv_u01' first.
[root@JY-DB ~]# e2fsck -f /dev/mapper/vg_jydb-lv_u01
e2fsck 1.41.12 (17-May-2010)
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/vg_jydb-lv_u01: 12/983040 files (0.0% non-contiguous), 100865/3932160 blocks
[root@JY-DB ~]# resize2fs /dev/mapper/vg_jydb-lv_u01 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_jydb-lv_u01 to 2621440 (4k) blocks.
The filesystem on /dev/mapper/vg_jydb-lv_u01 is now 2621440 blocks long.
[root@JY-DB ~]# lvresize -L 10G /dev/mapper/vg_jydb-lv_u01
WARNING: Reducing active logical volume to 10.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_u01? [y/n]: y
Size of logical volume vg_jydb/lv_u01 changed from 15.00 GiB (3840 extents) to 10.00 GiB (2560 extents).
Logical volume lv_u01 successfully resized
[root@JY-DB ~]# mount -a
[root@JY-DB ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_jydb-lv_root
15G 1.8G 13G 13% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 190M 36M 145M 20% /boot
/dev/mapper/vg_jydb-lv_data
9.8G 23M 9.2G 1% /data
/dev/mapper/vg_jydb-lv_u01
9.8G 23M 9.2G 1% /u01
[root@JY-DB ~]#
同样lvreduce命令也可以实现lv的缩减。
lvresize命令实际上是包含了lvextend和lvreduce的功能。