CENTOS7 root partition HDD expansion

Source: Internet
Author: User

The use of virtual machines often occurs when the hard disk capacity is insufficient, without changing the configuration requirements, directly to the root directory to increase capacity.

The default installation of Centos7 has managed to manage the disk as an LVM volume, which makes it easier to expand disk capacity. But centos7 in the expansion of the file partition, many articles with the resize2fs command , will be error, LVM use of XFS partition file format, you can not use the command.


There are still many hard disks that are used in MBR mode, with only 4 primary partitions. There were 2 installations, one was swap and the other was root, and two partitions were used. This can only be divided into 2, if the use of the future is uncertain, then the expansion of the time, do not divide the primary partition, but expand the partition, in order to be able to expand the capacity of the hard disk many times.


The first is in the virtual Machine management interface, expand the hard disk capacity, omitted here, start the machine.

And take a look at your capacity first.

Df-h

/dev/mapper/centos-root 16G 5.8G 13G 33%/
Devtmpfs 912M 0 912M 0%/dev
Tmpfs 921M 84K 921M 1%/DEV/SHM
Tmpfs 921M 8.9M 912M 1%/run
Tmpfs 921M 0 921M 0%/sys/fs/cgroup
/DEV/SDA1 497M 119M 379M 24%/boot


Fdisk-l

/DEV/SDA1 * 2048 1026047 512000 Linux
/dev/sda2 1026048 33554431 16264192 8e Linux LVM

Then partition the hard disk

Fdisk/dev/sda

Using the n command

Command (M for help): N

Partition Type:
P Primary (2 primary, 0 extended, 1 free)
E Extended

Will let you choose the number of areas, the general Order row, is 3, if the extension once, with the P option, if it is possible to expand several times later, choose E, we here in order to simply use P, set up a primary partition, and then you can use the P command to view the results

/dev/sda3 37748736 46137343 4194304-up Linux

Can see the ID is 83, is Linux, this can not be extended to the coupon, with the T command to change the partition format of 8e, is the Linux LVM logical volume format.

Then save it with the W command. to reboot.


Build a physical volume

Pvcreate/dev/sdb3

Show me a look.

Pvdisplay

---physical volume---
PV Name/dev/sda2
VG Name CentOS
PV Size 15.51 gib/not usable 3.00 MiB
Allocatable Yes (but full)
PE Size 4.00 MiB
Total PE 3970
Free PE 0
Allocated PE 3970
PV UUID DXUC0B-LZE1-X8K8-JZMI-SEQE-FX1J-CXKIHS

---physical volume---
PV Name/dev/sda3
VG Name CentOS
PV Size 2.00 gib/not Usable 4.00 MiB
Allocatable Yes (but full)
PE Size 4.00 MiB
Total PE 511
Free PE 0
Allocated PE 511
PV UUID Nxf54x-zdcs-b7gi-lhfo-1ypq-dww5-kvsipf


The following is the expansion

Look at the current volume group

Vgdisplay

---Volume Group---
VG Name CentOS
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 7
VG Access Read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
ACT PV 3
VG Size 19.50 GiB
PE Size 4.00 MiB
Total PE 4992
Alloc pe/size 4992/19.50 GiB
Free Pe/size 0/0
VG UUID LWO318-DF9J-SQWF-K7SK-ANVD-BXTB-ZNFHBH

Add the new SDA3 partition to the volume, from the above display the VG name CentOS, the volume name is CentOS

Vgextend Centos/dev/sda3

Check it out.

Vgdisplay

Free Pe/size 511/2 Gib

It's changed.


Take a look at the logical zone situation

Lvdisplay
---Logical volume---
LV Path/dev/centos/swap
LV Name Swap
VG Name CentOS
LV UUID I7xzpm-66bq-nny4-wabk-tcrl-ewld-t8dhy7
LV Write Access Read/write
LV Creation Host, time localhost, 2016-11-07 15:27:13 +0900
LV Status Available
# open 2
LV Size 1.60 GiB
Current LE 410
Segments 1
Allocation inherit
Read ahead Sectors Auto
-Currently set to 256
Block Device 253:0

---Logical volume---
LV Path/dev/centos/root
LV Name Root
VG Name CentOS
LV UUID kn1muq-t30g-x4b3-norh-txgu-r1ql-vl5w6p
LV Write Access Read/write
LV Creation Host, time localhost, 2016-11-07 15:27:14 +0900
LV Status Available
# open 1
LV Size 15.90 GiB
Current LE 4582
Segments 3
Allocation inherit
Read ahead Sectors Auto
-Currently set to 256
Block Device 253:1

Expand the size of the volume group, the path is the above LV Path/dev/centos/root

Lvextend-l +1.966g/dev/centos/root

Some articles use/dev/mapper/centos-root.

In fact, they are pointing to. /dm-1, all can.

Another point, here with the +1.996g, not 2G, because 2GB will fail, free pe/size 511/2 GIB display 511 blocks, 511*4/1024=1.996

Take a look at the logical zone situation.

---Logical volume---
LV Path/dev/centos/swap
LV Name Swap
VG Name CentOS
LV UUID I7xzpm-66bq-nny4-wabk-tcrl-ewld-t8dhy7
LV Write Access Read/write
LV Creation Host, time localhost, 2016-11-07 15:27:13 +0900
LV Status Available
# open 2
LV Size 1.60 GiB
Current LE 410
Segments 1
Allocation inherit
Read ahead Sectors Auto
-Currently set to 256
Block Device 253:0

---Logical volume---
LV Path/dev/centos/root
LV Name Root
VG Name CentOS
LV UUID kn1muq-t30g-x4b3-norh-txgu-r1ql-vl5w6p
LV Write Access Read/write
LV Creation Host, time localhost, 2016-11-07 15:27:14 +0900
LV Status Available
# open 1
LV Size 17.90 GiB
Current LE 4582
Segments 3
Allocation inherit
Read ahead Sectors Auto
-Currently set to 256
Block Device 253:1

Size LV size changed from 15.90 Gib to 17.90 Gib.


The following is the size of the extended file system, because this time with df-h is not see the larger.

Most of the online articles used RESIZE2FS, unfortunately, Resize2fs:bad magic number in Super-block

This command has not adapted to the new system requirements.

Xfs_growfs/dev/centos/root

The last line displayed

Data blocks changed from XXXXXX to XXXXXX

Indicates that it has been expanded

At this time again with DF-H can see capacity becomes bigger.

This article from "Genius without that 1% is absolutely impossible" blog, please be sure to keep this source http://xushen.blog.51cto.com/1673219/1870526

CENTOS7 root partition HDD expansion

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.