How to add a new disk in CentOS 7 without rebooting the system

Source: Internet
Author: User
Tags virtual environment
Guide Expanding the disk space of a Linux server is one of the day-to-day tasks for most system administrators. So this article will expand your disk space without restarting your production server by using Linux commands to demonstrate some simple steps on the CentOS 7 system. Regarding the expansion and addition of new disk to Linux systems, we will mention a variety of methods and a variety of possibilities, which are the most suitable for your choice.
1. Expand disk space on 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 a VMware vshere, VMware Workstation, and other virtual environment software that you use to increase the capacity of a single 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, the total disk size is still ten GB, although we've increased it to gigabytes in the back end. 3. Extend the space without restarting the virtual machine



Now run the following command, by rescan the SCSI (note: Small Computer system Interface small Computer system interface) bus and add SCSI devices, the system can extend the physical volume disk space of the operating system 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 name of the SCSI device 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 in the following illustration, the SCSI bus is scanned again, and the disk size that we set up on the virtual machine client is displayed correctly.
4. Create a new disk partition:



Once you can see the extended disk space in the system, you can run the following command to format your disk to create a new partition. Use the following procedure 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 the ' n ' key to create a new primary partition, select all the available sectors, use the ' t ' command to change the disk type ' LINUXLVM ', then either encode ' 8e ' or default, and the default type is ' 83 '.
Now enter ' W ' to save the partition table information and exit the command environment as follows:


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 is used at the
next reboot or after you run Partprobe (8) or KPARTX (8)


5. Create a physical Volume:



Depending on the prompts above, run the ' partprob ' or ' kpartx ' command to make the partitioned table effective, 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 follows:


# pvdisplay
# vgextend Centos/dev/sda3


6. Extended Logical Volume:



Now we extend the logical volume using the command below 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 increased successfully, and you can use the ' DF ' command to check the size of your disk drive. As illustrated.
7. Expand the root partition by adding new disks without restarting the system:



This is the second method, which uses a very simple command to increase the amount of logical volume space on the CentOS 7 system. So the first step is to open your virtual machine client's Settings page, click ' Add ' button, and then continue to the next step.

Select the configuration information you need for the new disk, as shown in the following figure, to 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 on 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 disks are 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 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 very simple, and you can use the steps described in this article to augment the disk space of any logical volume. You do not need to reboot the server on the production line, simply rescan the SCSI devices, and extend the LVM (logical volume management) you want. We hope this article will be useful to you. Please feel free to post useful comments and suggestions.






Reproduced in this article from: http://www.linuxprobe.com/how-add-newdisk-noreboot/free to provide the latest Linux technology tutorials Books, for the open source technology enthusiasts to do more and better: http://www.linuxprobe.com/


Related Article

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.