Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add a hard disk to CentOS on VPS without restarting the server?

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to add a hard disk to CentOS on VPS without restarting the server. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

For most system administrators, expanding the disk space of the Linux server is one of the daily tasks. So this article will demonstrate some simple steps to expand your disk space without restarting your production server on a CentOS 7 system by using the Linux command. With regard to expanding and adding new disks to the Linux system, we will mention a variety of methods and possibilities, and you can choose the most suitable one according to your needs.

1. Expand disk space on the virtual machine client:

Before adding disk volumes to your 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 you use to increase the capacity of a virtual disk.

two。 Check disk space:

Run the following command to check the current disk space.

The code is as follows:

# df-h

# fdisk-l

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

3. Expand the space without restarting the virtual machine

Now run the following command, by rescanning the SCSI bus and adding SCSI devices, the system can expand the physical volume disk space of the operating system without the need to restart the virtual machine.

The code is as follows:

# 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.

The code is as follows:

# 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 figure, the SCSI bus is rescanned, and then the disk size we set on the virtual machine client will display normally.

4. Create a new disk partition:

Once you can see the expanded 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.

The code is as follows:

# 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, and then type the'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 choose to encode' 8e'or not by default, its default type encoding is' 83'.

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

The code is 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 will be used at

The next reboot or after you run partprobe (8) or kpartx (8)

5. Create a physical volume:

According to the above prompts, run the 'partprob' or' kpartx' command to make the partition table effective, and then use the following command to create a new physical volume.

The code is as follows:

# 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:

The code is as follows:

# pvdisplay

# vgextend centos / dev/sda3

6. Extend logical volumes:

Now let's expand the logical volume with the following command to increase the disk space that our system is using.

The code is as follows:

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

Once the message of increasing success is returned, you can run the following command to expand your logical volume size.

The code is as follows:

# xfs_growfs / dev/mapper/centos-root

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

7. Expand the root partition by adding new disks without rebooting the system:

This is the second method, which uses a very simple command to increase the space of logical volumes on CentOS 7 systems.

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

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

Then go to the server and repeat the following command to scan your disk device so that the new disk is visible in the system.

The code is as follows:

# 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:

The code is as follows:

# 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.

The code is as follows:

# pvcreate / dev/sdb

# vgextend centos / dev/sdb

# vgdisplay

Now expand the logical volume based on the space size of this disk, and then add it to the root partition.

The code is as follows:

# lvextend-L + 20g / dev/mapper/centos-root

# xfs_growfs / dev/mapper/centos-root

# df-h

Conclusion:

The process of managing disk partitions on Linux CentOS 7 systems is very simple, and you can use the procedures described in this article to expand the disk space of any of your logical volumes. You don't need to restart the server on the production line, just simply rescan the SCSI device and extend the LVM (logical volume management) you want. We hope this article will be useful to you. Please feel free to make useful comments and suggestions.

After reading the above, do you have any further understanding of how to add a hard drive to CentOS on VPS without rebooting the server? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report