I'm running docker containers on my machine which puts it all in /var/. DF shows that /var/ is 6.9G and no free space. The Linux system is running under VMWare and I've given the server extra 100 GB's in VMWare console. How do I increase "/var" in the linux vm without restarting the the server?

root@TB-IOT02:/var# df -a | grep sda
/dev/sda1       19276020 4530700  13743080  25% /
/dev/sda5        6722700 6706316         0 100% /var
/dev/sda7        1182728    3748   1100852   1% /tmp
/dev/sda8       74238884   65640  70359052   1% /home

root@TB-IOT02:~# fdisk --list
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0b21c5c6

Device     Boot    Start       End   Sectors  Size Id Type
/dev/sda1  *        2048  39436287  39434240 18.8G 83 Linux
/dev/sda2       39438334 209713151 170274818 81.2G  5 Extended
/dev/sda5       39438336  53231615  13793280  6.6G 83 Linux
/dev/sda6       53233664  55326719   2093056 1022M 82 Linux swap / Solaris
/dev/sda7       55328768  57798655   2469888  1.2G 83 Linux
/dev/sda8       57800704 209713151 151912448 72.4G 83 Linux



Since the server is using traditional partitioning scheme, it is not possible to expand /var partition without restarting the server.

If I were you, I would create a new file system, and mount it to directory where Docker has its files.

Depending on how you added the space, there are two options:

  1. If you increased size of existing virtual disk 1.1. Use fdisk to create /dev/sda9 partition 1.2. Use mke2fs /dev/sda9 to create file system

  2. If you added a new virtual disk to VM 2.1. Use fdisk to create partition on the new device 2.2. Use mke2fs to create file system

Then, perform these steps:

  1. Run mount /dev/sda9 /mnt to mount new file system

  2. Stop Docker

  3. Run mv /var/lib/docker/* /mnt

  4. Run umount /mnt

  5. Add following line to /etc/fstab

    /dev/sda9 /var/lib/docker ext4 relatime 0 1

  6. Mount new filesystem by executing mount /var/lib/docker

  7. Start Docker

Replace /dev/sda9 with the partition name of the added virtual disk in above instructions.

After this, Docker files are in the new file system on the added space.

| improve this answer | |
  • Whats a traditional partitioning scheme? Is there a way to do this without taking docker down? im trying to avoid taking docker down, thats why im avoiding the restart. if i have to take docker down, its just as easy for me to restart the computer. Much appreciated :-) – resolver101 Jun 19 at 16:45
  • Traditional partition scheme is visible in your fdisk output. You have partitions sda1, sda5, sda7 and sda9. Other schemes are Logical Volumes, which are more flexible. There is no way to do this without taking Docker down. – Tero Kilkanen Jun 19 at 19:35
  • 1
    I presume there should be a step "Mount the filesystem" before "Start Docker". – Michael Hampton Jun 19 at 20:00
  • Thanks. How do i extend the volume to /dev/sda5 now i have added the extra 100GB in vmware? I'll restart the computer after the changes rather moving docker, ill need to take the application down anyway. I've added the fdisk to the original question incase that helps. – resolver101 Jun 19 at 20:01
  • 1
    That does not work because /dev/sda6 starts where /var partition ends. One would need to move all partitions towards the end of the disk in order to expand /var partition. – Tero Kilkanen Jun 20 at 10:47

Tero's answer is correct. Yet, if you are going to shutdown the VM, you can add a live expandable disk, so that you don't need to shut it down again for the same reason in the future.

You can expand Linux VM disks on ESXi (or other hypervisors) live. But only if:

  1. LVM (logical volume manger) is used.

or (more exotic, yet eventually simpler and it works)

  1. NO partitions, aka NO fdisk, format disks directly. For example mkfs.ext4 /dev/sdb, not mkfs.ext4 /dev/sdb1 which is the usual thing to do. It's perfectly possible.

So add a new disk using either of the above ways, assign it to something like /vartemp, copy all files from /var to /vartemp, then remove /var change /vartemp to /var and of you go. Live expanding of disk /var is now possible.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.