创建LVM卷和快照



一、查看磁盘情况并创建逻辑卷




[root@fengzhao001 ~]# fdisk /dev/sda



The number of cylinders for this disk is set to 60801.


There is nothing wrong with that, but this is larger than 1024,


and could in certain setups cause problems with:


1) software that runs at boot time (e.g., old versions of LILO)


2) booting and partitioning software from other OSs


   (e.g., DOS FDISK, OS/2 FDISK)



Command (m for help): p



Disk /dev/sda: 500.1 GB, 500107862016 bytes


255 heads, 63 sectors/track, 60801 cylinders


Units = cylinders of 16065 * 512 = 8225280 bytes



   Device Boot      Start         End      Blocks   Id  System


/dev/sda1   *           1          13      104391   83  Linux


/dev/sda2              14        6387    51199155   8e  Linux LVM


/dev/sda3            6388       12761    51199155   8e  Linux LVM


/dev/sda4           12762       60801   385881300    5  Extended



1、删除扩展分区


Command (m for help): d


Partition number (1-5): 4



Command (m for help): p



Disk /dev/sda: 500.1 GB, 500107862016 bytes


255 heads, 63 sectors/track, 60801 cylinders


Units = cylinders of 16065 * 512 = 8225280 bytes



   Device Boot      Start         End      Blocks   Id  System


/dev/sda1   *           1          13      104391   83  Linux


/dev/sda2              14        6387    51199155   8e  Linux LVM


/dev/sda3            6388       12761    51199155   8e  Linux LVM



Command (m for help): p



Disk /dev/sda: 500.1 GB, 500107862016 bytes


255 heads, 63 sectors/track, 60801 cylinders


Units = cylinders of 16065 * 512 = 8225280 bytes



   Device Boot      Start         End      Blocks   Id  System


/dev/sda1   *           1          13      104391   83  Linux


/dev/sda2              14        6387    51199155   8e  Linux LVM


/dev/sda3            6388       12761    51199155   8e  Linux LVM



Command (m for help):



2、创建扩展分区



Command (m for help): n


Command action


   e   extended


   p   primary partition (1-4)


4


