2

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

Thanks

resolver101
  • 301
  • 3
  • 7
  • 17

2 Answers2

2

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.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • 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 '20 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 '20 at 19:35
  • 1
    I presume there should be a step "Mount the filesystem" before "Start Docker". – Michael Hampton Jun 19 '20 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 '20 at 20:01
  • @resolver101 Again, you don't. You must create a new partition. – Michael Hampton Jun 19 '20 at 20:09
  • Even without LVM, it's not necessary to create a new partition. You can extend the partition under Linux, after of course you have expanded it in VMware first. The safest way is to boot using gparted iso and extend the partition using the graphic interface. If you want to do manually, you must umount /var, using fdisk to delete (!) the partition, and remake it starting from exactly the same sector and finishing to the last sector of the expanded disk. After that you can use resize2fs for ext2,3,4 filesystems or equivalent of other FSs. It's a bit dangerous, so you better use GParted iso. – Krackout Jun 20 '20 at 08:34
  • 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 '20 at 10:47
  • ok, got you. To create a new partition, how do i do that? I've added extra HD space but when run fdisk --list i cant see the space i created. What am i missing? – resolver101 Jun 20 '20 at 11:01
  • How did you add the extra space? To an existing disk or did you create a new device? – Tero Kilkanen Jun 20 '20 at 12:28
  • i added extra space through vmware. I havent done anything in Linux yet – resolver101 Jun 22 '20 at 13:46
  • That does not still answer my question. Did you extend existing disk device or did you create a new device? – Tero Kilkanen Jun 22 '20 at 16:54
1

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.

Krackout
  • 1,575
  • 7
  • 20