An example of Linux Virtual Machine disk and partition Expansion

Source: Internet
Author: User

When deploying a Linux virtual machine for a customer, I usually create a separate partition to store all the data of the customer and name it data. The default size of/data partitions is 35 GB. As time goes on, some customers may need to expand/data partitions. The following are my implementation steps on ESX4.0:

Note: In the production environment, you must back up the data before proceeding!

1) Turn off the Linux Virtual Machine and run the vmkfstools command to expand the vmdk file. The original size is 50 GB and is now 65 GB.

Vmkfstools-X 65G CentOS53.vmdk

2) to enable the Linux virtual machine, run the following command to view the new available space.

[Root @ CentOS53 ~] # Parted

GNU Parted 1.8.1

Using/dev/sda

Welcome to GNU Parted! Type 'help' to view a list of commands.

(Parted) print free

Model: VMware Virtual disk (scsi)

Disk/dev/sda: 69.8 GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number Start End SizeType File system Flags

1 32.3kB 107 MB 107 MB primary ext3 boot

2 107 MB 4401 MB 4294 MB primary ext3

3 4401 MB 6547 MB 2147 MB primary linux-swap

4 6547 MB 53.7 GB 47.1 GB extended

5 6547 MB 8694 MB 2147 MB logical ext3

6 8694 MB 10.8 GB 2147 MB logical ext3

7 10.8 GB 11.9 GB 1077 MB logical ext3

8 11.9 GB 13.0 GB 1077 MB logical ext3

9 13.0 GB 53.7 GB 40.7 GB logical ext3

53.7 GB 69.8 GB 16.1 GBFree Space

3) run disk/dev/sda and input P to view the partition result as follows, and record it (/dev/sda9 is loaded on/data Partition ). It can be seen that there are a total of 8485 cylinder, but the last partition only ends at 6527. This indicates that there is still hard disk space.

Disk/dev/sda: 69.7 GB, 69793218560 bytes

255 heads, 63 sectors/track, 8485 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sda1*1 13 104391 83 Linux

/Dev/sda2 14 535 4192965 83 Linux

/Dev/sda3 536 796 2096482 + 82 Linux swap/Solaris

/Dev/sda4 797652746034257 + 5 Extended

/Dev/sda5 7971057 2096451 83 Linux

/Dev/sda610581318 2096451 83 Linux

/Dev/sda713191449 1052226 83 Linux

/Dev/sda814501580 1052226 83 Linux

/Dev/sda915816527347000046 83 Linux

4) Input d to delete the extended partition/dev/sda4, so that all the logical partitions will disappear from the partition table ).

5) Input n to create a new extended partition, and create the original/dev/sda9 except) all logical partitions and keep the original starting and ending cylinder address unchanged. The start address of/dev/sda9 remains unchanged, and the end address is changed to 8485. The new partition table is as follows. Enter w to save the settings.

Command (m for help): p

Disk/dev/sda: 69.7 GB, 69793218560 bytes

255 heads, 63 sectors/track, 8485 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sda1*1 13 104391 83 Linux

/Dev/sda2 14 535 4192965 83 Linux

/Dev/sda3 536 796 2096482 + 82 Linux swap/Solaris

/Dev/sda4 797848561761892 + 5 Extended

/Dev/sda5 7971057 2096451 83 Linux

/Dev/sda610581318 2096451 83 Linux

/Dev/sda713191449 1052226 83 Linux

/Dev/sda814501580 1052226 83 Linux

/Dev/sda91581848555464381 83 Linux

6) view the changed partition size. So far, the/data Partition size has not changed.

[Root @ CentOS53 ~] # Df-h

FilesystemSize Used Avail Use % Mounted on

/Dev/sda8 996 M 235 M 710 M 25%/

/Dev/sda9 37G 177 M 35G 1%/data

/Dev/sda7 996 M 34 M 911 M 4%/home

/Dev/sda6 2.0G 76 M 1.8G 5%/var

/Dev/sda2 3.9G 1.4G 2.4G 38%/usr

/Dev/sda5 2.0G 36 M 1.9G 2%/usr/local

/Dev/sda1 99 M 17 M 78 M 18%/boot

Tmpfs 506 M 0 506 M 0%/dev/shm

7) run the resize2fs/dev/sda9 extended/data Partition. Umount is not required in 2.6.X kernel)

[Root @ CentOS53 ~] # Resize2fs/dev/sda9

Resize2fs 1.39 (29-May-2006)

Filesystem at/dev/sda9 is mounted on/apps; on-line resizing required

Ming an on-line resize of/dev/sda9 to 13866095 (4 k) blocks.

The filesystem on/dev/sda9 is now 13866095 blocks long.

8) view the partition size again. Success, oh yeah!

[Root @ CentOS53 ~] # Df-h

FilesystemSize Used Avail Use % Mounted on

/Dev/sda8 996 M 235 M 710 M 25%/

/Dev/sda9 52G 180 M 49G 1%/data

/Dev/sda7 996 M 34 M 911 M 4%/home

/Dev/sda6 2.0G 76 M 1.8G 5%/var

/Dev/sda2 3.9G 1.4G 2.4G 38%/usr

/Dev/sda5 2.0G 36 M 1.9G 2%/usr/local

/Dev/sda1 99 M 17 M 78 M 18%/boot

Tmpfs 506 M 0 506 M 0%/dev/shm

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.