Translated:20140813 Setup Flexible Disk Storage with Logical Volume Management (LVM) in Linux--PART 1.md

This commit is contained in:
GOLinux 2014-08-17 13:16:05 +08:00
parent f002305990
commit 0a6c9da1a9
2 changed files with 353 additions and 355 deletions

View File

@ -1,355 +0,0 @@
Translating by GOLinux ...
Setup Flexible Disk Storage with Logical Volume Management (LVM) in Linux PART 1
================================================================================
**Logical Volume Management (LVM)** makes it easier to manage disk space. If a file system needs more space, it can be added to its logical volumes from the free spaces in its volume group and the file system can be re-sized as we wish. If a disk starts to fail, replacement disk can be registered as a physical volume with the volume group and the logical volumes extents can be migrated to the new disk without data loss.
![Create LVM Storage in Linux](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage.jpg)
Create LVM Storage in Linux
In a modern world every Server needs more space day by day for that we need to expand depending on our needs. Logical volumes can be use in RAID, SAN. A Physical Disk will be grouped to create a volume Group. Inside volume group we need to slice the space to create Logical volumes. While using logical volumes we can extend across multiple disks, logical volumes or reduce logical volumes in size with some commands without reformatting and re-partitioning the current disk. Volumes can stripes data across multiple disks this can increase the I/O stats.
### LVM Features ###
- It is flexible to expand the space at any time.
- Any file systems can be installed and handle.
- Migration can be used to recover faulty disk.
- Restore the file system using Snapshot features to earlier stage. etc…
#### My Server Setup Requirements ####
- Operating System CentOS 6.5 with LVM Installation
- Server IP 192.168.0.200
### Creating LVM Disk Storage in Linux ###
**1. **Weve used CentOS 6.5 Operating system using LVM in a Virtual Disk (VDA). Here we can see the Physical Volume (PV), Volume Group (VG), Logical Volume (LV) by using following command.
# pvs
# vgs
# lvs
![Check Physical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-03.jpg)
Check Physical Volumes
Here, is the description of each parameters shown in above screenshot.
- Physical Disk Size (PV Size)
- Disk which used was Virtual Disk vda.
- Volume Group Size (VG Size)
- Volume Group name (vg_tecmint)
- Logical Volume name (LogVol00, LogVol01)
- LogVol00 Assigned for sawp with 1GB Size
- LogVol01 Assigned for / with 16.5GB
So, from here we come to know that there is not enough free space in VDA disk.
**2. **For Creating a **New Volume Group**, we need to add Additional **3 hard disks** in this server. It is not Compulsory to use 3 Drives just 1 is Enough to create a new **VG** and **LV** inside that vg, I am adding more here for demonstration purpose and for more feature command explanations.
Following are the disks I have added additionally.
sda, sdb, sdc
----------
# fdisk -l
![Verify Added Disks](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-04.jpg)
Verify Added Disks
- Default Disk using for Operating system (Centos6.5).
- Partitions defined in default Disk (vda1 = swap), (vda2 = /).
- Additionally added Disks are mentioned as Disk1, Disk2, Disk3.
Each and every Disks are 20 GB in Size. Default PE Size of a Volume Group is 4 MB, Volume group what we are using in this server is configured using default PE.
![Volume Group Display](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-05.jpg)
Volume Group Display
- **VG Name** A Volume Group name.
- **Format** LVM Architecture Used LVM2.
- **VG Access** Volume Group is in Read and Write and ready to use.
- **VG Status** Volume Group can be re-sized, We can Expand more if we need to add more space.
- **Cur LV** Currently there was 2 Logical volumes in this Volume Group.
- **CurPV and Act PV** Currently Using Physical Disk was 1 (vda), And its active, so what we can use this volume group.
- **PE Size** Physical Extends, Size for a disk can be defined using PE or GB size, 4MB is the Default PE size of LVM. For example, if we need to create 5 GB size of logical volume we can use sum of 1280 PE, Dont you understand what Im saying ?.
Here the Explanation > 1024MB = 1GB, if so 1024MB x 5 = 5120PE = 5GB, Now Divide the 5120/4 = 1280, 4 is the Default PE Size.
- Total PE This Volume Group have.
- Alloc PE Total PE Used, full PE already Used, 4482 x 4PE = 17928.
- Free PE Here its already used so there was no free PE.
**3. **Only vda used, Currently Centos Installed **/boot, /, swap,** in vda physical disk using lvm there were no space remaining in this disk.
# df -TH
![Check the Disk Space](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-06.jpg)
Check the Disk Space
Above image shows the mount Point we are using **18GB** fully used for root, so there is no free space available.
**4. **So lets, create new physical volume (**pv**), Volume Group (**vg**) in the name of **tecmint_add_vg** and create Logical Volumes (**lv**) in it, Here we can create 4 Logical Volumes in the name of **tecmint_documents**, **tecmint_manager** and **tecmint_public**.
We can extend the Volume Group of currently using VG to get more space. But here, what we are going to do is to Create new Volume Group and play around it, later we can see how to extend the file systems Volume group which is currently in use.
Before using a new Disk we need to partition the disk using fdisk.
# fdisk -cu /dev/sda
- **c** Switch off DOS-compatible mode it is Recommend to include this Option.
- **u** While listing the partition tables it will give us in sector instead of cylinder.
![Create New Physical Partitions](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-07.jpg)
Create New Physical Partitions
Next, follow the below steps to create new partition.
- Choose **n** to create new.
- Choose **p** to create a primary partition.
- Choose which number of partition we need to create.
- Press **Enter** twice to use the full space of the Disk.
- We need to change the type of newly created partition type **t**.
- Which number of partition need to change, choose the number which we created its **1**.
- Here we need to change the type, we need to create LVM so we going to use the type code of LVM as 8e, if we do not know the type code Press **L** to list all type codes.
- Print the Partition what we created to just confirm.
- Here we can see the ID as 8e LINUX LVM.
- Write the changes and exit fdisk.
Do the above steps for other 2 disks sdb and sdc to create new partitions. Then Restart the machine to verify the partition table using fdisk command.
# fdisk -l
![Verify Partition Table](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-08.jpg)
Verify Partition Table
### Creating Physical Volumes ###
**5. **Now, its time to create Physical Volumes using all 3 disks. Here, I have listed the physical disk using pvs command, only one default **pvs** is now listed.
# pvs
Then create the new physical disks using command.
# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1
Once again list the disk to see the newly created Physical disks.
# pvs
![Create Physical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-09.jpg)
Create Physical Volumes
### Creating Volume Groups ###
**6. **Create Volume Group in the name of **tecmint_add_vg** using available free PV Create using PE size 32. To Display the current volume groups, we can see there is one volume group with 1 PV using.
# vgs
This will create the volume group using 32MB PE size in the name of **tecmint_add_vg** using 3 Physical volumes we created in last steps.
# vgcreate -s 32M tecmint_add_vg /dev/sda1 /dev/sdb1 /dev/sdc1
Next, verify the volume group by running vgs command again.
# vgs
![Create Volume Groups](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-10.jpg)
Create Volume Groups
![Verify Volume Groups](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-11.jpg)
Verify Volume Groups
Understanding vgs command output:
- Volume Group name.
- Physical Volumes used in this Volume Group.
- Shows free space available in this volume group.
- Total Size of the Volume Group.
- Logical Volumes inside this volume group, Here we have not yet created so there is 0.
- SN = Number of Snapshots the volume group contains. (Later we can create a snapshot).
- Status of the Volume group as Writeable, readable, resizeable, exported, partial and clustered, Here it is wznthat means w = Writable, z = resizeable..
- Number of Physical Volume (PV) used in this Volume Group.
**7. **To Display more information about volume group use command.
# vgs -v
![Check Volume Group Information](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-12.jpg)
Check Volume Group Information
**8. **To get more information about newly created volume groups, run the following command.
# vgdisplay tecmint_add_vg
![List New Volume Groups](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-13.jpg)
List New Volume Groups
- Volume group name
- LVM Architecture used.
- It can be read and write state, ready to use.
- This volume group can be resizeable.
- No of Physical disk used and they are active.
- Volume Group total size.
- A Single PE size was 32 here.
- Total number of PE available in this volume group.
- Currently we have not created any LV inside this VG so its totally free.
- UUID of this volume group.
### Creating Logical Volumes ###
**9. **Now, ceate 3 Logical Volumes in the name of **tecmint_documents**, **tecmint_manager** and **tecmint_public**. Here, we can see how to Create Logical Volumes Using PE size and Using GB Size. First, list the Current Logical Volumes using following command.
# lvs
![List Current Volume Groups](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-14.jpg)
List Current Volume Groups
**10. **These Logical Volumes are in **vg_tecmint** Volume Group. List and see how much free spaces are there to create logical volumes using **pvs** command.
# pvs
![Check Free Space](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-15.jpg)
Check Free Space
**11. **Volume group size is **54GB** and its unused, So we can Create LV in it. Let us divide volume group to equal size to create 3 Logical Volumes. That means **54GB**/3 = **18GB**, A single Logical Volume will be 18GB in Size after Creation.
#### Method 1: Creating Logical Volumes using PE Sizes ####
First let us create Logical Volumes Using Physical Extends (PE) size. We need to know Default PE size assigned for this Volume Group and Total PE available to create new Logical Volumes, Run the command to get the info using.
# vgdisplay tecmint_add_vg
![Create New Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-16.jpg)
Create New Logical Volume
- Default PE Assigned for this VG is 32MB, Here Single PE size will be 32MB.
- Total Available PE is 1725.
Just do and see a little Calculation using bc command.
# bc
----------
1725PE/3 = 575 PE.
575 PE x 32MB = 18400 --> 18GB
![Calculate Disk Space](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-17.jpg)
Calculate Disk Space
Press **CRTL+D** to Exit from **bc**. Let us now Create 3 Logical Volumes using 575 PEs.
# lvcreate -l (Extend size) -n (name_of_logical_volume) (volume_group)
# lvcreate -l 575 -n tecmint_documents tecmint_add_vg
# lvcreate -l 575 -n tecmint_manager tecmint_add_vg
# lvcreate -l 575 -n tecmint_public tecmint_add_vg
- -**l** Creating using Extent Size
- -**n** Give a Logical Volume name.
List the Created Logical Volumes using lvs command.
# lvs
![List Created Logical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-18.jpg)
List Created Logical Volumes
#### Method 2: Creating Logical Volumes using GB Sizes ####
While Creating Logical Volume using GB size we cannot get the exact size. So, the better way is to create using extend.
# lvcreate -L 18G -n tecmint_documents tecmint_add_vg
# lvcreate -L 18G -n tecmint_manager tecmint_add_vg
# lvcreate -L 18G -n tecmint_public tecmint_add_vg
# lvcreate -L 17.8G -n tecmint_public tecmint_add_vg
List the Created logical Volumes using lvs command.
# lvs
![Verify Created Logical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-19.jpg)
Verify Created Logical Volumes
Here, we can see while creating 3rd LV we cant Round-up to 18GB, It is because of small changes in size, But this issue will be ignored while creating LV using Extend size.
### Creating File System ###
**12. **For using the logical volumes we need to format. Here I am using ext4 file-system to create the volumes and going to mount under **/mnt/**.
# mkfs.ext4 /dev/tecmint_add_vg/tecmint_documents
# mkfs.ext4 /dev/tecmint_add_vg/tecmint_public
# mkfs.ext4 /dev/tecmint_add_vg/tecmint_manager
![Create Ext4 File System](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-20.jpg)
Create Ext4 File System
**13. **Let us Create Directories in **/mnt** and Mount the Logical volumes what we have created file-system.
# mount /dev/tecmint_add_vg/tecmint_documents /mnt/tecmint_documents/
# mount /dev/tecmint_add_vg/tecmint_public /mnt/tecmint_public/
# mount /dev/tecmint_add_vg/tecmint_manager /mnt/tecmint_manager/
List and confirm the Mount point using.
# df -h
![Mount Logical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-22.jpg)
Mount Logical Volumes
#### Permanent Mounting ####
Its now temporarily mounted, for permanent mount we need to add the entry in fstab, for that let us get the mount entry from mtab using
# cat /etc/mtab
We need to make slight changes in fstab entry while entering the mount entry contents copies from mtab, we need to change the rw to defaults
# vim /etc/fstab
Our fstab Entry want to be similar to below sample. Save and exit from fstab using wq!.
/dev/mapper/tecmint_add_vg-tecmint_documents /mnt/tecmint_documents ext4 defaults 0 0
/dev/mapper/tecmint_add_vg-tecmint_public /mnt/tecmint_public ext4 defaults 0 0
/dev/mapper/tecmint_add_vg-tecmint_manager /mnt/tecmint_manager ext4 defaults 0 0
![Get mtab Mount Entry](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-23.jpg)
Get mtab Mount Entry
![Open fstab File](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-24.jpg)
Open fstab File
![Add Auto Mount Entry](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-25.jpg)
Add Auto Mount Entry
Execute the command mount -a to check for the fstab entry before restart.
# mount -av
![Verify fstab Entry](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-26.jpg)
Verify fstab Entry
Here we have seen how to setup flexible storage with logical volumes by using physical disk to physical volume, physical volume to volume group, volume group to logical volumes.
In my upcoming future articles, I will see how to extend the volume group, logical volumes, reducing logical volume, taking snapshot and restore from snapshot. Till then stay updated to TecMint for more such awesome articles.
--------------------------------------------------------------------------------
via: http://www.tecmint.com/create-lvm-storage-in-linux/
作者:[Babin Lonston][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/babinlonston/

View File

@ -0,0 +1,353 @@
在Linux中使用逻辑卷管理器构建灵活的磁盘存储——第一部分
================================================================================
**逻辑卷管理器LVM**让磁盘空间管理更为便捷。如果一个文件系统需要更多的空间,它可以在它的卷组中将空闲空间添加到它的逻辑卷中,而文件系统可以根据你的意愿调整大小。如果某个磁盘启动失败,替换磁盘可以使用卷组注册成一个物理卷,而逻辑卷扩展可以将数据迁移到新磁盘而不会丢失数据。
![Create LVM Storage in Linux](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage.jpg)
在Linux中创建LVM存储
在现代世界中每台服务器空间都会因为我们的需求增长而不断扩展。逻辑卷可以用于RAIDSAN。单个物理卷将会被加入组以创建卷组在卷组中我们需要切割空间以创建逻辑卷。在使用逻辑卷时我们可以使用某些命令来跨磁盘、跨逻辑卷扩展或者减少逻辑卷大小而不用重新格式化和重新对当前磁盘分区。卷可以跨磁盘抽取数据这会增加I/O数据量。
### LVM特性 ###
- 可以在任何时候灵活地扩展空间。
- 可以安装和处理任何文件系统。
- 可以通过迁移来恢复错误磁盘。
- 可以使用快照功能恢复文件系统到先前的阶段。等等……
####我的服务器设置 - 需求 ####
- 操作系统 —— 安装有LVM的CentOS 6.5
- 服务器IP地址 —— 192.168.0.200
### 在Linux中创建LVM磁盘存储 ###
**1.** 我们已经在虚拟磁盘VDA中使用了带LVM的CentOS 6.5操作系统。在此我们可以使用下列命令查看到物理卷PV卷组VG逻辑卷LV
# pvs
# vgs
# lvs
![Check Physical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-03.jpg)
检查物理卷
下面是上面截图中各个参数的说明。
- 物理磁盘大小PV Size
- 用作虚拟磁盘vda的磁盘
- 卷组大小VG Size
- 卷组名称vg_tecmint
- 逻辑卷名称LogVol00LogVol01
- LogVol00分配给swap大小1GB
- LogVol01分配给/大小16.5GB
从上面看我们可以知道VDA磁盘中没有足够的空闲空间。
**2.** 为了创建一个**新卷组**,我们需要在这台服务器上添加额外的**3个硬盘**。3个驱动器不是强制使用的只要一个就足够用来创建新的**VG**,并在其中创建**LV**了。我在这里添加了更多的磁盘,目的只是用于演示和更多命令功能的说明。
下面是我已经额外添加的磁盘。
sda, sdb, sdc
----------
# fdisk -l
![Verify Added Disks](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-04.jpg)
验证添加的磁盘
- 用于操作系统CentOS 6.5)的默认磁盘。
- 默认磁盘上定义的分区vda1 = swapvda2 = /)。
- 额外添加的磁盘Disk1Disk2Disk3。
各个磁盘大小都是20GB默认的卷组的PE大小为4MB我们在该服务器上配置的卷组使用默认PE。
![Volume Group Display](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-05.jpg)
卷组显示
- **VG Name** 卷组名称。
- **Format** LVM架构使用LVM2。
- **VG Access** 卷组为读写模式,备好待用。
- **VG Status** 卷组可调整大小,如果我们需要添加更多空间,我们可以扩展更多。
- **Cur LV** 当前卷组中有2个逻辑卷。
- **CurPV and Act PV** 当前使用的物理磁盘是1vda已被激活因此我们可以使用该卷组。
- **PE Size** 磁盘的物理扩展大小可以定义使用PE或者GBLVM的默认PE大小是4MB。例如如果我们需要创建5GB大小的逻辑卷我们可以使用总计1280 PE你们懂我的意思么
这里解释一下 -> 1024MB = 1GB这样的话1024MB x 5 = 5120PE = 5GB然后5120/4 = 12804是默认的PE大小。
- Total PE 该卷组具有的PE数量。
- Alloc PE 总的PE使用量已经使用的全部PE4482 x 4PE = 17928。
- Free PE 这里因为已经使用所以没有空闲PE了。
**3.** 只使用了vda当前CentOS在使用lvm的vda物理磁盘中安装了**/boot/swap,**,该磁盘中没有空间剩余。
# df -TH
![Check the Disk Space](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-06.jpg)
检查磁盘空间
上面的图片中显示了用于根的挂载点已使用了**18GB**,因此没有空闲空间可用了。
**4.** 那么,让我们创建新的物理卷(**pv**),以及名为**tecmint_add_vg**的卷组(**vg**),并在其中创建逻辑卷(**lv**。这里我们可以创建4个逻辑卷分别名为 **tecmint_documents****tecmint_manager**以及**tecmint_add_vg**。
我们可以扩展当前使用的卷组以获得更多空间。但在这里,我们将要做的是,创建新的卷组,然后在里面肆意妄为吧。过会儿,我们可以看到怎样来扩展使用中的卷组的文件系统。
在使用新磁盘钱我们需要使用fdisk来对磁盘分区。
# fdisk -cu /dev/sda
- **c** 关闭DOS兼容模式推荐使用该选项。
- **u** 当列出分区表时,会以扇区而不是柱面显示。
![Create New Physical Partitions](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-07.jpg)
创建新的物理分区
接下来,请遵循以下步骤来创建新分区。
- 选择**n**来创建新分区。
- 选择**p**来创建主分区。
- 选择我们需要创建的分区号。
- 按**Enter**两次来使用整个磁盘空间。
- 我们需要修改新创建的分区类型,输入**t**。
- 选择需要修改的分区号,选择我们创建的分区号**1**。
- 这里我们需要修改类型。我们需要创建LVM因此我们使用LVM的类型代码8e。如果不知道类型代码按**L**来列出所有类型代码。
- 打印我们创建的分区以确认。
- 这里我们可以看到Linux LVM的ID 8e。
- 写入修改并退出fdisk。
重复以上步骤为另外2个磁盘sdb和sdc创建新分区。然后重启机器使用fdisk命令来验证分区表。
# fdisk -l
![Verify Partition Table](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-08.jpg)
验证分区表
### 创建物理卷 ###
**5.** 现在该使用3个磁盘来创建物理卷了。这里我已经使用pvs命令将物理磁盘列了出来现在只有一个默认的**pvs**被列出来了。
# pvs
然后,使用命令创建新的物理磁盘。
# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1
再次列出磁盘来查看新创建物理磁盘。
# pvs
![Create Physical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-09.jpg)
创建物理卷
### 创建卷组 ###
**6.** 使用可用的空闲PV来创建名为**tecmint_add_vg**的卷组PE大小为32。显示当前卷组我们可以看到只有带有1个PV的一个卷组在使用。
# vgs
这将使用上面创建的3个物理卷创建名为**tecmint_add_vg**的卷组PE大小为32MB。
# vgcreate -s 32M tecmint_add_vg /dev/sda1 /dev/sdb1 /dev/sdc1
接下来再次运行vgs命令来验证卷组。
# vgs
![Create Volume Groups](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-10.jpg)
创建卷组
![Verify Volume Groups](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-11.jpg)
验证卷组
理解vgs命令输出
- 卷组名。
- 本卷组中使用的物理卷。
- 显示本卷组中的可用空闲空间。
- 卷组总大小。
- 本卷组中的逻辑卷这里我们还没创建所以是0。
- SN = 卷组包含的快照数量。(后面,我们会创建一个快照。)
- 卷组状态如可写可读可调整大小已导出部分的和集群的。这里是wz——意为w = 可写z = 可调整大小。
- 卷组中使用的物理卷PV数量。
**7.** 使用命令来显示更多卷组信息。
# vgs -v
![Check Volume Group Information](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-12.jpg)
检查卷组信息
**8.** 要获取更多关于新创建的卷组信息,运行以下命令。
# vgdisplay tecmint_add_vg
![List New Volume Groups](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-13.jpg)
列出新卷组
- 卷组名称
- 使用的LVM架构。
- 可读写,备好待用。
- 该卷组可以调整大小。
- 使用和激活的物理磁盘数量。
- 卷组总大小。
- 这里单个PE大小为32。
- 该卷组中可用的PE总数。
- 当前还没有在卷组中创建任何LV因此它是空闲的。
- 该卷组的UUID。
### 创建逻辑卷 ###
**9.** 现在创建3个名为**tecmint_documents**,**tecmint_manager**和**tecmint_public**的逻辑卷。这里我们可以看到如何分别以PE为单位和GB为单位来创建逻辑卷。首先使用以下命令来列出当前逻辑卷。
# lvs
![List Current Volume Groups](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-14.jpg)
列出当前卷组
**10.** 这些逻辑卷处于**vg_tecmint**卷组中使用**pvs**命令来列出并查看有多少空闲空间可以创建逻辑卷。
# pvs
![Check Free Space](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-15.jpg)
检查空闲空间
**11.** 卷组大小为**54GB**而且未被使用所以我们可以在该组内创建LV。让我们将卷组平均划分大小来创建3个逻辑卷就是说**54GB**/3 = **18GB**创建出来的单个逻辑卷应该会是18GB。
#### 方法1 使用PE创建逻辑卷 ####
首先让我们使用物理扩展PE为单位来创建逻辑卷。我们需要知道分配到该卷组的默认PE大小以及总的可用PE大小来创建新的逻辑卷运行下面的命令来获取使用中的卷组信息。
# vgdisplay tecmint_add_vg
![Create New Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-16.jpg)
创建新逻辑卷
- 默认分配给该卷组的PE为32MB这里单个的PE大小为32MB。
- 总可用PE是1725。
只要用bc命令做一点小小的计算来看看就知道了。
# bc
----------
1725PE/3 = 575 PE.
575 PE x 32MB = 18400 --> 18GB
![Calculate Disk Space](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-17.jpg)
计算磁盘空间
按**CRTL+D**退出**bc**。现在让我们使用575个PE来创建3个逻辑卷。
# lvcreate -l (Extend size) -n (name_of_logical_volume) (volume_group)
# lvcreate -l 575 -n tecmint_documents tecmint_add_vg
# lvcreate -l 575 -n tecmint_manager tecmint_add_vg
# lvcreate -l 575 -n tecmint_public tecmint_add_vg
- -**l** 使用扩展大小创建
- -**n** 给逻辑卷命名
使用lvs命令来列出创建的逻辑卷。
# lvs
![List Created Logical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-18.jpg)
列出创建的逻辑卷
#### 方法2 使用GB大小创建逻辑卷 ####
在使用GB大小创建逻辑卷时我们不能获得精确的大小。因此最好的办法是用扩展。
# lvcreate -L 18G -n tecmint_documents tecmint_add_vg
# lvcreate -L 18G -n tecmint_manager tecmint_add_vg
# lvcreate -L 18G -n tecmint_public tecmint_add_vg
# lvcreate -L 17.8G -n tecmint_public tecmint_add_vg
使用lvs命令来列出创建的逻辑卷。
# lvs
![Verify Created Logical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-19.jpg)
验证创建的逻辑卷
这里我们可以看到当创建第三个LV的时候我们不能收集到18GB空间。这是因为尺寸有小小的改变但在使用或者尺寸来创建LV时这个问题会被忽略。
### 创建文件系统 ###
**12.** 要使用逻辑卷我们需要格式化。这里我使用ext4文件系统来创建卷并打算挂载到**/mnt**。
# mkfs.ext4 /dev/tecmint_add_vg/tecmint_documents
# mkfs.ext4 /dev/tecmint_add_vg/tecmint_public
# mkfs.ext4 /dev/tecmint_add_vg/tecmint_manager
![Create Ext4 File System](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-20.jpg)
创建Ext4文件系统
**13.** 让我们在**/mnt**下创建目录,并将已创建好文件系统的逻辑卷挂载上去。
# mount /dev/tecmint_add_vg/tecmint_documents /mnt/tecmint_documents/
# mount /dev/tecmint_add_vg/tecmint_public /mnt/tecmint_public/
# mount /dev/tecmint_add_vg/tecmint_manager /mnt/tecmint_manager/
使用下面的命令来列出并确认挂载点。
# df -h
![Mount Logical Volumes](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-22.jpg)
挂载逻辑卷
#### 永久挂载 ####
现在这些逻辑卷是临时挂载上去的要永久挂载我们需要添加条目到fstab中。要达到这个目的让我们使用下面的命令来获取挂载条目
# cat /etc/mtab
在输入来自mtab中的挂载条目内容时我们需要在fstab中做些小小的改变修改rw为默认。
# vim /etc/fstab
我们的fstab条目应该和下面的类似使用wq保存并退出fstab。
/dev/mapper/tecmint_add_vg-tecmint_documents /mnt/tecmint_documents ext4 defaults 0 0
/dev/mapper/tecmint_add_vg-tecmint_public /mnt/tecmint_public ext4 defaults 0 0
/dev/mapper/tecmint_add_vg-tecmint_manager /mnt/tecmint_manager ext4 defaults 0 0
![Get mtab Mount Entry](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-23.jpg)
获取mtab挂载条目
![Open fstab File](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-24.jpg)
打开fstab文件
![Add Auto Mount Entry](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-25.jpg)
添加自动挂载条目
重启前执行mount -a命令来检查fstab条目。
# mount -av
![Verify fstab Entry](http://www.tecmint.com/wp-content/uploads/2014/07/Create-Logical-Volume-Storage-26.jpg)
验证fstab条目
这里,我们已经了解了怎样来使用逻辑卷构建灵活的存储,从使用物理磁盘到物理卷,物理卷到卷组,卷组再到逻辑卷。
在我即将奉献的文章中我将介绍如何扩展卷组、逻辑卷减少逻辑卷拍快照以及从快照中恢复。到那时保持TecMint更新到这些精彩文章中的内容。
--------------------------------------------------------------------------------
via: http://www.tecmint.com/create-lvm-storage-in-linux/
作者:[Babin Lonston][a]
译者:[GOLinux](https://github.com/GOLinux)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/babinlonston/