How to add new disks in CentOS 7 without restarting the system

Source: Internet
Author: User
Tags virtual environment

How to add new disks in CentOS 7 without restarting the system

For most system administrators, expanding the disk space of Linux servers is one of the daily tasks. Therefore, this article uses Linux commands to demonstrate some simple operation steps on CentOS 7 to expand your disk space without restarting your production server. With regard to expanding and adding new disks to the Linux system, we will mention a variety of methods and feasibility, you can choose the most suitable one as needed.

 

1. Expand disk space on the VM client:

Before adding a disk volume to a Linux system, you must add a new physical disk, you can also set it in VMware vShere, VMware workstation, and other virtual environment software 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.

  1. #df-h
  2. #fdisk-l

Fdisk check

As you can see, although we have increased it to 50 GB in the back end, the total disk size is still 10 GB.

 

3. Expand the space without restarting the Virtual Machine

Run the following command to re-scan the SCSI (Note: Small Computer System Interface) bus and add a SCSI device. Then, the System can expand the physical volume disk space of the operating System, you do not need to restart the VM.

  1. #ls/sys/class/scsi_host/
  2. #echo"- - -">/sys/class/scsi_host/host0/scan
  3. #echo"- - -">/sys/class/scsi_host/host1/scan
  4. #echo"- - -">/sys/class/scsi_host/host2/scan

Run the following command to check the name of the SCSI device and then scan the SCSI bus again.

  1. #ls/sys/class/scsi_device/
  2. #echo1>/sys/class/scsi_device/0\:0\:0\:0/device/rescan
  3. #echo1>/sys/class/scsi_device/2\:0\:0\:0/device/rescan

As shown in, the SCSI bus will be scanned again, and the disk size we set on the Virtual Machine Client will be displayed normally.

Rescan disk device

 

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. Follow these steps to expand your physical disk volume.

  1. #fdisk/dev/sda
  2. Welcome to fdisk(util-linux 2.23.2) press the 'm' key for help
  3. Command(m for help): m
  4. Command action
  5. a toggle a bootable flag
  6. b edit bsd disklabel
  7. c toggle the dos compatibility flag
  8. d delete a partition
  9. g create a newempty GPT partition table
  10. G create an IRIX (SGI) partition table
  11. l list known partition types
  12. m printthis menu
  13. n add a new partition
  14. o create a newempty DOS partition table
  15. p print the partition table
  16. q quit without saving changes
  17. s create a newemptySun disklabel
  18. t change a partition's system id
  19. u change display/entry units
  20. v verify the partition table
  21. w write table to disk and exit
  22. x extra functionality (experts only)
  23. Command (m for help):

Type 'P' to view the current partition table information, and then type 'n' 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 encoding '8e' or not selected by default. The default encoding type is '83 '.

Enter 'w' to save the partition table information and exit the command environment, as shown below:

  1. Command(m for help):w
  2. The partition table has been altered!
  3. Calling ioctl() to re-read partition table.
  4. WARNING:Re-reading the partition table failed with error 16:Deviceor resource busy.
  5. The kernel still uses the old table.Thenew table will be used at
  6. the nextrebootor after you run partprobe(8)or kpartx(8)

New disk Volume

 

5. Create a physical volume:

Run the 'partprob' or 'kpartx 'command to make the Partition Table take effect, and then use the following command to create a new physical volume.

  1. # partprobe
  2. # pvresize /dev/sda3

To check the newly created volume, run the following command to check whether the new physical volume has been created and is available. Next, we can use this new physical volume to expand the 'cento' volume group, as shown below:

  1. # pvdisplay
  2. # vgextend centos /dev/sda3

Extend volume Group

 

6. Extend the logical volume:

Now we use the following command to expand the logical volume to increase the disk space that our system is using.

  1. # lvextend -L +40G/dev/mapper/centos-root

Once a message is returned, run the following command to expand the size of your logical volume.

  1. # xfs_growfs /dev/mapper/centos-root

'/' The partition size has been successfully increased. You can use the 'df 'command to check the size of your disk drive. .

Increase disk space

 

7. Add a new disk to expand the root partition without restarting the system:

This is the second method. The command is very simple and used to increase the logical volume space on CentOS 7.

So the first step is to open the setting page of your virtual machine client, click 'add' button, and then proceed to the next step.

Add new disk

Select the configuration information required for the new disk, as shown in. Select the size and type of the new disk.

New disk setup

Enter the server and repeat the following command to scan your disk devices to make the new disk visible in the system.

  1. #echo"- - -">/sys/class/scsi_host/host0/scan
  2. #echo"- - -">/sys/class/scsi_host/host1/scan
  3. #echo"- - -">/sys/class/scsi_host/host2/scan

List the names of your SCSI devices:

  1. #ls/sys/class/scsi_device/
  2. #echo1>/sys/class/scsi_device/1\:0\:0\:0/device/rescan
  3. #echo1>/sys/class/scsi_device/2\:0\:0\:0/device/rescan
  4. #echo1>/sys/class/scsi_device/3\:0\:0\:0/device/rescan
  5. #fdisk-l

Scanning new disk

Once the new disk is visible, run the following command to create a new physical volume and add it to the volume group, as shown below.

  1. # pvcreate /dev/sdb
  2. # vgextend centos /dev/sdb
  3. # vgdisplay

Extending Volume Group

Now, the logical volume is extended based on the disk space and added to the root partition.

  1. # lvextend -L +20G/dev/mapper/centos-root
  2. # xfs_growfs /dev/mapper/centos-root
  3. #df-h

Increase/Partition

 

Conclusion:

The process of managing disk partitions on CentOS 7 is very simple. You can use the procedure described in this article to expand the disk space of any logical volume. You do not need to restart the servers on the production line, but simply re-scan the SCSI device and expand the LVM (logical volume Management) you want ). We hope this article will be useful to you. Please post useful comments and suggestions at will.

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.