For most system administrators, expanding the disk space of a Linux server is one of the daily tasks. So this article will use Linux commands to demonstrate some simple steps on the CentOS 7 system to augment your disk space without restarting your production server. To expand and add new disk-to-Linux systems, we will mention a variety of methods and possibilities that are best suited to your needs.
1. Expand disk space on the virtual machine client:
Before adding a disk volume to a Linux system, you first need to add a new physical disk, or set it up in VMware Vshere, VMware workstations, and other virtual environment software that you use to increase the capacity of a virtual disk.
Increase disk
2. Check disk space:
Run the following command to check the current disk space size.
Fdisk Check
As you can see, although we have increased it to more than a few gigabytes of space at the back end, the total disk size is still at this time of ten GB.
3. Expand the space without restarting the virtual machine
Now run the following command by rescanning the SCSI (Note: Small computer system Interface small Computer system interface) bus and adding SCSI devices, the system can expand the physical volume of the operating system disk space, and do not need to restart the virtual machine.
# ls /sys/class/scsi_host/
# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
# echo "- - -" > /sys/class/scsi_host/host2/scan
Use the following command to check the SCSI device name and then rescan the SCSI bus.
# ls /sys/class/scsi_device/
# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
As shown, the SCSI bus is re-scanned, and then the size of the disk that we set on the virtual machine client is displayed normally.
Rescan Disk Device
4. Create a new disk partition:
Once you can see the extended disk space in your system, you can run the following command to format your disk to create a new partition. Follow these steps to expand your physical disk volume.
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2) press the ‘m‘ key for help
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition‘s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
Type ' P ' to view the current partition table information, then type ' n ' key to create a new primary partition and select all available sectors. Use the ' t ' command to change the disk type to ' Linux LVM ' and then select ' Encode ' 8e ' or uncheck it by default, with the default type encoded as ' 83 '.
Now enter ' W ' to save the partition table information and exit the command environment, as shown below:
Command (m for help): w
The partition table has been altered!
Calling ioctl to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 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)
New Disk Volume
5. Create a physical Volume:
Based on the above prompts, run the ' partprob ' or ' kpartx ' command for the partition table to take effect, and then use the following command to create a new physical volume.
# partprobe
# pvresize /dev/sda3
To check the newly created volume, run the following command to see if the new physical volume has been created and is available. Next, we can use this new physical volume to extend the ' CentOS ' volume group, as shown below:
# pvdisplay
# vgextend centos /dev/sda3
Extend Volume Group
6. Expand the logical Volume:
Now we use the following command to extend the logical volume to increase the disk space that our system is using.
# lvextend -L +40G /dev/mapper/centos-root
Once you have returned a message that adds success, you can run the following command to extend the size of your logical volume.
# xfs_growfs /dev/mapper/centos-root
The size of the '/' partition has been increased successfully, and you can use the ' DF ' command to check the size of your disk drive. Shown
Increase disk space
7. Expand the root partition by adding a new disk without rebooting the system:
This is the second method, which uses a very simple command to increase the amount of logical volume on a CentOS 7 system.
So the first step is to open the Settings page of your virtual machine client, click on ' Add ' button, then proceed to the next step.
ADD New Disk
Select the configuration information that is required for the new disk, as shown in, select the size of the new disk and its type.
New Disk Setup
Then go to the server and repeat the following command to scan your disk device to make the new disk visible in the system.
# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
# echo "- - -" > /sys/class/scsi_host/host2/scan
List the name of your SCSI device:
# ls /sys/class/scsi_device/
# echo 1 > /sys/class/scsi_device/1\:0\:0\:0/device/rescan
# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
# echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
# fdisk -l
Scanning new disk
Once the new disk is visible, you can run the following command to create a new physical volume and then add it to the volume group, as shown below.
# pvcreate /dev/sdb
# vgextend centos /dev/sdb
# vgdisplay
Extending Volume Group
Now expand the logical volume based on the space size of the disk, and then add it to the root partition.
# lvextend -L +20G /dev/mapper/centos-root
# xfs_growfs /dev/mapper/centos-root
# df -h
Increase/partition
Reference
[1]: http://linoxide.com/author/kashifs/
[2]: Https://github.com/runningwater
[3]: Https://github.com/wxy
[4]: Https://github.com/LCTT/TranslateProject
Centos 7 Add New disk