这是一篇马哥课堂博客作业,这次换个表现方式写,前面先写总体的操作过程,后面显示详情
其实马哥视频讲的非常详尽,听起来特别容易理解,只是让我要写出来那得费九牛二虎之力,估计还得照着视频写。如下仅是看过视频之后的一个操作过程,比较粗糙,仅仅是作业。。。
LVM:logical volume manager version2 逻辑卷管理系统
PV:physical volume,物理卷,在整个逻辑卷管理系统的最下层,可以是任何块设备
VG:volume group,卷组,由一个或多个物理卷组织起来的卷组,并且可以根据以后的需要扩展或者收缩,
PE:physical extent,物理区域,在建立VG的时候划分的VG的存储块,并且创建VG之后PE的大小不能再更改,除非重新建立VG
LV:Logical volume,在VG的基础上划分的逻辑分区,并且也可以根据实际需要扩展或收缩分区的大小
创建逻辑卷: |
创建分区/dev/sda3,并设置分区Id为8e pvcreate /dev/sda3 vgcreate myvg /dev/sda3 lvcreate -n mylv myvg mke2fs -t ext4 /dev/myvg/mylv mount /dev/myvg/mylv /mydate/ |
扩展逻辑卷: |
pvcreate /dev/sda5 vgextend myvg /dev/sda5 lvextend -L +3G /dev/myvg/mylv resize2fs /dev/myvg/mylv |
缩减逻辑卷: |
cp some file to /mydate umount /mydate/ e2fsck -f /dev/myvg/mylv resize2fs /dev/myvg/mylv 2G lvreduce -L 2G /dev/myvg/mylv mount /dev/myvg/mylv /mydate/ 最后查看cp的文件有没有损坏 |
快照的使用: |
lvcreate -L 512M -p r -s -n my_snap /dev/myvg/mylv mount /dev/myvg/my_snap /mnt/mysnap/ 修改/mydate下某个文件再查看 umount mysnap/ lvremove /dev/myvg/my_snap |
删除所有操作: |
umount /mydate/ lvremove /dev/myvg/mylv vgremove myvg->pvremove /dev/sda3 pvremove /dev/sda5 |
创建逻辑卷:
[root@scm-dzm ~]# fdisk -l /dev/sda Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000428cc Device Boot Start End Blocks Id System /dev/sda1 * 1 1275 10240000 83 Linux /dev/sda2 1275 1406 1048576 82 Linux swap / Solaris /dev/sda4 1406 2610 9675225 5 Extended /dev/sda5 1406 1667 2100546 8e Linux LVM /dev/sda6 1668 1929 2104483+ 8e Linux LVM /dev/sda7 1930 2191 2104483+ 8e Linux LVM
[root@scm-dzm dzm]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created
[root@scm-dzm dzm]# vgcreate myvg /dev/sda3 Volume group "myvg" successfully created
[root@scm-dzm dzm]# lvcreate -L 1G -n mylv myvg Logical volume "mylv" created
[root@scm-dzm dzm]# ll /dev/myvg/ total 0 lrwxrwxrwx. 1 root root 7 Jun 23 16:15 mylv -> ../dm-0
[root@scm-dzm dzm]# mke2fs -t ext4 -L mylabel -b 1024 /dev/myvg/mylv
[root@scm-dzm /]# mount /dev/myvg/mylv /mydate/
扩展逻辑卷:
[root@scm-dzm mydate]# pvcreate /dev/sda5 Physical volume "/dev/sda5" successfully created
[root@scm-dzm mydate]# pvs PV VG Fmt Attr PSize PFree /dev/sda3 myvg lvm2 a-- 2.00g 1.00g /dev/sda5 lvm2 --- 2.01g 2.01g
[root@scm-dzm mydate]# vgextend myvg /dev/sda5 Volume group "myvg" successfully extended
[root@scm-dzm ~]# vgs VG #PV #LV #SN Attr VSize VFree myvg 2 0 0 wz--n- 4.00g 4.00g
[root@scm-dzm mydate]# lvextend -L +3G /dev/myvg/mylv Size of logical volume myvg/mylv changed from 1.00 GiB (256 extents) to 4.00 GiB (1024 extents). Logical volume mylv successfully resized
[root@scm-dzm mydate]# resize2fs /dev/myvg/mylv resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/myvg/mylv is mounted on /mydate; on-line resizing required old desc_blocks = 4, new_desc_blocks = 16 Performing an on-line resize of /dev/myvg/mylv to 4194304 (1k) blocks. The filesystem on /dev/myvg/mylv is now 4194304 blocks long.
缩减逻辑卷:
[root@scm-dzm mydate]# cp /etc/fstab ./ [root@scm-dzm mydate]# cp /etc/rc.d/rc.sysinit ./
[root@scm-dzm ~]# umount /mydate/
[root@scm-dzm ~]# e2fsck -f /dev/myvg/mylv 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 mylabel: 13/262144 files (0.0% non-contiguous), 102757/4194304 blocks
[root@scm-dzm ~]# resize2fs /dev/myvg/mylv 2G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/myvg/mylv to 2097152 (1k) blocks. The filesystem on /dev/myvg/mylv is now 2097152 blocks long.
[root@scm-dzm ~]# lvreduce -L 2G /dev/myvg/mylv WARNING: Reducing active logical volume to 2.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mylv? [y/n]: Do you really want to reduce mylv? [y/n]: y Size of logical volume myvg/mylv changed from 4.00 GiB (1024 extents) to 2.00 GiB (512 extents). Logical volume mylv successfully resized
[root@scm-dzm ~]# mount /dev/myvg/mylv /mydate/
[root@scm-dzm ~]# ll /mydate/ total 33 -rw-r--r--. 1 root root 711 Jun 23 16:43 fstab drwx------. 2 root root 12288 Jun 23 16:19 lost+found -rwxr-xr-x. 1 root root 19914 Jun 23 16:44 rc.sysinit
快照:snapshot
快照类似于硬链接,所以必须在同一个分区做快照,快照的大小取决于快照的生命周期内数据变化量,文件数据有变化才会cp其文件到快照区
[root@scm-dzm ~]# lvcreate -L 512M -p r -s -n my_snap /dev/myvg/mylv Logical volume "my_snap" created
[root@scm-dzm mnt]# mount /dev/myvg/my_snap /mnt/mysnap/ mount: block device /dev/mapper/myvg-my_snap is write-protected, mounting read-only
修改/mydate/fstab
[root@scm-dzm mysnap]# ls -il total 33 12 -rw-r--r--. 1 root root 711 Jun 23 16:43 fstab 11 drwx------. 2 root root 12288 Jun 23 16:19 lost+found 13 -rwxr-xr-x. 1 root root 19914 Jun 23 16:44 rc.sysinit [root@scm-dzm mysnap]# ls -il /mydate/ total 33 15 -rw-r--r--. 1 root root 723 Jun 23 17:03 fstab 11 drwx------. 2 root root 12288 Jun 23 16:19 lost+found 13 -rwxr-xr-x. 1 root root 19914 Jun 23 16:44 rc.sysinit
[root@scm-dzm mnt]# umount mysnap/
[root@scm-dzm mnt]# lvremove /dev/myvg/my_snap Do you really want to remove active logical volume my_snap? [y/n]: y Logical volume "my_snap" successfully removed
最后,删除前面所有操作
[root@scm-dzm ~]# umount /mydate/
[root@scm-dzm ~]# lvremove /dev/myvg/mylv Do you really want to remove active logical volume mylv? [y/n]: y Logical volume "mylv" successfully removed
[root@scm-dzm ~]# vgremove myvg Volume group "myvg" successfully removed
[root@scm-dzm ~]# pvremove /dev/sda3 Labels on physical volume "/dev/sda3" successfully wiped [root@scm-dzm ~]# pvremove /dev/sda5 Labels on physical volume "/dev/sda5" successfully wiped
原创文章,作者:Net20_天意,如若转载,请注明出处:http://www.178linux.com/20679