The use of LVM in Linux

2011-01-02  来源:本站原创  分类:OS  人气:95 

LVM is a "logical volume management (Logical Volume Manager)" for short. Simply put, that is more "physical volume (Physical Volume, PV, usually physical hard disk partition)" merged into a larger "logical volume group (Volume Group, VG)", and then split on its traditional partition uses the same "logical volume (Logical Volume, LV)". Logical volumes without disrupting the system allows us to run any time to adjust the size of the file system capacity, in theory, have "unlimited" capacity of the thermal expansion.

Steps:

(1) physical hard disk partitions (fdisk)
(2) Create physical volumes (pvcreate)
(3) create a volume group (vgcreate)
(4) Activate the volume group (vgchange)
(5) to create logical volumes (lvcreate)
(6) volume set of expansion (vgextend) or logical volume expansion (lvextent)

Here is a virtual machine on the operation and demonstration.

1 new hard drive partition

The new hard drive / dev / sdb into a separate primary partition.

$ sudo fdisk /dev/sdb

Command (m for help): n

Command action
   e   extended
   p   primary partition (1-4)
p

Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

$ sudo fdisk -l

Disk /dev/sdb: 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: 0xe7b472ca

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux

(2) create a volume group

Practice, we can omit the use of "sudo pvcreate / dev/sdb1" to create the physical volume of the process.
Create a volume group called myvg and physical volume / dev/sdb1 added to the group. Before use to activate the volume group.

$ sudo vgcreate myvg /dev/sdb1
  No physical volume label read from /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
  Volume group "myvg" successfully created

$ sudo vgchange -a y myvg
  0 logical volume(s) in volume group "myvg" now active

$ sudo vgdisplay
  --- Volume group ---
  VG Name               myvg
  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               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       0 / 0
  Free  PE / Size       5118 / 19.99 GiB
  VG UUID               O7APOI-T0b1-T1my-PkKg-zbu3-ZBHn-KX7hCm

3 Create the logical volume

Create a logical volume called mywww size 10G for / var / www data storage. Do not forget to create the file system, it can not be used. Recommends using ext4 or reiserfs, or thermal expansion may fail.

$ sudo lvcreate -L 10G -n mywww myvg
  Logical volume "mywww" created

$ sudo lvdisplay
  --- Logical volume ---
  LV Name                /dev/myvg/mywww
  VG Name                myvg
  LV UUID                dK9aNo-0GDu-2sxP-i1kM-Nni6-u58k-IMWAtT
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           251:2

$ sudo mkfs -t ext4 -j /dev/myvg/mywww

