Adding Disk Space to an Ubuntu VMware Virtual Machine without LVM

Issue

A default install of Ubuntu may have created three partitions on a single disk:

- A root partition
- An extended partition
- A swap partition in the extended partition

This prevents the root volume from being expanded, even if additional space is added to the vDisk. The swap partition must be moved to a separate vDisk to allow the root partition to be expanded.

For example:

# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a783

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    80353279    40175616   83  Linux
/dev/sda2        80355326    83884031     1764353    5  Extended
/dev/sda5        80355328    83884031     1764352   82  Linux swap / Solaris

# swapon --summary
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       1764348 164420  -1

Resolution

1. Attach an additional vDisk

From vSphere:
- Select the Virtual Machine
- Click Edit
- Click Add hard disk | New hard disk
- Set the size to 2GB
- Click Save

Force a scan of the SCSI controller:

# echo "- - -" > /sys/class/scsi_host/host2/scan

# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a783

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    80353279    40175616   83  Linux
/dev/sda2        80355326    83884031     1764353    5  Extended
/dev/sda5        80355328    83884031     1764352   82  Linux swap / Solaris

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table


2. Create the swap partition

# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb89058e1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb89058e1

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
Using default value 4194303

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb89058e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4194303     2096128   82  Linux swap / Solaris

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


3. Turn on new swap partition

# mkswap /dev/sdb1
Setting up swapspace version 1, size = 2096124 KiB
no label, UUID=b2b2b8ef-35fa-4e3a-a810-39d422f6d276

# swapon /dev/sdb1

# swapon --summary
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       1764348 162924  -1
/dev/sdb1                               partition       2096124 0       -2


4. Edit /etc/fstab to mount swap on boot

The UUID was shown when the swap was created above, or can be listed as below.

# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Oct 10 16:06 b2b2b8ef-35fa-4e3a-a810-39d422f6d276 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Oct 10 16:06 e9dd5560-b769-4716-a585-a9329a620316 -> ../../sda1

# cat /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=e9dd5560-b769-4716-a585-a9329a620316 /               ext4    errors=remount-ro,user_xattr 0       1
# swap was on /dev/sda5 during installation
UUID=6be6d4c2-5b6a-4671-916e-72c5ee717115 none            swap    sw              0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

# vi /etc/fstab

# cat /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=e9dd5560-b769-4716-a585-a9329a620316 /               ext4    errors=remount-ro,user_xattr 0       1
# swap was on /dev/sda5 during installation
UUID=b2b2b8ef-35fa-4e3a-a810-39d422f6d276 none            swap    sw              0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0


5. Turn off old swap partition

# swapoff /dev/sda5

# swapon --summary
Filename                                Type            Size    Used    Priority
/dev/sdb1                               partition       2096124 0       -1


6. Delete old swap and extended partitions

# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a783

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    80353279    40175616   83  Linux
/dev/sda2        80355326    83884031     1764353    5  Extended
/dev/sda5        80355328    83884031     1764352   82  Linux swap / Solaris

Command (m for help): d
Partition number (1-5): 5

Command (m for help): d
Partition number (1-5): 2

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.


7. Add additional space to the vDisk

From vSphere:
- Select the Virtual Machine
- Click Edit
- Increase the size of Hard disk 1
- Click Save

8. Scan for additional space

# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a783

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    80353279    40175616   83  Linux

Disk /dev/sdb: 2147 MB, 2147483648 bytes
22 heads, 16 sectors/track, 11915 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb89058e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4194303     2096128   82  Linux swap / Solaris

# ls -l /sys/class/scsi_device
total 0
lrwxrwxrwx 1 root root 0 Oct 10 12:46 1:0:0:0 -> ../../devices/pci0000:00/0000:00:07.1/ata2/host1/target1:0:0/1:0:0:0/scsi_device/1:0:0:0
lrwxrwxrwx 1 root root 0 Oct 10 12:46 2:0:0:0 -> ../../devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/scsi_device/2:0:0:0
lrwxrwxrwx 1 root root 0 Oct 10 15:58 2:0:1:0 -> ../../devices/pci0000:00/0000:00:10.0/host2/target2:0:1/2:0:1:0/scsi_device/2:0:1:0

# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan

# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a783

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    80353279    40175616   83  Linux

Disk /dev/sdb: 2147 MB, 2147483648 bytes
22 heads, 16 sectors/track, 11915 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb89058e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4194303     2096128   82  Linux swap / Solaris


9. Delete and recreate root partition
Ensure the Start sector is the same for the old and new partitions.

# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a783

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    80353279    40175616   83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599

Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a783

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   104857599    52427776   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

# partprobe


10. Resize the root file system

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G   12K  2.0G   1% /dev
tmpfs           404M  992K  403M   1% /run
/dev/sda1        38G   26G   10G  72% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            2.0G   76K  2.0G   1% /run/shm
none            100M   32K  100M   1% /run/user

# resize2fs /dev/sda1
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
The filesystem on /dev/sda1 is now 13106944 blocks long.

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G   12K  2.0G   1% /dev
tmpfs           404M  992K  403M   1% /run
/dev/sda1        50G   26G   22G  55% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            2.0G   76K  2.0G   1% /run/shm
none            100M   32K  100M   1% /run/user


11. Reboot at convenient time

A disk check may happen on boot

# cat /var/log/upstart/mountall.log

fsck from util-linux 2.20.1
/dev/sda1 has gone 222 days without being checked, check forced.
/dev/sda1: 454986/3276800 files (0.4% non-contiguous), 6969192/13106944 blocks


12. Check Partitions

# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
22 heads, 22 sectors/track, 216647 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a783

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   104857599    52427776   83  Linux

Disk /dev/sdb: 2147 MB, 2147483648 bytes
22 heads, 16 sectors/track, 11915 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb89058e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4194303     2096128   82  Linux swap / Solaris

# swapon --summary
Filename                                Type            Size    Used    Priority
/dev/sdb1                               partition       2096124 0       -1


Products

Ubuntu Desktop 14.04.4 LTS

Created: 10th October 2018
Updated: 10th October 2018


© 2005-2018 Jamie Morrison