VMware Virtual machine disk expansion for embedded development

Source: Internet
Author: User
Tags uuid
Reference DocumentsVMware extended disk space under Ubuntu

Tips:

The application scope of this document is Vmware+ubuntu development environment

In embedded development, it is common to use the Ubuntu virtual machine installed in VMware for software development, in order to improve the disk performance of virtual machines, it is recommended to use a pre-allocated disk when creating a virtual machine, as shown in the following figure:

As shown in the figure above, if you allocate all disk space immediately, you can improve performance, but the problem is that when you create a virtual machine with insufficient disk space, the expansion is cumbersome. The following is a detailed analysis of how disk expansion is done in the case of pre-allocated disks.

First allocate new space based on pre-allocated disk space (example 85GB expands 90GB)

Click the Extend button, after a long wait for the new disk allocation request work has been completed, but as the interface prompts "expansion operation only increase the size of the disk, partition and file system size is not affected" also need to enter into the Ubuntu system file system partition size adjustment

tip: All Ubuntu partition related operations need to be done under root user

View existing disk related information:fdisk-l

It is recommended to log the current disk condition for redistribution after partitioning reference

root:~ #fdisk
-L disk/dev/sda:90 GiB, 96636764160 bytes, 188743680 sectors
units:sectors of 1 * mb = bytes< C2/>sector size (logical/physical): bytes/512 bytes
I/o size (minimum/optimal): bytes/512 bytes
Diskla Bel type:dos
Disk identifier:0x6a1fff92

Device     Boot     Start       End   sectors Size Id type
/ DEV/SDA1  *         2048 174065663 174063616  83G, Linux
/dev/sda2       174067710   178255871 4188162   2G  5 Extended
/dev/sda5       174067712 178255871   4188160   2G. Linux Swap/solaris

The information from the FDISK command shows that the/DEV/SDA space has been extended to 90GiB, but the/dev/sda1,/dev/sda2, and/dev/sda5 partitions under Ubuntu are still distributed according to the 85GiB before expansion, so the idea now is Delete the existing partition first and then recreate the partition based on the new disk space

Turn off the Swap partition feature

root@ubuntu:# swapoff-a

Make sure the swap partition is closed: Swap lines are all 0

root@ubuntu:# free-m        Total used        free      shared  buff/cache   available
Mem:           1982         630         467         885        1110
Swap:             0           0           0

Delete all partitions using the FDISK command

root@ubuntu:~# FDISK/DEV/SDA

Welcome to fdisk (Util-linux 2.27.1).
Changes'll remain in memory only, until the decide to write them.
Be careful before using the Write command.


Command (M for help): D
Partition number (1,2,5, default 5): 1

Partition 1 have been deleted.

Command (M for help): D
Partition number (2,5, default 5): 2

Partition 2 have been deleted.

Command (M for help): P
disk/dev/sda:90 GiB, 96636764160 bytes, 188743680 sectors
Units:sectors of 1 * 512 = Bytes
Sector size (logical/physical): bytes/512 bytes
I/o size (minimum/optimal): bytes/512 byte s
disklabel type:dos
Disk identifier:0x6a1fff92

Re-create partitions

Command (M for help): N Partition type P primary (0 primary, 0 extended, 4 free) e-extended (container for logic Al partitions) Select (default p): Using Default Response P. Partition Number (1-4, default 1): First sector (2048-1887  43679, default 2048): Last sector, +sectors or +size{k,m,g,t,p} (2048-188743679, default 188743679): 184555520 Created A

New partition 1 of type ' Linux ' and of size ". Command (M for help): N Partition type P Primary (1 primary, 0 extended, 3 free) e-extended (container for logic Al partitions) Select (default p): Using Default Response P. Partition Number (2-4, default 2): First sector (184555521 -188743679, default 184557568): Last sector, +sectors or +size{k,m,g,t,p} (184557568-188743679, default 188743679): Cre

Ated a new partition 2 of type ' Linux ' and of size 2 GiB.
Command (M for help): P disk/dev/sda:90 GiB, 96636764160 bytes, 188743680 sectors units:sectors of 1 * mb = bytes Sector size (logical/physical): 5bytes/512 bytes I/o size (minimum/optimal): bytes/512 bytes Disklabel type:dos Disk identifier:0x6a1fff92 De Vice Boot Start End sectors Size Id type/dev/sda1 2048 184555520 184553473 88G linux/dev/ Sda2 184557568 188743679 4186112 2G Linux

Here sda1 end needs to be calculated, calculated as/DEV/SDA total sector number-swap partition occupied sector number

/DEV/SDA Total sector number can be obtained from previously saved partition information as 188743680
Swap partition occupies sector number of 4188160
new SDA1 partition End position is 188743680-4188160 = 184555520

Update the ID of the SDA2 partition

Command (M for help): T
Partition number (on, default 2): 
Partition type (type L to list all types): A-Z-

Chang Ed type of partition ' Linux ' to ' Linux Swap/solaris '.

Command (M for help): P
disk/dev/sda:90 GiB, 96636764160 bytes, 188743680 sectors
Units:sectors of 1 * 512 = 51 2 bytes
Sector size (logical/physical): bytes/512 bytes
I/o size (minimum/optimal): bytes/512 bytes
  disklabel type:dos
Disk identifier:0x6a1fff92

Device     Boot     Start       End   Sectors Size Id Type
/dev/sda1            2048 184555520 184553473  88G. Linux
/dev/sda2       184557568 188743679   4186112   2G Swap/solaris Linux

Save partition information

Command (M for help): W The
partition table has been altered.
Calling IOCTL () to re-read partition table.
Re-reading the partition table failed.: Device or resource busy the kernel still uses the old

table. The new table would be used on the next reboot or after you run 
Partprobe (8) or KPARTX (8).

Restart Ubuntu virtual Machine

Update the UUID of the swap partition, otherwise the Swap partition feature will not work properly

root@ubuntu:~# awk '/swap/{print '} '/etc/fstab
#
uuid=d3dc807d-3d2b-477a-a77b-03b783b0317e
root@xiaoyalun:~# DD If=/dev/zero of=/dev/sda2
dd:writing to '/dev/sda2 ': No space left on device
4186113+0 Recor DS in
4186112+0 records
out 2143289344 bytes (2.1 GB, 2.0 GiB) copied, 68.846 s, 31.1 MB/s
root@ubuntu:~# m Kswap-u d3dc807d-3d2b-477a-a77b-03b783b0317e/dev/sda2
Setting up swapspace version 1, size = 2 GiB (2143285248 byte s)
no label, uuid=d3dc807d-3d2b-477a-a77b-03b783b0317e

The first is to query from/etc/fstab to the new UUID and create a new swap partition with the Mkswap command

Resizing a partition

root@ubuntu:~# resize2fs/dev/sda1
resize2fs 1.42.13 (17-may-2015)
Filesystem at/dev/sda1 was mounted on/; On-li NE resizing required
old_desc_blocks = 6, New_desc_blocks = 6 The
filesystem on/dev/sda1 is now 23069184 (4k) Blo Cks Long.

The virtual machine disk expansion is now complete

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.