码迷,mamicode.com
首页 > 系统相关 > 详细

Linux文件系统管理—LVM

时间:2015-09-04 12:41:51      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:lvm   文件系统   

1.LVM的基本简介

       LVM:logical Volume Manager,逻辑卷管理,其目的在于可以弹性调整文件系统容量。LVM建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵活性,它可以整合多个物理分区在一起,让这些分区看起来像一个磁盘,而且,还可以将其他物理分区添加LVM中或从这个LVM管理的磁盘中删除。

2.LVM基本术语

       PV:Physical Volume物理卷,就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。注意:需要将分区标识符改为8e(LVM的标识符),然后用pvcreate

命令创建pv。

       VG:Volume Group卷组类似于非LVM系统中的物理硬盘,其由物理卷组成。可以在卷组上创建一个或多个“LVM分区”(逻辑卷),LVM卷组由一个或多个物理卷组成。

       PE:每一个物理卷被划分为称为PE(Physical Extents)的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB。

       LV:从VG中划分的逻辑分区。

技术分享

3.LVM的创建与管理

创建分区:使用fdisk命令创建分区,调整分区标识符为8e。

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


WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to

         switch off the mode (command ‘c‘) and change display units to

         sectors (command ‘u‘).


Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First cylinder (7859-15665, default 7859): 

Using default value 7859

Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665): +5G


Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First cylinder (8513-15665, default 8513): 

Using default value 8513

Last cylinder, +cylinders or +size{K,M,G} (8513-15665, default 15665): +5G


Command (m for help): P


Disk /dev/sda: 128.8 GB, 128849018880 bytes

255 heads, 63 sectors/track, 15665 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: 0x00051a06


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        7859    62914560   8e  Linux LVM

/dev/sda3            7859       15665    62708728+   5  Extended

/dev/sda5            7859        8512     5252224+  83  Linux

/dev/sda6            8513        9166     5253223+  83  Linux


Command (m for help): t

Partition number (1-6): 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-6): 6

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

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


Command (m for help): p


Disk /dev/sda: 128.8 GB, 128849018880 bytes

255 heads, 63 sectors/track, 15665 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: 0x00051a06


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        7859    62914560   8e  Linux LVM

/dev/sda3            7859       15665    62708728+   5  Extended

/dev/sda5            7859        8512     5252224+  8e  Linux LVM

/dev/sda6            8513        9166     5253223+  8e  Linux LVM

创建PV:pvcreate  /dev/devices,使用pvdisplay查看pv详细信息。


[root@magedu ~]# pvcreate /dev/sda5 /dev/sda6

  Physical volume "/dev/sda5" successfully created

  Physical volume "/dev/sda6" successfully created

[root@magedu ~]# pvdisplay /dev/sda5 /dev/sda6

  "/dev/sda5" is a new physical volume of "5.01 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sda5

  VG Name               

  PV Size               5.01 GiB

  Allocatable           NO

  PE Size               0   

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               L8WHe3-EdsZ-aC6K-RJUW-8kkL-D8wj-RiwkUv

   

  "/dev/sda6" is a new physical volume of "5.01 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sda6

  VG Name               

  PV Size               5.01 GiB

  Allocatable           NO

  PE Size               0   

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               EcvE1Y-5wXl-t5Kc-M48F-Nrqw-R2hL-xi0hch

创建VG:vgcreate  VolumeGroupName  PhysicalDevicePath 

[root@magedu ~]# vgcreate myvg /dev/sda5 /dev/sda6

  Volume group "myvg" successfully created

[root@magedu ~]# vgdisplay myvg

  --- Volume group ---

  VG Name               myvg

  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               10.02 GiB

  PE Size               4.00 MiB

  Total PE              2564

  Alloc PE / Size       0 / 0   

  Free  PE / Size       2564 / 10.02 GiB

  VG UUID               mDpNg3-cUa0-AQ2F-doM2-9wmj-fc6t-Q2XqiH

创建LV:lvcreate  -L #[mMgGtT] -n NAME VolumeGroup

[root@magedu ~]# lvcreate -L 10 -n mylv myvg

  Rounding up size to full physical extent 12.00 MiB

  Logical volume "mylv" created

[root@magedu ~]# lvdisplay /dev/myvg/mylv 

  --- Logical volume ---

  LV Path                /dev/myvg/mylv

  LV Name                mylv

  VG Name                myvg

  LV UUID                yfJqxR-ao9l-uR9p-OcEb-Xdi4-pJ2d-7bYO5A

  LV Write Access        read/write

  LV Creation host, time magedu, 2015-08-18 13:21:49 +0800

  LV Status              available

  # open                 0

  LV Size                12.00 MiB

  Current LE             3

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:4

LV格式化及挂载:lv需要先格式化才能存储

[root@magedu ~]# mke2fs -t ext4 /dev/myvg/mylv 

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

3072 inodes, 12288 blocks

614 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=12582912

2 block groups

8192 blocks per group, 8192 fragments per group

1536 inodes per group

Superblock backups stored on blocks: 

8193


Writing inode tables: done                            

Creating journal (1024 blocks): done

Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 32 mounts or

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

[root@magedu ~]# mkdir /tmp/lvtest

[root@magedu ~]# mount /dev/myvg/mylv /tmp/lvtest/

[root@magedu ~]# mount

/dev/mapper/vg0-root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

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

tmpfs on /dev/shm type tmpfs (rw)

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

/dev/mapper/vg0-usr on /usr type ext4 (rw)

/dev/mapper/vg0-var on /var type ext4 (rw)

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

/dev/mapper/myvg-mylv on /tmp/lvtest type ext4 (rw)

扩展逻辑卷

       lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME

       resize2fs /dev/VG_NAME/LV_NAME

缩减逻辑卷

       umount /dev/VG_NAME/LV_NAME

       e2fsck -f /dev/VG_NAME/LV_NAME

       resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT]

       lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME

       mount

Linux文件系统管理—LVM

标签:lvm   文件系统   

原文地址:http://zhaibo.blog.51cto.com/8252246/1691269

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!