"Linux" Add a disk to make an LVM volume and mount it in a partition

Source: Internet
Author: User

Linux server to add a new hard disk, you can directly format the disk can be used, such as mount in the/usr/local directory, but there is a drawback, that is, if this disk full, the subsequent want to expand, can not continue to mount this/usr/local mount point, There is a certain amount of trouble with scaling, so we recommend using LVM to support dynamically expanding disks. Detailed how to do this is described below.

1, to view the new disk, need to use root permissions

Fdisk-l

See that there is a new 100G disk

2, partitioning the disk

Fdisk/dev/xvdb

1, Input: n

Means to create a new partition

2, Input: P

Represents creating a basic partition (P is the base partition and E is an extended partition)

3, select the partition number, 1~4, use 1 by default, press ENTER directly.

4, select the partition starting point, using the default, press ENTER directly.

5, select the end of the partition, using the default, press ENTER directly.

6, Partition complete.

  

3. Change the partition number

We need to change the partition type to a Linux LVM volume to create LVM.

Input: T

Enter T to change the partition number

Input: L

Uppercase L means view all numbers

Here we choose 8e

Input: 8e

Enter

4, Save exit

Input: W

Indicates write to disk (write)

Before we proceed to the next step, we explain the relationship between PV, VG, and LV.

A hard disk F partition consists of a PV (physical volume)

One or more PV form a VG (volume group)

A VG can be divided into multiple LV (logical volumes)

5, create PV

Input: PVCREATE/DEV/XVDB1

The disk partition at this time is xvdb1, not xvdb.

6, create VG

Input: Vgcreate vg_group/dev/xvdb1

The vg_group here is the name of the VG group and can be customized.

View the created VG

Input: Vgdisplay

You can see that you have successfully created

7, creating the LV

Input: lvcreate-l 60g-n vg_usr Vg_group

The size of the LV is followed by-l

-N Create a new LV with the name VG_USR

The VG used is Vg_group

8, formatted LV

To view the file type of the system

Input: df-th

File type is EXT4

Formatting LV

Input: MKFS.EXT4/DEV/VG_GROUP/VG_USR

MKFS is followed by the file type.

9. Edit the/etc/fstab file to create a disk boot auto mount

Vim/etc/fstab

Add a row at the end of the file

First column: Disk to be mounted

Second column: mount point

Third column: File type

Fourth column: Mount option, refer to man mount for details. Some common options are listed below:
Auto: The system mounts automatically, Fstab is this option by default
Ro:read-only
Rw:read-write
DEFAULTS:RW, suid, Dev, exec, auto, Nouser, and async.

Fifth column: For the dump option, set whether to let the Backup program dump backup file system, 0 is ignored, 1 is backup.

Sixth column: For the fsck option, tell the FSCK program in what order to check the file system, 0 is ignored.

10, re-mount

Mount-a

11 to see if the mount was successful

Now that the new disk creation LVM is complete, the LVM can be expanded at any time later.

To enlarge a logical Volume:

Lvextend-l +100g/dev/mapper/vg_group-vg_user

Then use the RESIZE2FS update

Resize2fs/dev/mapper/vg_group-vg_user

"Linux" Add a disk to make an LVM volume and mount it in a partition

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.