Expand CentOS to the root partition in VirtualBox

Source: Internet
Author: User
For current network developers, a good partner is the combination of Win7 & amp; 43; VirtualBox & amp; 43; CentOS, which can leverage the powerful network service functions of Linux, it can also effectively isolate various services from slowing down the system and affect the system operation. for new users, it can reduce the number of errors caused by configuration errors.

For current network developers, a good partner is a combination of Win7 + VirtualBox + CentOS, which can leverage the powerful network service functions of Linux and effectively isolate slow systems of various services, the impact on the system operation can reduce the loss caused by configuration errors for new users. The most important thing is to facilitate the migration. different System reinstallation requires a lot of trouble.

However, if we find that the system storage is not enough when installing and using the virtual machine, we can use VirtualBox version 4 or later to conveniently and quickly scale up.

In VirtualBox, virtual hard disks include VMDK, VDI, VHD, and HDD,

VMDK is developed and used by VMware and is also supported by SUN's xVM, QEMU, SUSE Studio, and. NET DiscUtils, so it has better compatibility.

VDI is the processing format of Virtual Box, and Virtual Box supports Windows and Linux, so it is better for users who use VirtualBox.

VHD is a proprietary processing format for Windows, and HDD is Apple's proprietary processing format. Therefore, it does not support cross-platform processing and is generally not considered.

Here we will take how to resize VMDK and VDI as an example. for other formats, convert them to Baidu Google.

VDI

The simplest command for VDI resizing is as follows:

VBoxManage modifyhd xxxx. vdi -- resize 16000 // xxxx. vdi is generally stored in VirtualBox VMs.

VMDK

If it is a VMDK, it must be converted to VDI before resizing.

VBoxManage clonehd "xxxx. vmdk" "cloned. vdi" -- format vdiVBoxManage modifyhd "cloned. vdi" -- resize 16000 // The unit here is M
If you want to switch back to VMDK, you can directly use the vdi format.
VBoxManage clonehd "cloned.vdi" "resized.vmdk" --format vmdk
A burst of 0%... 10%... 20%... 30%... 40%... 50%... 60%... 70%... 80%... 90%... after 100%

You can see the cloned file through the VBoxManage list hdds.

The following figure shows how to choose "Open Virtual Machine"> "select a system"> "right-click"> "set"> "storage"> "controller SATA"> "add virtual hard disk"> "clone file.

Open the system on the virtual machine and run df-h to check whether the root directory is the same. we can use lVM to expand partitions.

LVM (Logic Volume Manager) logical Volume management, like the default partition management method of the RedHat system, is built on the hard disk partition, the Logic layer under the file system, it is used to solve the problem of incorrect evaluation and partition capacity allocation during initial partitioning, resulting in insufficient system partitions.

Think of a word from a great god. any problems in the computer can be solved by adding an intermediate layer.

So extending partitions is just a few lines of code.

Sudo fdisk-l to view the current system partition. You can view the created partition, sda1 sda2, or ls/dev. If there is a second hard disk, you will see sdb,

I only have one, and have already divided sda1 and sda2.

Create the extended space and create a new partition

Sudo mkfs. ext4/dev/sda4 // format the partition to ext4

Perform the following LVM operations:

Sudo vgdisplay // Check the volume group name. here is the VolGroup. remember to use

 

Sudo pvcreate/dev/sda4 // create a new physical volume
Sudo vgextend VolGroup/dev/sda4 // extend to volume Group

/Dev/VolGroup/lv_root is the root partition and the partition to be extended.

Sudo lvextend-L + 6.96/dev/VolGroup/lv_root
Sudo lvextend/dev/VolGroup/lv_root/dev/sda4
// Both commands can be used, but the following commands do not need to be computed. the commands mean to extend to logical partitions.

Last
Sudo resize2fs/dev/VolGroup/lv_root // refresh the capacity of the logical partition sudo df-h // you will find that the root partition is doubled...
Sudo reboot // restart the system. everything is OK. My VM is revived again...

PS: add some basic LVM knowledge:

In LVM, PVS, VG, and LV indicate physical volumes, Volume groups, and logical volumes respectively.

The procedure is to create the entire partition and hard disk as a physical volume through pvcreate -- create a volume group volgroup for home vgcreate, add the physical volume of pvcreate to -- and then use lvcreate to create a logical volume of 20 GB in the volume group volgroup --> use mkfs to format it as the expected format, such as ext4 --> mount the file through mount, form a file system that we can access.

If you want to scale out, use lvextend-L + xxG/dev/VolGroup/zzz to increase the capacity.

If you want to compress ---- unmount the logical volume -- e2fsck detects the remaining capacity -- resizef2fs/dev/VolGroup/zzz xxM reduces xxM -- lvreduce-L xxM reduces the logical volume by xxM

The "lvremove vgremove pvremove" command also requires umount to modify the mounting information in/etc/fstab at the same time; otherwise, it cannot be started.

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.