How to mount and expand multiple hard disks (non-directory mounting) in the centos system of an Alibaba Cloud host

Source: Internet
Author: User
Tags extend centos

The default hard disk of the newly purchased Alibaba Cloud host is not mounted. If it is attached to the default hard disk that is not mounted, you can directly look at the tutorial provided by Alibaba Cloud. However, I felt that the hard disk was not enough. Later I bought another hard disk and didn't want to mount it to a directory separately. I wanted to expand the existing hard disk, or if you want to expand the hard disk after mounting the only hard disk, the tutorial provided by Alibaba Cloud will not work.

After a long time, it was finally mounted successfully. However, we do not recommend that you directly toss it under the system disk! Otherwise you will regret it!

1. The Alibaba Cloud centos 6 series does not seem to have LVM2 installed. You need to install LVM2 first, search for the Internet, and install LVM2 on your own. LVM2 has been installed on 5.4 32-bit devices, so this step is not required.

2. if you have mounted a hard disk using the tutorial provided by Alibaba Cloud, you can back up the data in the disk (data security, don't forget this step, because you want to format it) and Unbind It.

# Umount-
Edit the startup item
# Vi/dev/fstab
Remove the startup item added to/dev/xvdb1/mnt ext3 defaults 0 0.
Then save
Then, use fdisk to delete the partition. Assume that you are bound to/dev/xvdb1.
# Fdisk/dev/xvdb
# D
# Wq
Then, use fdisk-l.
Check whether xvdb1 has been unbound.

3. If this is your first mount, or you do not want to use the method officially provided by Alibaba Cloud to mount it, skip the above process.

# Fdisk-l
Suppose you see two disks are not mounted yet.
/Dev/xvdb
/Dev/xvdc
Process/dev/xvdb first and input it in the following order
# Fdisk/dev/xvdb
# N
# P
#1
# T
# 8e
# Wq
Then proceed with/dev/xvdc in the same way
# Fdisk/dev/xvdc
# N
# P
#1
# T
# 8e
# Wq
If you don't have a second one, you don't have to do it.

4. Use fdisk-l to check if the/dev/xvdb1/dev/xvdc1 partitions have been created.

The physical volumes created for the two partitions are as follows:
# Pvcreate/dev/xvdb1
# Pvcreate/dev/xvdc1
If you do not have/dev/xvdc1, but want to increase the capacity of xvdb1 in the future, ignore the Operation steps on xvdc1 automatically.

5. Create a volume group.

# Vgcreate mygroup/dev/xvdb1
Mygroup is the name of the volume group.

6. Activate the volume Group

# Vgchange-ay mygroup
Do you still remember that mygroup is your own volume group name, and activating the volume group is too lazy to restart VPS?

7. Extend the volume Group

Vgextend mygroup/dev/xvdc1
If not, ignore this step.

8. Create a logical volume

# Vgdisplay mygroup | grep "Total PE"
Use the preceding command to obtain
Total PE 15357
15357 is the logical number of the volume group.
# Lvcreate-l15357 mygroup-n wwwroot
Wwwroot is the name of the logical volume.
8. Format the logical volume
# "Mkfs. ext3/dev/mygroup/wwwroot"

9. Create a directory you want to bind, such as/www (in other words, WDCP uses/www by default)

Mkdir/www

10. Add a startup item

Echo '/dev/mygroup/wwwroot/www ext3 defaults 0 0'>/etc/fstab

11. Mount

Mount-

12. Finally, use df-hal to check whether the operation is successful?
 
 
With this method, it is easy if you want to expand and add this partition again later.
If you use fdisk-l to see that/dev/xvdd is your new hard disk, you need to extend it to the previous partition.
# Fdisk/dev/xvdd
# N
# P
#1
# T
# 8e
# Wq
# Reboot restart
GET/dev/xvdd1, and then
#/Pvcreate/dev/xvdd1
# Vgextend mygroup/dev/xvdd1
# Vgdisplay mygroup | grep "Total PE"
This command returns the Total number of PES Total PE 10240
# Lvresize-l10240/dev/mygroup/wwwroot
# Resize2fs/dev/mygroup/wwwroot
Have a cup of tea and run df-hal to check whether the operation is successful.
 
In other words, Alibaba Cloud's centos system disk does not use LVM2 partition, so it cannot be expanded to/dev/hda1. If your website is promising, do not specify the database file to the system disk, if you are a promising image site, do not place the site on the system disk, or use the official mounting method provided by Alibaba Cloud. Otherwise, you will not be able to increase the capacity without any gaps.

However, I once saw a solution from someone else on a website, namely cloning the system disk into two external disks and changing the startup mode, the boot files of the original system and the replication system must be modified (both changed to the secondary disk), restarted, and used as the primary system. Then, LVM2 is used to partition the original system disk, after completing the configuration, clone the system in the secondary disk to the original system disk and change the startup files of the two systems (both changed to the original disk). After the restart, the system disk becomes the LVM2 partition, you can expand and add capacity, and then you can delete the system files in the secondary disk.
I forgot where I saw it. After two failed attempts, the restart of Alibaba Cloud's reinstallation system was too slow and I didn't want to worry about it.

In general, Alibaba Cloud's host is still good. Don't consider the backup problem on your own, and the operation is stable, that is, the bandwidth is a little expensive.

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.