Invalid partition number for type `4'


Command action


   e   extended


   p   primary partition (1-4)


e


Selected partition 4


First cylinder (12762-60801, default 12762):


Using default value 12762


Last cylinder or +size or +sizeM or +sizeK (12762-60801, default 60801):


Using default value 60801




3、创建逻辑分区



Command (m for help): n


First cylinder (12762-60801, default 12762):


Using default value 12762


Last cylinder or +size or +sizeM or +sizeK (12762-60801, default 60801): +100M



Command (m for help): n


First cylinder (12775-60801, default 12775):


Using default value 12775


Last cylinder or +size or +sizeM or +sizeK (12775-60801, default 60801): +100M



Command (m for help): n


First cylinder (12788-60801, default 12788):


Using default value 12788


Last cylinder or +size or +sizeM or +sizeK (12788-60801, default 60801): +100M



Command (m for help): n


First cylinder (12801-60801, default 12801):


Using default value 12801


Last cylinder or +size or +sizeM or +sizeK (12801-60801, default 60801): +100M




4、查看创建情况



Command (m for help): p



Disk /dev/sda: 500.1 GB, 500107862016 bytes


255 heads, 63 sectors/track, 60801 cylinders


Units = cylinders of 16065 * 512 = 8225280 bytes



   Device Boot      Start         End      Blocks   Id  System


/dev/sda1   *           1          13      104391   83  Linux


/dev/sda2              14        6387    51199155   8e  Linux LVM


/dev/sda3            6388       12761    51199155   8e  Linux LVM


/dev/sda4           12762       60801   385881300    5  Extended


/dev/sda5           12762       12774      104391   83  Linux


/dev/sda6           12775       12787      104391   83  Linux


/dev/sda7           12788       12800      104391   83  Linux


/dev/sda8           12801       12813      104391   83  Linux



Command (m for help):



5、修改分区标记



Command (m for help): t


Partition number (1-8): 5


Hex code (type L to list codes): 8e


Changed system type of partition 5 to 8e (Linux LVM)



Command (m for help): t


Partition number (1-8): 6


Hex code (type L to list codes): 8e


Changed system type of partition 6 to 8e (Linux LVM)



Command (m for help): t


Partition number (1-8): 7


Hex code (type L to list codes): 8e


Changed system type of partition 7 to 8e (Linux LVM)



Command (m for help): t


Partition number (1-8): 8


Hex code (type L to list codes): 8e


Changed system type of partition 8 to 8e (Linux LVM)



Command (m for help): p



Disk /dev/sda: 500.1 GB, 500107862016 bytes


255 heads, 63 sectors/track, 60801 cylinders


Units = cylinders of 16065 * 512 = 8225280 bytes



   Device Boot      Start         End      Blocks   Id  System


/dev/sda1   *           1          13      104391   83  Linux


/dev/sda2              14        6387    51199155   8e  Linux LVM


/dev/sda3            6388       12761    51199155   8e  Linux LVM


/dev/sda4           12762       60801   385881300    5  Extended


/dev/sda5           12762       12774      104391   8e  Linux LVM


/dev/sda6           12775       12787      104391   8e  Linux LVM


/dev/sda7           12788       12800      104391   8e  Linux LVM


/dev/sda8           12801       12813      104391   8e  Linux LVM



6、保存并退出


Command (m for help): w


The partition table has been altered!



Calling ioctl() to re-read partition table.



WARNING: Re-reading the partition table failed with error 16: Device or resource busy.


The kernel still uses the old table.


The new table will be used at the next reboot.


Syncing disks.


[root@fengzhao001 ~]#



二、查看分区状况



[root@fengzhao001 ~]# fdisk -l



Disk /dev/sda: 500.1 GB, 500107862016 bytes


255 heads, 63 sectors/track, 60801 cylinders


Units = cylinders of 16065 * 512 = 8225280 bytes



   Device Boot      Start         End      Blocks   Id  System


/dev/sda1   *           1          13      104391   83  Linux


/dev/sda2              14        6387    51199155   8e  Linux LVM


/dev/sda3            6388       12761    51199155   8e  Linux LVM


/dev/sda4           12762       60801   385881300    5  Extended


/dev/sda5           12762       12774      104391   8e  Linux LVM


/dev/sda6           12775       12787      104391   8e  Linux LVM


/dev/sda7           12788       12800      104391   8e  Linux LVM


/dev/sda8           12801       12813      104391   8e  Linux LVM


[root@fengzhao001 ~]#



三、创建物理卷



1、扫描物理卷并创建



[root@fengzhao001 ~]# pvscan


  PV /dev/sda3   VG Vol0   lvm2 [48.82 GB / 0    free]


  PV /dev/sda2   VG virt   lvm2 [48.82 GB / 1.95 GB free]


  Total: 2 [97.65 GB] / in use: 2 [97.65 GB] / in no VG: 0 [0   ]


[root@fengzhao001 ~]# pvcreate /dev/sda{5,6,7,8}


  Device /dev/sda5 not found (or ignored by filtering).


  Device /dev/sda6 not found (or ignored by filtering).


  Device /dev/sda7 not found (or ignored by filtering).


  Device /dev/sda8 not found (or ignored by filtering).



2、磁盘未找到,需同步


[root@fengzhao001 ~]# partprobe


[root@fengzhao001 ~]# pvcreate /dev/sda{5,6,7,8}


  Writing physical volume data to disk "/dev/sda5"


  Physical volume "/dev/sda5" successfully created


  Writing physical volume data to disk "/dev/sda6"


  Physical volume "/dev/sda6" successfully created


  Writing physical volume data to disk "/dev/sda7"


  Physical volume "/dev/sda7" successfully created


  Writing physical volume data to disk "/dev/sda8"


  Physical volume "/dev/sda8" successfully created


[root@fengzhao001 ~]#



3、磁盘创建成功


[root@fengzhao001 ~]# pvscan


  PV /dev/sda3   VG Vol0            lvm2 [48.82 GB / 0    free]


  PV /dev/sda2   VG virt            lvm2 [48.82 GB / 1.95 GB free]


  PV /dev/sda5                      lvm2 [101.94 MB]


  PV /dev/sda6                      lvm2 [101.94 MB]


  PV /dev/sda7                      lvm2 [101.94 MB]


  PV /dev/sda8                      lvm2 [101.94 MB]


  Total: 6 [98.05 GB] / in use: 2 [97.65 GB] / in no VG: 4 [407.78 MB]


[root@fengzhao001 ~]#



四、创建卷组



1、扫描卷组情况



[root@fengzhao001 ~]# vgscan


  Reading all physical volumes.  This may take a while...


  Found volume group "Vol0" using metadata type lvm2


  Found volume group "virt" using metadata type lvm2



2、创建卷组并查看情况



[root@fengzhao001 ~]# vgcreate vg1 /dev/sda{5,6}


  Volume group "vg1" successfully created



[root@fengzhao001 ~]# vgdisplay


  --- Volume group ---


  VG Name               vg1


  System ID             


  Format                lvm2


  Metadata Areas        2


  Metadata Sequence No  1


  VG Access             read/write


  VG Status             resizable


  MAX LV                0


  Cur LV                0


  Open LV               0


  Max PV                0


  Cur PV                2


  Act PV                2


  VG Size               200.00 MB


  PE Size               4.00 MB


  Total PE              50


  Alloc PE / Size       0 / 0   


  Free  PE / Size       50 / 200.00 MB


  VG UUID               d5kLtl-1f9k-crTG-xFjZ-UlGE-fTVm-XXjeG0


   


  --- Volume group ---


  VG Name               Vol0


  System ID             


  Format                lvm2


  Metadata Areas        1


  Metadata Sequence No  2


  VG Access             read/write


  VG Status             resizable


  MAX LV                0


  Cur LV                1


  Open LV               1


  Max PV                0


  Cur PV                1


  Act PV                1


  VG Size               48.82 GB


  PE Size               4.00 MB


  Total PE              12499


  Alloc PE / Size       12499 / 48.82 GB


  Free  PE / Size       0 / 0   


  VG UUID               uyZVp6-V4Yd-tOWe-7lAe-dPho-h4v3-2GZxBU


   


  --- Volume group ---


  VG Name               virt


  System ID             


  Format                lvm2


  Metadata Areas        1


  Metadata Sequence No  4


  VG Access             read/write


  VG Status             resizable


  MAX LV                0


  Cur LV                3


  Open LV               2


  Max PV                0


  Cur PV                1


  Act PV                1


  VG Size               48.82 GB


  PE Size               4.00 MB


  Total PE              12499


  Alloc PE / Size       12000 / 46.88 GB


  Free  PE / Size       499 / 1.95 GB


  VG UUID               91Txq2-ZK0n-R6oT-0Tvh-HlTu-p1Bs-2A8ZOP


   


[root@fengzhao001 ~]#



五、建立逻辑卷



[root@fengzhao001 ~]# lvscan


  ACTIVE            '/dev/Vol0/vol_root' [48.82 GB] inherit


  ACTIVE            '/dev/virt/station' [19.53 GB] inherit


  ACTIVE            '/dev/virt/windows' [7.81 GB] inherit


  ACTIVE            '/dev/virt/server' [19.53 GB] inherit


[root@fengzhao001 ~]#


[root@fengzhao001 ~]# lvcreate -L +200M -n lv1 vg1


  Logical volume "lv1" created


[root@fengzhao001 ~]#


[root@fengzhao001 ~]# lvscan


  ACTIVE            '/dev/vg1/lv1' [200.00 MB] inherit


  ACTIVE            '/dev/Vol0/vol_root' [48.82 GB] inherit


  ACTIVE            '/dev/virt/station' [19.53 GB] inherit


  ACTIVE            '/dev/virt/windows' [7.81 GB] inherit


  ACTIVE            '/dev/virt/server' [19.53 GB] inherit



[root@fengzhao001 ~]# lvdisplay |grep lv1


  LV Name                /dev/vg1/lv1


[root@fengzhao001 ~]#



查看逻辑卷状况


[root@fengzhao001 ~]# lvdisplay /dev/vg1/lv1


  --- Logical volume ---


  LV Name                /dev/vg1/lv1


  VG Name                vg1


  LV UUID                RMmdmX-vJR2-ho6f-Otu9-RqGa-Mvef-e8F6aG


  LV Write Access        read/write


  LV Status              available


  # open                 0


  LV Size                200.00 MB


  Current LE             50


  Segments               2


  Allocation             inherit


  Read ahead sectors     auto


  - currently set to     256


  Block device           253:4


   


[root@fengzhao001 ~]#



六、格式化并挂载逻辑卷



1、格式化逻辑卷



[root@fengzhao001 ~]# mkfs.ext3 /dev/vg1/lv1


mke2fs 1.39 (29-May-2006)


Filesystem label=


OS type: Linux


Block size=1024 (log=0)


Fragment size=1024 (log=0)


51200 inodes, 204800 blocks


10240 blocks (5.00%) reserved for the super user


First data block=1


Maximum filesystem blocks=67371008


25 block groups


8192 blocks per group, 8192 fragments per group


2048 inodes per group


Superblock backups stored on blocks:


        8193, 24577, 40961, 57345, 73729



Writing inode tables: done                            


Creating journal (4096 blocks): done


Writing superblocks and filesystem accounting information: done



This filesystem will be automatically checked every 35 mounts or


180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@fengzhao001 ~]#



2、挂载逻辑卷



[root@fengzhao001 ~]# mkdir /shiyanlvm


[root@fengzhao001 ~]# mount /dev/vg1/lv1 /shiyanlvm/


[root@fengzhao001 ~]# mount


/dev/mapper/Vol0-vol_root on / type ext3 (rw)


proc on /proc type proc (rw)


sysfs on /sys type sysfs (rw)


devpts on /dev/pts type devpts (rw,gid=5,mode=620)


/dev/sda1 on /boot type ext3 (rw)


tmpfs on /dev/shm type tmpfs (rw)


none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)


sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)


/dev/mapper/vg1-lv1 on /shiyanlvm type ext3 (rw)


[root@fengzhao001 ~]#



七、调整LVM卷大小



1、扩大卷组



[root@fengzhao001 ~]# vgextend vg1 /dev/sda{7,8}


  Volume group "vg1" successfully extended



[root@fengzhao001 ~]# vgscan


  Reading all physical volumes.  This may take a while...


  Found volume group "vg1" using metadata type lvm2


  Found volume group "Vol0" using metadata type lvm2


  Found volume group "virt" using metadata type lvm2



[root@fengzhao001 ~]# vgdisplay


  --- Volume group ---


  VG Name               vg1


  System ID             


  Format                lvm2


  Metadata Areas        4


  Metadata Sequence No  3


  VG Access             read/write


  VG Status             resizable


  MAX LV                0


  Cur LV                1


  Open LV               1


  Max PV                0


  Cur PV                4


  Act PV                4


  VG Size               400.00 MB


  PE Size               4.00 MB


  Total PE              100


  Alloc PE / Size       50 / 200.00 MB


  Free  PE / Size       50 / 200.00 MB


  VG UUID               d5kLtl-1f9k-crTG-xFjZ-UlGE-fTVm-XXjeG0





2、扩大逻辑卷



[root@fengzhao001 ~]# lvextend -L +200M /dev/vg1/lv1


  Extending logical volume lv1 to 400.00 MB


  Logical volume lv1 successfully resized



3、对比之前的结果



[root@fengzhao001 ~]# df -h


Filesystem            Size  Used Avail Use% Mounted on


/dev/mapper/Vol0-vol_root


                       48G  4.4G   41G  10% /


/dev/sda1              99M   13M   81M  14% /boot


tmpfs                 3.8G     0  3.8G   0% /dev/shm


/dev/mapper/vg1-lv1   194M  5.6M  179M   4% /shiyanlvm



4、同步



[root@fengzhao001 ~]# resize2fs /dev/vg1/lv1


resize2fs 1.39 (29-May-2006)


Filesystem at /dev/vg1/lv1 is mounted on /shiyanlvm; on-line resizing required


Performing an on-line resize of /dev/vg1/lv1 to 409600 (1k) blocks.


The filesystem on /dev/vg1/lv1 is now 409600 blocks long.



5、对比之后的结果



[root@fengzhao001 ~]# df -h


Filesystem            Size  Used Avail Use% Mounted on


/dev/mapper/Vol0-vol_root


                       48G  4.4G   41G  10% /


/dev/sda1              99M   13M   81M  14% /boot


tmpfs                 3.8G     0  3.8G   0% /dev/shm


/dev/mapper/vg1-lv1   388M  6.3M  362M   2% /shiyanlvm


[root@fengzhao001 ~]#



6、减小逻辑卷





(1)卸载逻辑卷



[root@fengzhao001 ~]# umount /shiyanlvm



[root@fengzhao001 ~]# mount


/dev/mapper/Vol0-vol_root on / type ext3 (rw)


proc on /proc type proc (rw)


sysfs on /sys type sysfs (rw)


devpts on /dev/pts type devpts (rw,gid=5,mode=620)


/dev/sda1 on /boot type ext3 (rw)


tmpfs on /dev/shm type tmpfs (rw)


none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)


sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)



(2)先减小文件系统大小



[root@fengzhao001 ~]# resize2fs /dev/vg1/lv1 200M


resize2fs 1.39 (29-May-2006)


Please run 'e2fsck -f /dev/vg1/lv1' first.



[root@fengzhao001 ~]# e2fsck -f /dev/vg1/lv1


e2fsck 1.39 (29-May-2006)


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/vg1/lv1: 11/98784 files (9.1% non-contiguous), 18639/401408 blocks


[root@fengzhao001 ~]#



[root@fengzhao001 ~]# resize2fs /dev/vg1/lv1 200M


resize2fs 1.39 (29-May-2006)


Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.


The filesystem on /dev/vg1/lv1 is now 204800 blocks long.



(3)查看文件系统大小


[root@fengzhao001 ~]# mkdir /shiyan


[root@fengzhao001 ~]# mount /dev/vg1/lv1 /shiyan


[root@fengzhao001 ~]# df -h


Filesystem            Size  Used Avail Use% Mounted on


/dev/mapper/Vol0-vol_root


                       48G  4.4G   41G  10% /


/dev/sda1              99M   13M   81M  14% /boot


tmpfs                 3.8G     0  3.8G   0% /dev/shm


/dev/mapper/vg1-lv1   194M  5.6M  179M   4% /shiyan



(4)此时LVM大小(400M)



[root@fengzhao001 ~]# lvs


  LV       VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert


  vol_root Vol0 -wi-ao  48.82G                                      


  lv1      vg1  -wi-a- 412.00M                                      


  server   virt -wi-ao  19.53G                                      


  station  virt -wi-ao  19.53G                                      


  windows  virt -wi-a-   7.81G                                      


                             


[root@fengzhao001 ~]#



(5)再减小逻辑卷大小[逻辑卷大小必须大于或等于文件系统大小]



[root@fengzhao001 ~]# lvreduce -L 205M /dev/vg1/lv1


  Rounding up size to full physical extent 208.00 MB


  WARNING: Reducing active logical volume to 208.00 MB


  THIS MAY DESTROY YOUR DATA (filesystem etc.)


Do you really want to reduce lv1? [y/n]: y


  Reducing logical volume lv1 to 208.00 MB


  Logical volume lv1 successfully resized


[root@fengzhao001 ~]# lvdisplay


  --- Logical volume ---


  LV Name                /dev/vg1/lv1


  VG Name                vg1


  LV UUID                RMmdmX-vJR2-ho6f-Otu9-RqGa-Mvef-e8F6aG


  LV Write Access        read/write


  LV Status              available


  # open                 0


  LV Size                208.00 MB


  Current LE             52


  Segments               3


  Allocation             inherit


  Read ahead sectors     auto


  - currently set to     256


  Block device           253:2




八、减小卷组大小



[root@fengzhao001 ~]# vgreduce vg1 /dev/sda{8,9}


  Removed "/dev/sda8" from volume group "vg1"


  Removed "/dev/sda9" from volume group "vg1"


[root@fengzhao001 ~]# vgdisplay


  --- Volume group ---


  VG Name               vg1


  System ID             


  Format                lvm2


  Metadata Areas        3


  Metadata Sequence No  23


  VG Access             read/write


  VG Status             resizable


  MAX LV                0


  Cur LV                1


  Open LV               0


  Max PV                0


  Cur PV                3


  Act PV                3


  VG Size               300.00 MB


  PE Size               4.00 MB


  Total PE              75


  Alloc PE / Size       52 / 208.00 MB


  Free  PE / Size       23 / 92.00 MB


  VG UUID               d5kLtl-1f9k-crTG-xFjZ-UlGE-fTVm-XXjeG0


   



九、创建快照



1、新加磁盘(250M)



[root@fengzhao001 ~]# fdisk /dev/sda



The number of cylinders for this disk is set to 60801.


There is nothing wrong with that, but this is larger than 1024,


and could in certain setups cause problems with:


1) software that runs at boot time (e.g., old versions of LILO)


2) booting and partitioning software from other OSs


   (e.g., DOS FDISK, OS/2 FDISK)



Command (m for help): p



Disk /dev/sda: 500.1 GB, 500107862016 bytes


255 heads, 63 sectors/track, 60801 cylinders


Units = cylinders of 16065 * 512 = 8225280 bytes



   Device Boot      Start         End      Blocks   Id  System


/dev/sda1   *           1          13      104391   83  Linux


/dev/sda2              14        6387    51199155   8e  Linux LVM


/dev/sda3            6388       12761    51199155   8e  Linux LVM


/dev/sda4           12762       60801   385881300    5  Extended


/dev/sda5           12762       12774      104391   8e  Linux LVM


/dev/sda6           12775       12787      104391   8e  Linux LVM


/dev/sda7           12788       12800      104391   8e  Linux LVM


/dev/sda8           12801       12813      104391   8e  Linux LVM



Command (m for help): d


Partition number (1-8): 8



Command (m for help): p



Disk /dev/sda: 500.1 GB, 500107862016 bytes


255 heads, 63 sectors/track, 60801 cylinders


Units = cylinders of 16065 * 512 = 8225280 bytes



   Device Boot      Start         End      Blocks   Id  System


/dev/sda1   *           1          13      104391   83  Linux


/dev/sda2              14        6387    51199155   8e  Linux LVM


/dev/sda3            6388       12761    51199155   8e  Linux LVM


/dev/sda4           12762       60801   385881300    5  Extended


/dev/sda5           12762       12774      104391   8e  Linux LVM


/dev/sda6           12775       12787      104391   8e  Linux LVM


/dev/sda7           12788       12800      104391   8e  Linux LVM



Command (m for help): n


First cylinder (12801-60801, default 12801):


Using default value 12801


Last cylinder or +size or +sizeM or +sizeK (12801-60801, default 60801): +250M    



Command (m for help): t


Partition number (1-8): 8


Hex code (type L to list codes): 8e


Changed system type of partition 8 to 8e (Linux LVM)



Command (m for help): w


The partition table has been altered!



Calling ioctl() to re-read partition table.



WARNING: Re-reading the partition table failed with error 16: Device or resource busy.


The kernel still uses the old table.


The new table will be used at the next reboot.


Syncing disks.



同步


[root@fengzhao001 ~]# partprobe



新建物理卷


[root@fengzhao001 ~]# pvcreate /dev/sda8


  Writing physical volume data to disk "/dev/sda8"


  Physical volume "/dev/sda8" successfully created


[root@fengzhao001 ~]#



扩展卷组


[root@fengzhao001 ~]# vgextend vg1 /dev/sda8


  Volume group "vg1" successfully extended



[root@fengzhao001 ~]# vgdisplay


  --- Volume group ---


  VG Name               vg1


  System ID             


  Format                lvm2


  Metadata Areas        4


  Metadata Sequence No  11


  VG Access             read/write


  VG Status             resizable


  MAX LV                0


  Cur LV                1


  Open LV               1


  Max PV                0


  Cur PV                4


  Act PV                4


  VG Size               540.00 MB


  PE Size               4.00 MB


  Total PE              135


  Alloc PE / Size       53 / 212.00 MB


  Free  PE / Size       82 / 328.00 MB


  VG UUID               d5kLtl-1f9k-crTG-xFjZ-UlGE-fTVm-XXjeG0


   


    


[root@fengzhao001 ~]#



2、创建快照



[root@fengzhao001 ~]# lvcreate -L 250M -s -n kuaizhaoss /dev/vg1/lv1


  Rounding up size to full physical extent 252.00 MB


  Logical volume "kuaizhaoss" created



查看


[root@fengzhao001 ~]# lvscan


  ACTIVE   Original '/dev/vg1/lv1' [212.00 MB] inherit


  ACTIVE   Snapshot '/dev/vg1/kuaizhaoss' [252.00 MB] inherit


  ACTIVE            '/dev/Vol0/vol_root' [48.82 GB] inherit


  ACTIVE            '/dev/virt/station' [19.53 GB] inherit


  ACTIVE            '/dev/virt/windows' [7.81 GB] inherit


  ACTIVE            '/dev/virt/server' [19.53 GB] inherit


[root@fengzhao001 ~]#



3、挂载快照


[root@fengzhao001 ~]# mkdir /kuaizhao



[root@fengzhao001 ~]# mount /dev/vg1/kuaizhaoss /kuaizhao/


[root@fengzhao001 ~]#



4、是否成功挂载


[root@fengzhao001 ~]# mount


/dev/mapper/Vol0-vol_root on / type ext3 (rw)


proc on /proc type proc (rw)


sysfs on /sys type sysfs (rw)


devpts on /dev/pts type devpts (rw,gid=5,mode=620)


/dev/sda1 on /boot type ext3 (rw)


tmpfs on /dev/shm type tmpfs (rw)


none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)


sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)


/dev/mapper/vg1-lv1 on /shiyanlvm type ext3 (rw)


/dev/mapper/vg1-kuaizhaoss on /kuaizhao type ext3 (rw)


[root@fengzhao001 ~]#



5、对比文件系统与快照



(1)在原逻辑卷中添加内容



[root@fengzhao001 ~]# dd if=/dev/zero of=/shiyanlvm/file1 bs=1M count=100


100+0 records in


100+0 records out


104857600 bytes (105 MB) copied, 1.06717 seconds, 98.3 MB/s



(2)查看文件系统大小


[root@fengzhao001 ~]# ls -lh /shiyanlvm/file1


-rw-r--r-- 1 root root 100M Feb 27 03:48 /shiyanlvm/file1



(3)查看快照


[root@fengzhao001 ~]# ls -lh /kuaizhao


total 12K


drwx------ 2 root root 12K Feb 27 03:41 lost+found



(4)在快照中输入内容



[root@fengzhao001 ~]# dd if=/dev/zero of=/kuaizhao/file2 bs=1M count=100


100+0 records in


100+0 records out


104857600 bytes (105 MB) copied, 1.00667 seconds, 104 MB/s



(5)查看快照



[root@fengzhao001 ~]# ls -lh /kuaizhao


total 101M


-rw-r--r-- 1 root root 100M Feb 27 03:49 file2


drwx------ 2 root root  12K Feb 27 03:41 lost+found



(6)查看文件系统



[root@fengzhao001 ~]# ls -lh /shiyanlvm


total 101M


-rw-r--r-- 1 root root 100M Feb 27 03:48 file1


drwx------ 2 root root  12K Feb 27 03:41 lost+found



(7)在快照原文件输入50M内容



[root@fengzhao001 ~]# dd if=/dev/zero of=/kuaizhao/file2 bs=1M count=50


50+0 records in


50+0 records out


52428800 bytes (52 MB) copied, 0.882904 seconds, 59.4 MB/s



[root@fengzhao001 ~]# ls -lh /shiyanlvm


total 101M


-rw-r--r-- 1 root root 100M Feb 27 03:48 file1


drwx------ 2 root root  12K Feb 27 03:41 lost+found



(8)查看原文件变化



[root@fengzhao001 ~]# ls -lh /kuaizhao


total 51M


-rw-r--r-- 1 root root 50M Feb 27 03:50 file2


drwx------ 2 root root 12K Feb 27 03:41 lost+found



(9)在快照中输入另一个文件(100M)


[root@fengzhao001 ~]# dd if=/dev/zero of=/kuaizhao/file3 bs=1M count=50


50+0 records in


50+0 records out


52428800 bytes (52 MB) copied, 0.480316 seconds, 109 MB/s



(10)对比文件系统和快照



[root@fengzhao001 ~]# ls -lh /kuaizhao


total 101M


-rw-r--r-- 1 root root 50M Feb 27 03:50 file2


-rw-r--r-- 1 root root 50M Feb 27 03:51 file3


drwx------ 2 root root 12K Feb 27 03:41 lost+found



[root@fengzhao001 ~]# ls -lh /shiyanlvm


total 101M


-rw-r--r-- 1 root root 100M Feb 27 03:48 file1


drwx------ 2 root root  12K Feb 27 03:41 lost+found


[root@fengzhao001 ~]#