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
第一種方法:直接增大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命令實現。
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