LVM 的创建,扩展,缩减及建立快照

 Lvm 是逻辑卷管理( logical Volume manager)的简称是在linux下的一种管理机制,lvm 是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵活性,lvm 是磁盘分区和文件系统之间添加的一个逻辑层,来为下层磁盘分区布局,提供一个抽象的盘卷,在盘卷上建立文件系统

第一部分

 先创建三个但分区,且每个分区为1G 并把该分区改为LVM的文件类型,lvm的代号是8e

 

 

1首先创建物理卷

# pvcreate /dev/sdb1

  Physical volume "/dev/sdb1" successfully created

 

查看创建的物理卷

 #pvdisplay   /dev/sdb1

  /dev/cdrom: open failed: No medium found

  --- Physical volume ---

  PV Name               /dev/sda2

  VG Name               vol0

  PV Size               17.58 GB / not usable 18.53 MB

  Allocatable           yes

  PE Size (KByte)       32768

  Total PE              562

  Free PE               291

  Allocated PE          271

  PV UUID               08q5Bg-Q1No-xGPj-Nl8y-IrAx-tuOU-Q8RsGi

  

  "/dev/sdb1" is a new physical volume of "964.81 MB"

  --- NEW Physical volume ---

  PV Name               /dev/sdb1

  VG Name              

  PV Size               964.81 MB

  Allocatable           NO

  PE Size (KByte)       0

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               G15TOa-rLX3-DqqC-oE44-TKXR-1jqE-A0guz6

 

 

 

 

3创建逻辑卷组

# vgcreate  vol1  /dev/sdb1

  Volume group "vol1" successfully created

 

查看创建的逻辑卷组

# vgdispaly  /dev/vol1

 

--- Volume group ---

  VG Name               vol1

  System ID             

  Format                lvm2

  Metadata Areas        1

  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                1

  Act PV                1

  VG Size               964.00 MB

  PE Size               4.00 MB

  Total PE              241

  Alloc PE / Size       0 / 0  

  Free  PE / Size       241 / 964.00 MB

  VG UUID               TpscPr-FA4g-t3fv-WXty-o6u0-KtXf-Cv0Ge6

  

 

4创建逻辑卷

  #lvcreate   -L 500M  -n lv1 /dev/vol1

Insufficient free extents (241) in volume group vol1: 256 required

  Logical volume "lv1" created

查看创建的逻辑卷

#lvdiisplay  /dev/vol1/lv1

--- Logical volume ---

  LV Name                /dev/vol1/lv1

  VG Name                vol1

  LV UUID                YsaXYW-Hkcx-Kl1B-Cdrq-C7Tw-8hhQ-Bhhvy9

  LV Write Access        read/write

  LV Status              available

  # open                 0

  LV Size                500.00 MB

  Current LE             125

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:2

 

 

创建目录

 #mkdir  /lv1

6格式化逻辑卷

 # mkfs.ext3 /dev/vol1/lv1

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

128016 inodes, 512000 blocks

25600 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67633152

63 block groups

8192 blocks per group, 8192 fragments per group

2032 inodes per group

Superblock backups stored on blocks:

        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

 

Writing inode tables: done                           

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 36 mounts or

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

挂载逻辑卷

#mount /dev/vol1/lv1   /lv1

如果想要开机启动自动挂载需要编辑文件/etc/fstab

 /dev/vol1/lv1   /lv1     ext3  defaults    0 0

 

 

扩展逻辑组

 # vgextend  vol1  /dev/sdb7

Volume group "vol1" successfully extended

 

查看逻辑组

 #vgs --name /dev/vol1

  VG #PV #LV #SN Attr VSize VFree

  LVM2_VG_NAME='vol1' LVM2_PV_COUNT='2' LVM2_LV_COUNT='1' LVM2_SNAP_COUNT='0' LVM2_VG_ATTR='wz--n-' LVM2_VG_SIZE='1.88G' LVM2_VG_FREE='1.39G'

10 扫描逻辑组的

# vgscan

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

  Found volume group "vol1" using metadata type lvm2

  Found volume group "vol0" using metadata type lvm2

 

 

 

11 能够显示所有的逻辑组包括隐藏的逻辑组

# vgexport  -a

  Volume group "vol1" has active logical volumes

  Volume group "vol0" has active logical volumes

 

12 能够隐藏所有的逻辑组

# vgimport  -a

  Volume group "vol1" is not exported

  Volume group "vol0" is not exported

13扩展逻辑卷的大小

 #lvextend  -L  +200M       /dev/vol1/lv1

  Extending logical volume lv1 to 700.00 MB

  Logical volume lv1 successfully resized

 注: lvextend   -L  [+|-] numM   设备名

  + 表示在原大小的上再增加numM

   - 表示在原大小上减小numM

     什么不加时表示扩展到的大小

 

 

第二部分

 缩减逻辑卷的大小

 先卸载逻辑卷

 #umount  /dev/vol1/lv1   

检测磁盘

 #fsck  -f

fsck 1.39 (29-May-2006)

e2fsck 1.39 (29-May-2006)

/dev/vol0/root is mounted. 

 

WARNING!!!  Running e2fsck on a mounted filesystem may cause

SEVERE filesystem damage.

 

Do you really want to continue (y/n)? yes

 

/dev/vol0/root: recovering journal

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/vol0/root: ***** FILE SYSTEM WAS MODIFIED *****

/dev/vol0/root: ***** REBOOT LINUX *****

/dev/vol0/root: 109901/2097152 files (0.7% non-contiguous), 758106/2097152 blocks

3强制检测逻辑卷

  # e2fsck  -f  /dev/vol1/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/vol1/lv1: 12/128016 files (8.3% non-contiguous), 26703/512000 blocks

 

 

 

指定缩减的大小

# resize2fs /dev/vol1/lv1 400M

resize2fs 1.39 (29-May-2006)

Resizing the filesystem on /dev/vol1/lv1 to 409600 (1k) blocks.

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

 

5执行缩减的命令

# lvreduce -L 400M /dev/vol1/lv1

  WARNING: Reducing active logical volume to 400.00 MB

  THIS MAY DESTROY YOUR DATA (filesystem etc.)

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

  Reducing logical volume lv1 to 400.00 MB

  Logical volume lv1 successfully resized

 

查看缩减后的逻辑卷

# lvdisplay  /dev/vol1/lv1

  --- Logical volume ---

  LV Name                /dev/vol1/lv1

  VG Name                vol1

  LV UUID                u0apc1-UDbE-4mOB-RnlM-5xC2-hGLX-9ciDTQ

  LV Write Access        read/write

  LV Status              available

  # open                 0

  LV Size                400.00 MB

  Current LE             100

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:2

  

 

重新挂载

 #mount /dev/vol1/lv1  /lv1

 

第三部分

制作逻辑卷的快照

# lvcreate -L 50M  -s -p r -n lv1snap /dev/vol1/lv1

  Rounding up size to full physical extent 52.00 MB

  Logical volume "lv1snap" created

 

2创建目录

#mkdir  /lv1snap

3挂载快照

# mount /dev/vol1/lv1snap  /lv1snap

mount: block device /dev/vol1/lv1snap is write-protected, mounting read-only









本文转自 freehat08 51CTO博客,原文链接:http://blog.51cto.com/freehat/278892,如需转载请自行联系原作者
上一篇:【iOS 开发】Objective-C 运算符(二)


下一篇:django RESTful研究一第一个测试例子(用序列化器编写原生的Django视图函数)