mke2fs 1.41.11 (14-Mar-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

4 Mount the logical volume

The / dev / myvg / mywww mounted to / var / www.

$ sudo mkdir -p /var/www

$ sudo mount /dev/myvg/mywww /var/www

$ df -h /var/www
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/myvg-mywww
                      9.9G   23M  9.4G   1% /var/www

$ mount
/dev/mapper/myvg-mywww on /var/www type ext4 (rw)

Of course, we can add it to / etc / fstab so that boot automatically mount.

$ sudo cat /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/myvg/mywww /var/www        auto    defaults        0       0

5 new physical volume

The new physical partition / dev/sdc1 to the volume group for expansion.

$ sudo vgdisplay
  --- Volume group ---
  VG Name               myvg
  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               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       2560 / 10.00 GiB
  Free  PE / Size       2558 / 9.99 GiB
  VG UUID               qWjob5-j7VY-uOnp-BMoH-7TV0-nwJA-mghxk8

$ sudo vgextend myvg /dev/sdc1
  No physical volume label read from /dev/sdc1
  Physical volume "/dev/sdc1" successfully created
  Volume group "myvg" successfully extended

$ sudo vgdisplay
  --- Volume group ---
  VG Name               myvg
  System ID
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               39.98 GiB
  PE Size               4.00 MiB
  Total PE              10236
  Alloc PE / Size       2560 / 10.00 GiB
  Free  PE / Size       7676 / 29.98 GiB
  VG UUID               qWjob5-j7VY-uOnp-BMoH-7TV0-nwJA-mghxk8

By looking at the "VG Size" and "Free PE / Size" can confirm the success of expansion.

6 of the logical volume expansion

As / dev / myvg / www additional 5GB of space.

$ sudo lvextend -L +5G /dev/myvg/mywww
  Extending logical volume mywww to 15.00 GiB
  Logical volume mywww successfully resized

$ sudo resize2fs -f /dev/myvg/mywww
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/myvg/mywww is mounted on /var/www; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/myvg/mywww to 3932160 (4k) blocks.
The filesystem on /dev/myvg/mywww is now 3932160 blocks long.

$ df -h /var/www
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/myvg-mywww
                       15G  153M   14G   2% /var/www

Expansion success!

7 Delete logical volume

Unmount, delete / dev / myvg / mywww logical volume.

$ sudo umount /var/www

$ sudo lvremove /dev/myvg/mywww
Do you really want to remove active logical volume mywww? [y/n]: y
  Logical volume "mywww" successfully removed

$ sudo vgdisplay
  --- Volume group ---
  VG Name               myvg
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  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               39.98 GiB
  PE Size               4.00 MiB
  Total PE              10236
  Alloc PE / Size       0 / 0
  Free  PE / Size       10236 / 39.98 GiB
  VG UUID               qWjob5-j7VY-uOnp-BMoH-7TV0-nwJA-mghxk8

--------- ---------------- Separator

Recommended to install the Linux Server, in addition to the basic system (/, / boot, swap) to draw a total capacity of not more than 5GB of several partitions, all other remaining space into the LVM (/ home, / var), so future expansion is very convenient.

Reference documents:

"Common threads: Learning Linux LVM, Part 1"
"Common threads: Learning Linux LVM, Part 2"
"Logical Volume Manager (LVM)"
"Creating and Managing LVM"

相关文章
  • The use of LVM in Linux 2011-01-02

    LVM is a "logical volume management (Logical Volume Manager)" for short. Simply put, that is more "physical volume (Physical Volume, PV, usually physical hard disk partition)" merged into a larger "logical volume group (Volume Gro

  • LVM <3> Linux operating system introduced under the Lvm Management 2010-06-28

    1, the system is installed using lvm First, draw a disk / boot partition, and then the remaining space is divided into lvm, lvm management use. 2, in the system management using lvm # Fdisk-l # Pvcreate / dev / diskname # Vgcreate-s pp_size vgname di

  • LVM <3> Linux operating systems introduced under the Lvm Management 2010-06-28

    1, the system is installed using lvm First, draw a disk / boot partition, and then the remaining space is divided into lvm, lvm management use. 2, in the system management using lvm # Fdisk-l # Pvcreate / dev / diskname # Vgcreate-s pp_size vgname di

  • linux LVM的创建和管理 2011-11-18

    LVM是Logical Volume Manager(逻辑卷管理器)的简写,它为主机提供了更高层次的磁盘存储管理能力.LVM可以帮助系统管理员为应用与用户方便地分配存储空间.在LVM管理下的逻辑卷可以按需改变大小或添加移除.另外,LVM可以为所管理的逻辑卷提供定制的命名标识.因此,使用LVM主要是方便了对存储系统的管理,增加了系统的扩展性. 目前LVM在Linux下有两个版本,分别是LVM 1和LVM 2,LVM2不仅仅是Linux逻辑卷管理在版本与功能上的升级,而且是架构在一个新的内核存储子系

  • linux file system management (hard) [switch] 2011-05-13

    RH133-Unit4 file system management First, the system how to recognize the hard disk initialization 1, the system initially based on the information to identify the hard disk MBR, including some of the implementation of file to load the system, the ex

  • Linux文件系统在线扩容(操作示范) 2015-01-23

    介绍 Linux文件系统能在线扩容吗?- Yes! Linux文件系统扩容必须重新挂载?- NO! 本文章通过LVM工具,给大家展示一种Linux文件系统在线扩容办法,无需重启服务器,无需重新挂在文件系统,应用也无需做任何更改. 更多信息 实验环境 操作系统:Red Hat Enterprise Linux Server release 6.0 (Santiago) - 64bit 文件系统:ext4 工具:e2fsprogs-1.41.12-3.el6.x86_64 逻辑卷管理(LVM)概念

  • linux内核编译选项 2012-08-22

    第一部分 01.Code maturity level options ---> 代码成熟等级选项 01.01. [ ] Prompt for development and/or incomplete code/drivers 默认情况下是选择的,这将会在设置界面中显示还在开发或者还没有完成的代码与驱动.你应该选择它,因为有许多设备可能必需选择这个选项才能进行配置,实际 上它是安全的. 01.02.[ ] Select only drivers expected to compile clea

  • Linux, mount the lvm and lvm resolve conflicts and the shortcomings of the same name 2010-06-18

    Linux lvm mount under the same name and address conflicts Use the new hard drive in the Linux installation system, installed after the re-mount the original hard disk, partition format for the system-wide default partition, the system is used by defa

  • Linux, mount the lvm lvm and resolve conflicts and the shortcomings of the same name 2010-06-18

    Linux lvm mount under the same name and address conflicts Use the new hard drive in the Linux installation system, installed after the re-mount the original hard disk, partition format for the system-wide default partition, the system is used by defa

  • LVM <2> System Maintenance: linux LVM partition management under 2010-06-28

    http://blog.chinaitlab.com/html/82/1984182-281856.html Suppose now that a piece of 339.14GB attached to the server disk and want to use LVM partition on the disk management of this paper, we create two partitions, each name is called data and data1 S

  • LVM <2> System Maintenance: linux partition under LVM management 2010-06-28

    http://blog.chinaitlab.com/html/82/1984182-281856.html Now assume that a piece of 339.14GB attached to the server disk and want to use LVM partition on the disk management of this paper, we create two partitions, each name is called data and data1 Si

  • Linux, the basic configuration steps lvm 2010-07-11

    1. Additional hardware to increase the ide hard drive prefix hd, scsi hard disk prefix sd; the first hard disk as hda or sda, second hard drive as hdb or sdb, and so on. 2. With the fdisk tool to partition the hard disk operation to a second scsi exa

  • Linux in the LVM (logical volume management) 2010-08-21

    These days to redo their systems and then, made their own computer hard disk partition the LVM (logical volume management) type of the. Oh, always occurs before a partition of a sudden shortage of disk space, and then have to put another plate. And o

  • lvm linux of learning (Reprinted) 2010-09-15

    The hard drive partition linux lvm learn how to set the size, how to plan, even the best plans go wrong when there are, the unexpected. In order for us from the tragic partition and the partition that modify the tool, please contact me to know what L

  • Linux + Disk disk lvm / disk partition / disk mount / disk man 2010-12-29

    RedHat Linux LVM LVM - very very strong http://www.javaeye.com/topic/283065 LVM (Logic Volume Management, logical volume management), is the traditional commercial Unix to a senior with a disk management tool, unusually strong. LVM was ported to the

  • The use of Linux in the LVM 2011-01-02

    LVM is a "logical volume management (Logical Volume Manager)" for short. Simply put, that is, multiple "physical volume (Physical Volume, PV, usually a physical hard disk partition)" merged into a larger "logical volume group (Vol

  • linux disk partition management - Logical Volume Manager (LVM) and Managing Disk Storage 2010-12-05

    Starting from Red Hat Linux 8.0, Logical Volume Manager (LVM) can be allocated on the hard drive to use. LVM is a hard disk drive space allocation into a logical way, so you do not have to use hard drive partition and was easy to redraw the size. Wit

  • Detailed Linux LVM logical volume management 2011-06-24

    Summary: Linux users to install the Linux operating system encountered one of the most common problem is difficult to determine how to correctly assess the size of the partition to assign the appropriate hard disk space. Encounter the appearance of a

  • create lvm linux install oracle raw device 2011-03-30

    Quote http://bluewind.oracle.com.cn/viewthread.php?tid=156445&extra=page%3D3 The following is added to a new virtual machine hard disk, and create lvm Raw device to use the process to the oracle , And we will study together, there is no hope to guide

  • Debian Linux LVM 配置手册 2013-11-11

    摘要: 使用 Debian Linux 下的 lvm2 配置 LVM 磁盘系统 作者: By REISTLIN [雷斯林] MSN: [email protected] QQ: 3A984 版权: 原创文章.转载请保留作者信息和原文完整.谢绝任何方式的摘要. 本文出自:http://www.reistlin.com/blog/493 LVM 介绍: LVM - Logical Volume Manager 是Linux系统下最强大的磁盘管理技术之一.它将您从不得不思考物理容量中解脱出来,代之以逻