1.创建一个分区 [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 或pvdisplay //查看当前pv的信息 PV VG Fmt Attr PSize PFree /dev/sda5 lvm2 a-- 1.87G 1.87G
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
4.备份快照 [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.恢复数据 [root@localhost tmp]# mount /dev/vg0/lv01 /mnt/lv01 [root@localhost tmp]# cd /mnt/lv01 [root@localhost lv01]# ls lost+found [root@localhost lv01]# restore -rf /tmp/lv-backup.dump //恢复 restore: ./lost+found: File exists [root@localhost lv01]# ls //由于之前都删除了,所以这些都是改变的部分 aa ab ac ba bb bc ca cb cc lost+found lv.file restoresymtable
六,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