How to expand the disk partition for centos system

How to expand the disk partition for centos system

Problem/failure/scenario/requirement

The hard disk of Eve-ng's virtual machine OVA is only 38G, so more space is needed. After VMware directly expands the hard disk, restart the system and use fdisk -l to see that the hard disk has been expanded, but the file system has not been expanded. The newly added space needs to be allocated to a certain file system. The entire expansion process is recorded below

Solution/Steps

Expand the disk to 250G in the VM and restart the system to check the current file system status

root@eve-ng:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.9G 0 7.9G 0% /dev
tmpfs 1.6G 19M 1.6G 2% /run
/dev/mapper/eve--ng--vg-root 38G 13G 23G 36% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/sda1 472M 83M 365M 19% /boot

root@eve-ng:~# fdisk -l
...omit some content Disk /dev/sda: 250 GiB, 268435456000 bytes, 524288000 sectors //You can see that there are already 250G Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3e3ca055

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 83884031 82882562 39.5G 5 Extended
/dev/sda5 1001472 83884031 82882560 39.5G 8e Linux LVM

Disk /dev/mapper/eve--ng--vg-root: 38.6 GiB, 41406169088 bytes, 80871424 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/eve--ng--vg-swap_1: 980 MiB, 1027604480 bytes, 2007040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

//Execute the partition below root@eve-ng:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type
  p primary (1 primary, 1 extended, 2 free)
  l logical (numbered from 5)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (999424-524287999, default 999424): 83884032 //Note that this is the last block allocated before (sda5 end) plus one (83884031+1)
Last sector, +sectors or +size{K,M,G,T,P} (83884032-524287999, default 524287999): //Note whether this is the last block. Created a new partition 3 of type 'Linux' and of size 210 GiB.

Command (m for help): t
Partition number (1-3,5, default 5): 3 3
Partition type (type L to list all types): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

root@eve-ng:~# reboot

root@eve-ng:~# pvcreate /dev/sda3
 Physical volume "/dev/sda3" successfully created
root@eve-ng:~# vgdisplay
 --- Volume group ---
 VG Name eve-ng-vg
 System ID
 Format lvm2
 Metadata Areas 1
 Metadata Sequence No 3
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 2
 Open LV 2
 Max PV 0
 Cur PV 1
 Act PV 1
 VG Size 39.52 GiB
 PE Size 4.00 MiB
 Total PE 10117
 Alloc PE / Size 10117 / 39.52 GiB
 Free PE / Size 0 / 0
 VG UUID EvwUbc-nfsg-dHqA-znxB-U3gv-V782-Q8ZxkI

root@eve-ng:~# vgextend eve-ng-vg /dev/sda3
 Volume group "eve-ng-vg" successfully extended
root@eve-ng:~# vgdisplay
 --- Volume group ---
 VG Name eve-ng-vg
 System ID
 Format lvm2
 Metadata Areas 2
 Metadata Sequence No 4
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 2
 Open LV 2
 Max PV 0
 Cur PV 2
 Act PV 2
 VG Size 249.52 GiB
 PE Size 4.00 MiB
 Total PE 63877
 Alloc PE / Size 10117 / 39.52 GiB
 Free PE / Size 53760 / 210.00 GiB
 VG UUID EvwUbc-nfsg-dHqA-znxB-U3gv-V782-Q8ZxkI

root@eve-ng:~# lvdisplay
 --- Logical volume ---
 LV Path /dev/eve-ng-vg/root
 LV Name root
 VG Name eve-ng-vg
 LV UUID ktUpR0-VpqS-rJJv-a1FC-u6Gd-U8yN-2WYQ53
 LV Write Access read/write
 LV Creation host, time eve-ng, 2018-03-21 02:25:21 +0200
 LV Status available
 # open 1
 LV Size 38.56 GiB
 Current LE 9872
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:0

//Extend logical volume root@eve-ng:~# lvextend -l +100%FREE /dev/eve-ng-vg/root
 Size of logical volume eve-ng-vg/root changed from 38.56 GiB (9872 extents) to 248.56 GiB (63632 extents).
 Logical volume root successfully resized.

root@eve-ng:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.9G 0 7.9G 0% /dev
tmpfs 1.6G 19M 1.6G 2% /run
/dev/mapper/eve--ng--vg-root 38G 13G 23G 36% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/sda1 472M 83M 365M 19% /boot

//For online capacity expansion, you must first check the type of the current file system. You can view it through cat /etc/fstab root@eve-ng:~# resize2fs /dev/eve-ng-vg/root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/eve-ng-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 16
The filesystem on /dev/eve-ng-vg/root is now 65159168 (4k) blocks long.

root@eve-ng:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.9G 0 7.9G 0% /dev
tmpfs 1.6G 19M 1.6G 2% /run
/dev/mapper/eve--ng--vg-root 245G 13G 222G 6% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/sda1 472M 83M 365M 19% /boot

refer to

Online expansion Use resize2fs or xfs_growfs to expand the mount directory online

  • resize2fs for file systems ext2 ext3 ext4
  • xfs_growfs for the file system xfs

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementation of formatting partitions and mounting in Centos7
  • How to resize partitions in CentOS7
  • How to add and delete swap partition in Centos7
  • Detailed explanation of adding swap partition in CentOS7 in Linux
  • Detailed explanation of adjusting partition size under CentOS/Linux (taking home and root partitions as examples)
  • Detailed explanation of CentOS Alibaba Cloud server hard disk partition and mounting
  • Centos5 expands the /root partition
  • How to install the system by manually partitioning centos 5

<<:  Introducing icons by implementing custom components based on Vue

>>:  Solution to the problem that Java cannot connect to MySQL 8.0

Recommend

Advanced Usage Examples of mv Command in Linux

Preface The mv command is the abbreviation of mov...

Detailed explanation of the 14 common HTTP status codes returned by the server

HTTP Status Codes The status code is composed of ...

Implementation of 2D and 3D transformation in CSS3

CSS3 implements 2D plane transformation and visua...

MySQL 5.7.17 installation and configuration method graphic tutorial (windows)

1. Download the software 1. Go to the MySQL offic...

SQL implementation of LeetCode (177. Nth highest salary)

[LeetCode] 177.Nth Highest Salary Write a SQL que...

Management of xinetd-based services installed with RPM packages in Linux

Table of contents Preface 1. Startup management b...

Detailed use cases of vue3 teleport

Official Website https://cli.vuejs.org/en/guide/ ...

Detailed examples of variable and function promotion in JavaScript

js execution Lexical analysis phase: includes thr...

MySQL 8.0.21 installation tutorial with pictures and text

1. Download the download link Click download. You...

Use the Linux seq command to generate a sequence of numbers (recommended)

The Linux seq command can generate lists of numbe...

MySQL 5.7 installation-free configuration graphic tutorial

Mysql is a popular and easy-to-use database softw...

How to operate json fields in MySQL

MySQL 5.7.8 introduced the json field. This type ...