Linux LVM

in 系统环境
关注公众号【好便宜】( ID:haopianyi222 ),领红包啦~
搬瓦工,CN2 GIA 优质线路,搭梯子、海外建站推荐:

What’s LVM? Why using Linux Logical Volume Manager or LVM? Well, these questions are not the scope here. But in brief, the most attractive feature of Logical Volume Manager is to make disk management easier in Linux!

Basically, LVM allows users to dynamically extend or shrink Linux “partition” or file system in online mode! The LVM can resize volume groups (VG) online by adding new physical volumes (PV) or rejecting those existing PVs attached to VG.

A visualized concept diagram of the Linux Logical Volume Manager or LVM

LVM 术语介绍

  1. 物理存储介质(The physical media):这里指系统的存储设备:硬盘,如:/dev/hda1、/dev/sda等等,是存储系统最低层的存储单元.
  2. 物理卷(physical volume):物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
  3. 卷组(Volume Group):LVM卷组类似于非LVM系统中的物理硬盘,其由物理卷组成。可以在卷组上创建一个或多个“LVM分区”(逻辑卷),LVM卷组由一个或多个物理卷组成。
  4. 逻辑卷(logical volume):LVM的逻辑卷类似于非LVM系统中的硬盘分区,在逻辑卷之上可以建立文件系统(比如/home或者/usr等)
  5. PE(physical extent):每一个物理卷被划分为称为PE(Physical Extents)的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB

Setup Linux LVM

Using the whole secondary hard disk for LVM partition: fdisk /dev/sda
At the Linux fdisk command prompt

1. press n to create a new disk partition,
2. press p to create a primary disk partition,
3. press 1 to denote it as 1st disk partition,
4. press ENTER twice to accept the default of 1st and last cylinder – to convert the whole secondary hard disk to a single disk partition,
5. press t (will automatically select the only partition – partition 1) to change the default Linux partition type (0×83) to LVM partition type (0x8e),
6. press L to list all the currently supported partition type,
7. press 8e (as per the L listing) to change partition 1 to 8e, i.e. Linux LVM partition type,
8. press p to display the secondary hard disk partition setup. Please take note that the first partition is denoted as /dev/sda1 in Linux,
9. press w to write the partition table and exit fdisk upon completion.

fdisk end!

This LVM command will create a LVM physical volume (PV) on a regular hard disk or partition: pvcreate /dev/sda1

Now, another LVM command to create a LVM volume group (VG) called vg0 with a physical extent size (PE size) of 16MB: vgcreate -s 16M vg0 /dev/sda1

Be properly planning ahead of PE size before creating a volume group with vgcreate -s option!

Create a 400MB logical volume (LV) called lvol0 on volume group vg0: lvcreate -L 400M -n lvol0 vg0

This lvcreate command will create a softlink /dev/vg0/lvol0 point to a correspondence block device file called /dev/mapper/vg0-lvol0.

The Linux LVM setup is almost done. Now is the time to format logical volume lvol0 to create a Red Hat Linux supported file system, i.e. EXT3 file system, with 1% reserved block count: mkfs -t ext3 -m 1 -v /dev/mapper/vg0-lvol0

Create a mount point before mounting the new EXT3 file system: mkdir /mnt/vfs

The last step of this LVM tutorial – mount the new EXT3 file system created on logical volume lvol0 of LVM to /mnt/vfs mount point: mount -t ext3 /dev/mapper/vg0-lvol0 /mnt/vfs

To confirm the LVM setup has been completed successfully, use df -h command.


关注公众号【好便宜】( ID:haopianyi222 ),领红包啦~
搬瓦工,CN2 GIA 优质线路,搭梯子、海外建站推荐:
Comments are closed.