Ubuntu

Get rid of full disk in Ubuntu

by mounting directory appropriately.

Recently when working with docker-compose, I met an issue:

No space left on device

The first solution comes up to my mind is add disk space from different partition to the partition that holds docker. But this is difficult. Turns out we have easier problem that we can mount the directory that holds docker data to different directory.

Check the /var/lib/docker, we will see that it belongs to /dev/sdb3

user:/var/lib/docker$ df .
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb3 58795996 53734356 2045244 97% /

And /dev/sdb3 is about to full.

Check the home directory

user:/home$ df .
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb4 892956360 429285640 418241268 51% /home

/dev/sdb4 still has a lot of space. So we will mount /var to this home directory.

This is how we could do that

  • mkdir -p /home/var
  • rsync -va /var /home/var
  • mv /var /var.old # you can remove /var.old when you are done to reclaim the space
  • mkdir -p /var
  • mount -o bind /home/var /var
  • update your /etc/fstab to make the bind-mount permanent.

/etc/fstab

/home/var /var        none    bind

Then when we work with docker, data will be stored in /home/var instead of /var.

References

Enjoy working guys~~~

PEACE~~

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store