Vmware Linux Virtual Machine disk expansion method

Source: Internet
Author: User

My Linux version is ubuntu12.04 32bit. Today, when downloading the Android source code, I found that the disk space that I initially allocated to this virtual machine was not enough (only 20G). So you need to expand the disk. on the internet roughly searched, there are two main solutions: one, another disk, two, to the original disk expansion. I chose the second option.

1. Shut down the virtual machine. Go to the Settings screen where you want to expand the virtual machine, select the disk in the Device box, select Utilities, and then choose the expansion option. In the pop-up box, enter the size of the disk you want to enlarge. I fill in the 60G.

PS: One thing to note here: If you've ever taken a snapshot of a virtual machine, you have to delete all the snapshots to scale up this way. Delete Snapshot method: Snapshot management of Virtual machine and snapshot, select Snapshot Click Delete.

2. Do we need to expand our virtual machines by just the above steps? Of course not! Due to the features of the Linux system, we also need to manually set up partitions, mount devices, etc. for the newly allocated disk space. The following is a detailed introduction to the configuration process.

① log into the system as root (or enter sudo su after entering the system, switch to root mode) and enter the following command:

#fdisk-L

You can see the partition, mount, and other information of your own disk.

We can see that the list shown has an id = 5 system = extern partition/dev/sda2.

This is the disk space we just expanded.

There is also an id = Swap/solaris partition, which is the system swap partition/DEV/SDA5.

and the id = System = Linux partition,/DEV/SDA1, which is the disk partition used before the expansion.

② The situation I encountered was not the same as the others, because only 1024block of space was reserved for me between the system swap partition (/DEV/SDA5) of my virtual machine and the system's original disk partition (/DEV/SDA1) (How do I see it?). In the output of the fdisk-l command there is a start and end identifier, start indicates the start block number of the partition, end indicates the end block number, and a little analysis is calculated. But my new disk is far more than that! So I have to delete this swap partition so that I can do it later.

③ How do I delete a swap partition?

# FDISK/DEV/SDA

#m (lists Help for Linux disk tools)

#d (indicates that you want to delete the partition)

#Partition number (1-4): 5 (because the SDA of my swap partition is 5, which means that I want to delete the 5th primary partition)

The swap partition is deleted here, and you can enter the command p to see the result of the change.

#w (means save the changes, this step is necessary!) )

After ④ delete the swap partition, we can change the Exern partition to be the primary partition.

#fdisk/DEV/SDA

#n (add partition)

#p (Increase primary partition)

Set the partition number #回车即可

Set partition start block number #回车即可

Set partition end block number #默认值-900000 (It is important here that we reserve 900,000 block of space to reestablish the swap partition)

#w (Save)

By doing this, we've built the primary partition/dev/sda2.

⑤ now re-create the swap partition and finish formatting and mounting

First, create a third primary partition as a fourth step

Then change the primary partition to swap partition

#fdisk/DEV/SDA

#n

#t (Modify system ID)

#3 (indicates the SDA number of this primary partition to be changed is 3)

#82 (change to swap ID number)

#p (Print the modified partition result)

#w (Save)

You can restart the system here.

After the reboot, the following command is also executed with root privileges

Formatting:

#mkswap/dev/sda3

Start Viewing and loading

#free (view)

#swapon/dev/sda3

#free

The creation of the ⑥ partition is complete, and the next thing to do is to mount the newly created primary partition 2 to the file system.

First format primary partition 2

#mkfs Ext4/dev/sda2 (because the Ubuntu12.04 file system is EXT4, so here the parameter is EXT4, if you do not know your file system version, you can view the/DEV/SDA1 type value by command mount, the Value is the file system version)

Then create a directory in your user's root directory

Switch to normal user mode

$mkdir/home/(your username)/externdisk (this directory is the "root" of our new disk space, it is important to note that this is not a command executed as root!) )

Switch to root mode

#mount/dev/sda2 /home/(your user name)/externdisk (mount partition to this directory)

#df-H (view mounted partition condition)

⑦ setting up auto mount on boot

Modify the/etc/fstab partition table file

#vim/etc/fstab

At the end of the file add/dev/sda2 /home/(your user name)/externdisk ext4 defaults 0 0

Then save the exit and reboot!

Now the disk expansion of the virtual machine has been completed! If you have a large file, move it to this /home/(your user name)/externdisk directory!

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.