Centos 7 Add New disk

Source: Internet
Author: User
Tags virtual environment

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.

    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

Use the following command to check the SCSI device name and then rescan the SCSI bus.

    1. # ls /sys/class/scsi_device/
    2. # echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
    3. # 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.

  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 new empty GPT partition table
  10. G create an IRIX (SGI) partition table
  11. l list known partition types
  12. m print this menu
  13. n add a new partition
  14. o create a new empty DOS partition table
  15. p print the partition table
  16. q quit without saving changes
  17. s create a new empty Sun 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, 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:

    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: Device or resource busy.
    5. The kernel still uses the old table. The new table will be used at
    6. 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.

    1. # partprobe
    2. # 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:

    1. # pvdisplay
    2. # 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.

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

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

    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 name of your SCSI device:

    1. # ls /sys/class/scsi_device/
    2. # echo 1 > /sys/class/scsi_device/1\:0\:0\:0/device/rescan
    3. # echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
    4. # echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
    5. # 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.

    1. # pvcreate /dev/sdb
    2. # vgextend centos /dev/sdb
    3. # 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.

    1. # lvextend -L +20G /dev/mapper/centos-root
    2. # xfs_growfs /dev/mapper/centos-root
    3. # 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

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.