Home > System Tutorial > LINUX > body text

How to add a hard disk and adjust the LVM size on CentOS7?

王林
Release: 2024-01-02 12:00:06
forward
1294 people have browsed it

LVM is the abbreviation of LogicalVolume Manager (Logical Volume Management), which is a mechanism for managing disk partitions in the Linux environment. LVM virtualizes one or more disk partitions (PV) into a volume group (VG), which is equivalent to a large hard disk, on which we can divide some logical volumes (LV). When the space in the volume group is insufficient, new disk partitions can be added. We can also allocate some space from the remaining space of the volume group for use by logical volumes that do not have enough space.

The LVM model is as shown below:

No need to restart, refresh new hard disk files

First cat command cat /proc/scsi/scsi Tour Id:??What is the largest. Then echo "scsiadd-single-device 0 0 ? 1 0" > /proc/scsi/scsi

cat /proc/scsi/scsi >>

Attached devices:

Host: scsi0 Channel: 00 Id: 00 Lun: 00

Vendor: VMware, Model: VMware Virtual S Rev: 1.0

Type: Direct-Access ANSI SCSI revision: 02

Host: scsi2 Channel: 00 Id:00 Lun: 00

Vendor: NECVMWar Model: VMware IDECDR10 Rev: 1.00

Type: CD-ROM ANSI SCSI revision: 05

Host: scsi0 Channel: 00 Id:01 Lun: 00

Vendor: VMware, Model: VMware Virtual S Rev: 1.0

Type: Direct-Access ANSI SCSI revision: 02

2. After the addition is completed

1. Add a hard drive (8GB) to the system

Use fdisk -l to see that the new disk is /dev/vdb:

1shell# fdisk -l

2. Partition the new disk

Use the fdisk command to partition the new disk. A primary partition /dev/vdb1 is created here, with a size of 8GB. Finally, use the partprobe (or partx -u) command to re-read the partition table:

1shell# fdisk /dev/vdb

2shell# partprobe

During the partitioning process, pay attention to setting the format to 8e, which is the partition format of LVM.

3. Create a physical volume (PV)

Use the pvcreate command to create a physical volume, and pvdisplay to view the physical volume information:

1shell# pvcreate /dev/vdb1

2shell# pvdisplay

4. Add PV to the volume group (VG)

VG Create #vgcreate VG name device name

Use vgdisplay to view volume group information. The following figure shows that the volume group name is centos and the free size is 0:

1shell# vgdisplay

Use the vgextend command to add /dev/vdb1 to centos:

1shell# vgextend centos /dev/vdb1

Let’s re-check the volume group information and find that the free space is 8GB, indicating that /dev/vdb1 has been successfully added:

5. Create a logical volume (LV)

Use the lvcreate command to divide a new logical volume from the volume group. Here, a logical volume partition named newlv with a size of 4GB is created; use lvdisplay to view the logical volume information:

1shell# lvcreate -L 4G -n newlv centos (specify to add 4G capacity)

2 lvcreate -l 100%free -n newlv centos (add maximum available capacity)

shell# lvdisplay

Let’s check the volume group information again. The volume group has 4GB of space left:

6. Format the logical volume and mount it

After formatting, the new logical volume can be mounted to the system to store data. Use mkfs.xfs to format the xfs file system of CentOS7:

1shell# mkfs.xfs /dev/centos/newlv

Mount to the /mnt directory (you can mount to the directory you need). After mounting, you will see that the capacity is 4GB:

1shell# mount -t xfs /dev/centos/newlv /mnt/

2shell# df -Th

Set up automatic mounting at boot, edit the /etc/fstab file and add the last line:

1/dev/centos/newlv/mntxfs defaults1 2

7. Logical volume expansion

Use the lvextend command to expand the logical volume. I allocated all the remaining space to newlv and increased it to 8GB, as shown below:

1shell# lvextend -l 100%FREE /dev/centos/newlv

Use the xfs_growfs command to adjust the xfs format file system size online (CentOS6 uses resize2fs):

1shell# xfs_growfs /dev/centos/newlv

Finally we see that the logical volume partition has been dynamically expanded to 8GB:

The above is the detailed content of How to add a hard disk and adjust the LVM size on CentOS7?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template