The GNS3 VM uses a virtual disk with a size of about 100 GB for storing disk images and projects. While this is sufficient for most situations, you may run out of disk space, when using the GNS3 VM intensively.

Here an example:

gns3@gns3vm:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            997M  4.0K  997M   1% /dev
tmpfs           201M  760K  200M   1% /run
/dev/sda1        18G  849M   16G   6% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none           1001M     0 1001M   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sdb1        96G   80G   12G  87% /opt

The second disk (/dev/sdb) is used for storing disk images and projects in the /opt directory. In this example 80 GB out of 96 GB are used. Furthermore Linux reserves another 5% of the disk space, so 87% of the disk are in use.

Expanding the disk of a VM is done in three steps:

  • Expand the disk image in the hypervisor
  • Expand the partition within the virtual disk
  • Expand the file system within the partition

Lets have a detailed look at those steps.

0. Make a Backup of the GNS3 VM

Fiddling with disk images is a risky operation. Even though the procedure is well tested, I strongly recommend to make a backup of the GNS3 VM.

For that locate the directory, where the VM is stored. Normally that’s in the Home directory -> Documents -> Virtual Machines folder. If you have difficulties locating it, open the VM settings of the GNS3 VM and select a hard disk. The path to the disk file is shown, use the Explorer to navigate to the Virtual Machines folder.

Stop the GNS3 GUI and the VM, then copy the whole GNS3 VM directory to a safe place.

1. Expand the Disk Image in the Hypervisor

Ensure, that the GNS3 GUI and the VM are stopped. Open the VM settings, select the second hard disk and expand it’s size.

Here the settings for VMware Player 14:

VM Settings

Expand Disk Capacity

2. Expand the Partition and File System

Start the GNS3 VM, but not the GUI. In the menu select “Shell” to open a console window.

2.1 Become root and stop the running services

gns3@gns3vm:~$ sudo -s
root@gns3vm:~# service gns3 stop
gns3 stop/waiting
root@gns3vm:~# service docker stop
docker stop/waiting
root@gns3vm:~#

2.2 Expand Partition

First unmount the second hard disk, then use fdisk to expand the partition. As fdisk doesn’t have an option to modify a partition, we have to delete it and re-create it. It’s extremely important, that the recreated partition starts on the same sector as previously. But as the default values are fine, that’s easy.

root@gns3vm:~# umount /dev/sdb1
root@gns3vm:~# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 429.5 GB, 429496729600 bytes
54 heads, 41 sectors/track, 378889 cylinders, total 838860800 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: 0x42e944ee

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   204799999   102398976   83  Linux

Command (m for help): d 1
Selected partition 1

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

Command (m for help): p

Disk /dev/sdb: 429.5 GB, 429496729600 bytes
54 heads, 41 sectors/track, 378889 cylinders, total 838860800 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: 0x42e944ee

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   838860799   419429376   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
root@gns3vm:~#

2.3 Expand File System within the Partition

Check the file system structure, expand the file system and check the structure again.

root@gns3vm:~# e2fsck -f /dev/sdb1
e2fsck 1.42.9 (4-Feb-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 17/6406144 files (0.0% non-contiguous), 21186104/25599744 blocks
root@gns3vm:~#
root@gns3vm:~# resize2fs /dev/sdb1
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/sdb1 to 104857344 (4k) blocks.
The filesystem on /dev/sdb1 is now 104857344 blocks long.

root@gns3vm:~#
root@gns3vm:~# e2fsck -f /dev/sdb1
e2fsck 1.42.9 (4-Feb-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 17/26214400 files (0.0% non-contiguous), 22432031/104857344 blocks
root@gns3vm:~#

2.4 Check the result

Mount the second hard disk and check the disk utilization. If everything looks fine, reboot the VM to restart all services.

root@gns3vm:~# mount /opt
root@gns3vm:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            997M  4.0K  997M   1% /dev
tmpfs           201M  760K  200M   1% /run
/dev/sda1        18G  849M   16G   6% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none           1001M     0 1001M   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sdb1       394G   80G  295G  22% /opt
root@gns3vm:~#
root@gns3vm:~#
root@gns3vm:~# reboot