点评:LVM(Logical Volume Manager)是一个应用于Linux的内核的逻辑卷管理器,是Linux环境下对磁盘进行分区管理的一种机制
一、LVM 简介
LVM(Logical Volume Manager)是一个应用于Linux的内核的逻辑卷管理器,是Linux环境下对磁盘进行分区管理的一种机制。先介绍几个有关LVM的名词 二、相关命令介绍
1、物理卷PV 确定扩展多大 确定当前逻辑卷所在的卷组有足够的空闲空间;
扩展: 三、lv之示例 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 //保存 www.jbxue.com [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
3、VG的创建
[root@localhost ~]# vgcreate vg0 /dev/sda5 //vg0为当前vg的名 Volume group "vg0" successfully created [root@localhost ~]# vgs //查看vg的信息 VG #PV #LV #SN Attr VSize VFree vg0 1 0 0 wz--n- 1.87G 1.87G
4、lv的创建
[root@localhost ~]# lvcreate -L 500M -n lv01 vg0 Logical volume "lv01" created [root@localhost ~]# lvs //查看lv的信息 LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv01 vg0 -wi-a- 500.00M www.jbxue.com You have mail in /var/spool/mail/root [root@localhost ~]# mkfs.ext3 /dev/vg0/lv01 //格式化
lvm的使用 5、lv的增大
[root@localhost ~]# lvextend -L +300M /dev/vg0/lv01 //(原来lv大小500M ,拉伸分区到 800M) Extending logical volume lv01 to 800.00 MB Logical volume lv01 successfully resized [root@localhost ~]# resize2fs /dev/vg0/lv01 //拉伸文件系统 [root@localhost ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv01 vg0 -wi-ao 800.00M //大小变成了800M
6、lv的减小
# 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 www.jbxue.com 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
2、为lvm创建快照
[root@localhost lv01]# lvcreate -L 64M -s -n lv-backup /dev/vg0/lv01 Logical volume "lv-backup" created
3、挂载快照
[root@localhost lv01]# mkdir /mnt/lv-backup [root@localhost mnt]# mount -o ro /dev/vg0/lv-backup /mnt/lv-backup/
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、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 www.jbxue.com [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 (责任编辑:IT) |