LVM Configuration on Ubuntu server

Source: Internet
Author: User
Tags hex code

In the installation of Linux, usually encountered a headache problem is the partition, in the end of each district how much, after a period of time, a partition is not enough, what to do? If it is a normal server, that all say, the big deal on the shutdown partition, but for some of the key servers, don't say shut down, is to stop the service is intolerable. For example: a virtual hosting service provider, originally to/home zoned 100G space, in the first year, everything is OK, space enough, until the second year, began to engage in promotion, the results two months later,/home partition is only 1GB left, and/var partition estimated 1 months to run out, What to do? Is there a technology that can dynamically increase hard disk space without stopping the service? Yes, this is the origin of LVM technology under Linux.

LVM, known as logical Volume Management, is a mechanism for managing disk partitions in a Linux environment by creating an abstract logical layer on hard disks and partitions to block the size of partitions and the difficulties that disk space poses to users. In LVM, multiple disk partitioning groups can be made into a storage pool where the administrator can create logical volume groups on the storage pool and mount them to the corresponding mount points, thus achieving the purpose of dynamically increasing disk space. For example, when the/home partition is not large enough, you can mount a portion of the disk to home/home, so that you can achieve zero-time to adjust the disk.

Before starting the LVM configuration, briefly describe a few basic concepts and terminology:

1. Physical storage Media:

Refers to the physical hard disk, in the/dev directory to see the SDA,SDB,SDC,HDA,HDB,HDC and so on.

2. Physical volume (pisical Volume):

Refers to a partition on a physical hard disk or a device that logically has the same functionality as a disk partition, which is the basic storage block of LVM, but is compared to the partition, but contains parameters related to LVM management. This is the storage pool that was previously spoken.

3. Volume groups (Volume Group):

An LVM volume group is similar to a physical hard disk, where multiple virtual "partitions" can be created on top of a volume group, and an LVM volume group consists of one or more physical volumes.

4. Logical volume (Logical Volume):

LVM's logical volumes are similar to hard disk partitions in non-LVM systems, where a file system can be built on top of a logical volume, used to mount to different mount points, and increase partition space-a real part of the user's dealings.

5. PE (physical Extent)

Each physical volume is divided into basic storage units, each of which has a unique address (something similar to the one on the physical hard disk). The size of PE defaults to 4MB.

6. LE (Logical Extent)

Each logical volume is also divided into a basic storage unit, and each Le also has a unique addressing. In the same volume group, the size of Le and PE is equal.

In summary, one conclusion is that one or more LVM partitions can be partitioned on one or more physical hard disks, and then these partitions can form a physical volume (PV), forming a storage pool. The user divides this storage pool one or more LV, mounts to the different partition to use, this is the LVM basic principle, is also establishes the LVM process.

In conjunction with the above example, if you want to add space to the/home and/var partitions, you should have the following steps:

1. Install 2 new drives to the server

2. Partition the new hard drive and mark it as an LVM partition

3. Merge the LVM partitions on the 2 new hard drives to form a new physical volume (PV)

4. Divide a physical volume into two logical volumes (LV): Home and Var, respectively

5. Establish the file system on both logical volumes

6. Attach these two logical volumes to/home and/var up

Now, to begin the practice of LVM, the example in this article is in VMware, with disk space of only 8GB, and the example above is different.

In this server, 1 hard disks are installed with the following partition sizes:

swap:384m

/boot:100m

/home:2gb

/var:2gb

/: All remaining space

Now, found that home/home space is not enough,/VAR is also in emergency, so I decided to install LVM for this server, expand space.

"First Step"

Turn off the virtual machine, add two hard drives, and both drives are 8GB in size. Because this is a virtual machine, there is no way to hot plug the hard disk, so can only shut down, if it is a physical server, with hot-swappable hard disk interface, can naturally save this step

"Step Two"

After booting again, you can see the newly added two HDD sdb and SDC in the/dev directory, the original one is SDA.

First, install the LVM management software first:

    1. $sudo Apt-get Install lvm2

Then, look at the hard drives in the current system:

    1. $sudo fdisk-l

You can see that there are 3 hard drives in the current system.

Then, the SDB is partitioned:

    1. $sudo Fdisk/dev/sdb

System prompt:

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF Disklabel

Building a new DOS disklabel with disk identifier 0xc3a40868.

Changes'll remain in memory only, until the decide to write them.

After that, of course, the previous content won ' t is recoverable.

Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite)

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 ')

Regardless of this hint, start now, at command (M for help): After entering N, which represents creating a new partition

The system then prompts you to:

E Extend

P Primary Partition

e represents the extended partition to be created, and p represents the primary partition to be created. Enter P here to create the primary partition.

The system prompts partition number (1-4): I want to allocate all the space of this hard disk to/home, do not use it, so it is enough to divide 1 zones, enter 1 here.

Then the system prompts first cylinder (1-1044, default 1): The defaults start with the initial cylinder, where the direct carriage return is OK.

Then the system prompts

Using Default value 1

Last cylinder, +cylinders or +size{k,m,g} (1-1044, default 1044)

Here is the partition size, I intend to all the space allocated to this partition, so directly input: 1044, the entire space allocated.

Then use the P command to print out the current partition situation.

Device Boot Start End Blocks Id System

