[root@stau11 ~]# fdisk -l //查看分区的情况
[root@stau11 ~]# fdisk /dev/sda //进行分区
Command (m for help): n //n为添加一个分区,p查看分区
First cylinder (2898-10443, default 2898): //按【Enter】键决定
Using default value 2898 //起始柱面选择默认 值
Last cylinder or +size or +sizeM or +sizeK (289810443, default 10443): +2G // 给2G的大小
Command (m for help): t //更改分区类型
Partition number (1-5): 5 //选着分区
Hex code (type L to list codes): l //分区类型列表
Hex code (type L to list codes):8e //将新添加的分区标注成lvm
Command (m for help): p //查看分区表
/dev/sda5 2756 2999 1959898+ 8e Linux LVM
Command (m for help): w //保存
[root@localhost ~]# partprobe /dev/sda //是系统识别分区(代替重启)
[root@localhost ~]# mkfs.ext3 /dev/sda5 //格式化新添加的分区
2、PV的创建
代码如下:
[root@localhost ~]# pvcreate /dev/sda5 //创建pv
Writing physical volume data to disk "/dev/sda5"
Physical volume "/dev/sda5" successfully created
[root@localhost ~]# pvs //查看当前pv的信息
PV VG Fmt Attr PSize PFree
/dev/sda5 lvm2 a-- 1.87G 1.87G
# umount /dev/vg0/lv01 //卸载逻辑卷/dev/vg0/lv01
# df -h //查看
# e2fsck -f /dev/vg0/lv01 //磁盘校验
# resize2fs /dev/vg0/lv01 500M //回缩文件系统到 500M
# lvreduce -L 500M /dev/vg0/lv01 //回缩分区到 500M
WARNING: Reducing active logical volume to 500.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv01? [y/n]: y
# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv01 vg0 -wi-a- 500.00M //此时已变成500M大小
# mount /dev/vg0/lv01 /mnt/lv01 //重新挂载分区
# df -h //查看
# ls /mnt/lv01 //查看文件
四、lvm的系统快照
1、挂载lvm
代码如下:
[root@localhost ~] # mount /dev/vg0/lv01 /mnt/lv01
[root@localhost ~]# cd /mnt/lv01
[root@localhost lv01]# touch {a,b,c}{a,b,c}
[root@localhost lv01]# ls
aa ab ac ba bb bc ca cb cc lost+found lv.file restoresymtable
[root@localhost tmp]# dump -0u -f /tmp/lv-backup.dump /mnt/lv-backup/ //备份
DUMP: Date of this level 0 dump: Sun Nov 11 14:53:31 2012
DUMP: Dumping /dev/mapper/vg0-lv--backup (/mnt/lv-backup) to /tmp/lv-backup.dump
5、删除快照
代码如下:
[root@localhost tmp]# umount /mnt/lv-backup/
[root@localhost tmp]# lvremove /dev/vg0/lv-backup
Do you really want to remove active logical volume lv-backup? [y/n]: y
Logical volume "lv-backup" successfully removed
6、清空/dev/vg0/lv01下得内容
代码如下:
[root@localhost tmp]# umount /mnt/lv01
[root@localhost tmp]# mkfs.ext3 /dev/vg0/lv01
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
7、lvm的关闭
代码如下:
[root@localhost ~]# umount /mnt/lv01
[root@localhost ~]# lvremove /dev/vg0/lv01 //删除lv
Do you really want to remove active logical volume lv01? [y/n]: y
Logical volume "lv01" successfully removed
[root@localhost ~]# vgchange -a n vg0 //使vg0不具有active标志
0 logical volume(s) in volume group "vg0" now active
[root@localhost ~]# vgremove vg0 //删除vg
Volume group "vg0" successfully removed
[root@localhost ~]# pvremove /dev/sda5 //删除pv
Labels on physical volume "/dev/sda5" successfully wiped