一、新建并挂载目录 /u01 和 /data

1.创建目录挂节点/u01,/data

mkdir -p /{u01,data}

2.创建lv,名称是lv_u01,大小10g,从vg_linuxidc中划分空间,这里的vg_linuxidc是vg的名称。

lvcreate -L 10g -n lv_u01 vg_linuxidc

3.格式化为ext4文件系统

mkfs.ext4 /dev/mapper/vg_linuxidc-lv_u01

4.同样的,创建lv_data

lvcreate -L 10g -n lv_data vg_linuxidc
mkfs.ext4 /dev/mapper/vg_linuxidc-lv_data

5.在/etc/fstab中添加挂载信息,实现开机自动挂载

vi /etc/fstab
/dev/mapper/vg_linuxidc-lv_u01      /u01                    ext4    defaults        1 1
/dev/mapper/vg_linuxidc-lv_data      /data                    ext4    defaults        1 1

二、lv扩容:

第一种方法:直接增大5G,写“+5G”
1.lv扩容5G

lvresize -L +5G /dev/mapper/vg_linuxidc-lv_root

2.文件系统大小变更

resize2fs /dev/mapper/vg_linuxidc-lv_root

第二种方法:原来是10G,增大5G就是“15G”
1.lv扩容到15G

lvresize -L 15G /dev/mapper/vg_linuxidc-lv_u01

2.文件系统大小变更

resize2fs  /dev/mapper/vg_linuxidc-lv_u01

注:以上的lvresize命令操作也可以通过lvextend命令实现。

三、lv缩减:

1.需要先卸载目录

umount /u01

2.这一步是否有根据执行下一步的执行返回决定,看下面的例子

e2fsck -f /dev/mapper/vg_linuxidc-lv_u01

3.文件系统大小变更

resize2fs  /dev/mapper/vg_linuxidc-lv_u01 10G

4.lv缩减

lvresize -L 10G /dev/mapper/vg_linuxidc-lv_u01

5.挂载所有/etc/fstab中记录的目录

mount -a

附:lv缩减的一个实际操作过程:

[root@LINUXIDC-DB ~]# umount /u01
[root@LINUXIDC-DB ~]# resize2fs  /dev/mapper/vg_linuxidc-lv_u01 10G
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mapper/vg_linuxidc-lv_u01' first.

[root@LINUXIDC-DB ~]# e2fsck -f /dev/mapper/vg_linuxidc-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_linuxidc-lv_u01: 12/983040 files (0.0% non-contiguous), 100865/3932160 blocks
[root@LINUXIDC-DB ~]# resize2fs  /dev/mapper/vg_linuxidc-lv_u01 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_linuxidc-lv_u01 to 2621440 (4k) blocks.
The filesystem on /dev/mapper/vg_linuxidc-lv_u01 is now 2621440 blocks long.

[root@LINUXIDC-DB ~]# lvresize -L 10G /dev/mapper/vg_linuxidc-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_linuxidc/lv_u01 changed from 15.00 GiB (3840 extents) to 10.00 GiB (2560 extents).
  Logical volume lv_u01 successfully resized
[root@LINUXIDC-DB ~]# mount -a
[root@LINUXIDC-DB ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_linuxidc-lv_root
                       15G  1.8G   13G  13% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             190M   36M  145M  20% /boot
/dev/mapper/vg_linuxidc-lv_data
                      9.8G   23M  9.2G   1% /data
/dev/mapper/vg_linuxidc-lv_u01
                      9.8G   23M  9.2G   1% /u01
[root@LINUXIDC-DB ~]#

同样lvreduce命令也可以实现lv的缩减。
lvresize命令实际上是包含了lvextend和lvreduce的功能。

–LVM管理的swap扩展,比如增大1024M:

[root@linuxidc-DB ~]# swapoff /dev/mapper/vg_linuxidc-lv_swap

[root@linuxidc-DB ~]# lvextend -L +1024m /dev/mapper/vg_linuxidc-lv_swap

[root@linuxidc-DB ~]# mkswap /dev/mapper/vg_linuxidc-lv_swap

[root@linuxidc-DB ~]# swapon /dev/mapper/vg_linuxidc-lv_swap