/DEV/SDB1 1 1044 8385898+ Linux

Then, you can see that the type of this partition is Linux, and now you want to change it to LVM, using the T command:

System tip: Hex code (Type L to list codes): And then enter the L command to see all the code. In the system print out of this table, you can see the Linux LVM corresponding code is 8e, here enter 8e, Mark completed. After this step is done, the hard drive is OK, remember to save it with the W command.

Then use the same method to do the/DEV/SDC again.

"Step Three"

Now, there are two new drives in the system: SDB and SDC, and the LVM partitions sdb1 and SDC1 are built on top, and now it's time to add the two LVM partitions on the two hard drives to the physical volume (physical Volume). Use the command:

    1. $sudo PVCREATE/DEV/SDB1/DEV/SDC1

System prompt:

Physical volume "/dev/sdb1″successfully created

Physical volume "/dev/sdc1″successfully created

It is also easy to delete a partition using the command:

    1. $sudo PVREMOVE/DEV/SDB1

This command will remove the/DEV/SDB1 from the physical volume.

Once created, you can use the Pvdisplay command to view the status of a physical volume:

    1. $pvdisplay

"Fourth Step"

After the physical volume (PV) is created, the LVM partitions that are scattered on each of the physical hard disks are formed into a storage pool.

Now start creating the Logical Volume Group (Volume Group), which will block out the hard disk, partition, and allow the user to transparently manage the disk using the LVM feature, using the command:

    1. $sudo vgcreate EXTSPACE/DEV/SDB1/DEV/SDC1

System prompt:

Volume Group "Extspace" successfully created

This creates a logical volume called extspace, and after creation, you can see a device named Extspace in the/dev directory.

* Note: If a physical volume fileserver already exists, add the new hard disk partition/DEV/SDB1 to the logical volume group whose commands are:

    1. $sudo Vgextend FILESERVER/DEV/SDB1

When a logical volume group Extspace is created, the command to delete it is:

    1. $sudo Vgremove Extspace

The commands for viewing logical volume groups are:

    1. $sudo Vgdisplay

Or

    1. $sudo Vgscan

"Fifth Step"

Logical Volume Group (VG) created, and now create a logical volume on top, I'm going to create two logical volumes, one called Home_ext, one called var_ext, words too literally, a space to increase the/home partition, and a space for adding/var partitions.

Use the command:

    1. $sudo lvcreate--name home_ext--size 8G extspace
    2. $sudo lvcreate--name var_ext--size 8G extspace

These two commands are simple, meaning that you create two logical volumes (LVS) of 8GB size on a logical volume group (VG) with names of Home_ext,var_ext

When you're done, you'll be prompted:

Logical volume "Home_ext" created

Logical volume "Var_ext" created

Use the following command to view the case of a logical volume (LV):

    1. $sudo Lvdisplay

The output of the system is easy to understand, and is a parameter of two logical volumes, respectively. After creation, you can see two devices under/dev/extspace/, called Home_ext and Var_ext, respectively.

If you want to delete a logical volume, it is also easy to use the command:

    1. $sudo Lvremove/dev/extspace/home_ext

This removes the logical volume Home_ext that you just created.

"Sixth Step"

After the logical volume (LV) is created, basically the work is done 90%, only need to mount point mount on it, before mount, if the logical volume of space size, the name is not satisfied, you can also modify (of course, you can use to delete the Reconstruction method), LVM provides the corresponding command:

    1. $sudo lvextend-l 10g/dev/extspace/home_ext

This command increases the space size of the logical volume (LV) named Home_ext to 10G (This example cannot be increased because all disk space is used when the LVM partition is created)

    1. $sudo lvreduce-l 4g/dev/extspace/home_ext

This command reduces the space size of the home_ext logical volume (LV) to 4G

    1. $sudo lvrename Extspace/home_ext Home_ext1

This command renames the logical volume (LV) Home_ext in the Extspace volume group to HOME_EXT1

"Seventh Step"

Next, is to create the file system on the logical volume, this filesystem is to be consistent with the mount point file system, I have not tried to mount the Ext4 file system FAT32 is what effect, anyway I do are the same file system.

First of all, the Home_ext is made into Ext4 file system, my/home partition is EXT4

    1. $sudo Mkfs.ext4/dev/extspace/home_ext

And then make Var_ext into Ext4 file system, my/var partition is also EXT4

    1. $sudo Mkfs.ext4/dev/extspace/var_ext

Once you're done, you can mount the logical volume.

    1. $sudo Mount/dev/extspace/home_ext/home
    2. $sudo Mount/dev/extspace/var_ext/var

At this point, the problem of insufficient space to solve!

You can view the mounted file system using the Df-h command.

"Eighth Step"

In the seventh step, the LVM configuration is completed, but considering that the server will also have a reboot, and after rebooting, these logical volumes will not be automatically mounted, so you need to modify the/etc/fstab file (before modifying it to keep a backup):

    1. $sudo Vi/etc/fstab

Add the following lines:

View Plaincopy to Clipboardprint?
    1. /dev/extspace/home_ext/home ext4 rw,noatime 0 0
    2. /dev/extspace/var_ext/var ext4 rw,noatime 0 0

Restart verification, everything is OK.

LVM Configuration on Ubuntu server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.