Guide |
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.
2. Check disk space:
Run the following command to check the current disk space size.
# df-h# Fdisk-l
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/host 1/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.
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/sdawelcome to Fdisk (util-linux 2.23.2) Press the ' m ' Key for Helpcommand (M-help): Mcommand Actiona Togg Le a bootable FLAGB edit BSD DISKLABELC toggle the DOS compatibility Flagd Delete a partitiong create a new empty GPT part Ition Tableg Create a IRIX (SGI) partition Tablel list known partition TYPESM print this Menun add a new Partitiono creat e A new empty DOS partition Tablep print the partition Tableq quit without saving changess create a new empty Sun Disklabe Lt change a partition ' s system idu change display/entry UNITSV Verify the partition Tablew write table to disk and Exitx E Xtra functionality (experts only) Command (M-help):
Type ' P ' to view the current partition table information, then type the ' n ' key to create a new primary partition, select all available sectors, use the ' t ' command to change the disk type to ' Linux LVM ', and then choose the encoding ' 8e ' or uncheck it by default, and its default type is ' 83 '. Now enter ' W ' to save the partition table information and exit the command environment, as shown below:
Command (M for help): Wthe partition table have 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 is being used atthe next reboot or after you run Partprobe (8) or KPARTX (8)
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# Pvcreate/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
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
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.
Select the configuration information that is required for the new disk, as shown in, select the size of the new disk and its type.
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
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
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
Conclusion:
The process of managing disk partitions on a Linux CentOS 7 system is straightforward, and you can use the steps described in this article to augment the disk space of any logical volume you have. You do not need to restart the server on the production line, just simply rescan under the SCSI device, and expand the LVM (logical volume management) you want. We hope this article will be of use to you. Please feel free to post useful comments and suggestions.
Free to provide the latest Linux technology tutorials Books, for open-source technology enthusiasts to do more and better: http://www.linuxprobe.com/
How to add a new disk to CentOS 7 without rebooting the system