DEV Community

Khuram Murad
Khuram Murad

Posted on

๐Ÿš€ How I Fixed "Not Enough Free Space in /var" While Upgrading Kali Linux

While upgrading my Kali Linux running on VMware, I encountered this error:

E: You don't have enough free space in /var/cache/apt/archives/.
Enter fullscreen mode Exit fullscreen mode

When I checked my disk space using:

df -h
Enter fullscreen mode Exit fullscreen mode

I found that my /var partition was almost full, preventing the system from downloading and installing updates.


๐Ÿ” Investigating the Disk Space

To analyze the situation, I ran:

lsblk
Enter fullscreen mode Exit fullscreen mode

Disk Layout Before Fixing the Issue:

NAME                     SIZE  USED AVAIL MOUNTPOINTS
sda                      500G  
โ”œโ”€sda1                   487M  186M  245M /boot
โ”œโ”€sda2                   124.5G  
โ”‚ โ”œโ”€kalilinux--vg-root    23G   14G  8.3G /
โ”‚ โ”œโ”€kalilinux--vg-var    9.3G  7.2G  1.5G /var
โ”‚ โ”œโ”€kalilinux--vg-home   89.1G  227M  83G /home
Enter fullscreen mode Exit fullscreen mode

I had already expanded my VMware virtual disk to 500GB, but my LVM partitions hadnโ€™t been extended to use the extra space.


๐Ÿ› ๏ธ Step-by-Step Solution: Expanding the /var Partition in LVM

Since my Kali Linux uses LVM (Logical Volume Manager), I had to allocate more space to /var.


๐Ÿ“Œ Step 1: Expanding the Virtual Disk in VMware

If you're using VMware, you can increase the disk size:

  1. Power off your Kali Linux VM.
  2. Open VMware Workstation/Player.
  3. Go to VM Settings > Hard Disk > Expand.
  4. Increase the disk size to 500GB.
  5. Apply changes & boot into Kali Linux.

After this, the virtual disk (/dev/sda) now had extra space, but the partitions hadnโ€™t changed yet.


๐Ÿ“Œ Step 2: Checking Available Space

After booting up Kali, I checked the available space using:

lsblk
Enter fullscreen mode Exit fullscreen mode

Output Before Resizing Partitions:

NAME                     SIZE  USED AVAIL MOUNTPOINTS
sda                      500G  
โ”œโ”€sda1                   487M  
โ”œโ”€sda2                   124.5G  
โ”‚ โ”œโ”€kalilinux--vg-root    23G  
โ”‚ โ”œโ”€kalilinux--vg-var    9.3G  
โ”‚ โ”œโ”€kalilinux--vg-home   89.1G  
โ””โ”€ Free space            375G  (Unused)
Enter fullscreen mode Exit fullscreen mode

I had 375GB of free space that needed to be allocated to /var.


๐Ÿ“Œ Step 3: Resizing the Partition (/dev/sda5) to Use the Free Space

I had to extend /dev/sda5 (the LVM partition) to use the extra 375GB.

  1. Open cfdisk to edit partitions:
   sudo cfdisk /dev/sda
Enter fullscreen mode Exit fullscreen mode
  1. Select /dev/sda2 (Extended Partition).
  2. Choose Resize and extend it to fill the free space.
  3. Select /dev/sda5 inside /dev/sda2, and resize it to use all available space.
  4. Write changes and exit.

๐Ÿšจ Important: Reboot the system for changes to take effect:

sudo reboot
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“Œ Step 4: Expanding LVM to Use the New Space

After rebooting, I had to tell LVM to use the expanded partition.

  1. Resize the LVM Physical Volume:
   sudo pvresize /dev/sda5
Enter fullscreen mode Exit fullscreen mode
  1. Check how much free space is available in the Volume Group:
   sudo vgdisplay
Enter fullscreen mode Exit fullscreen mode

Look for "Free PE / Size", which should now show the extra space.


๐Ÿ“Œ Step 5: Extending the /var Logical Volume

Since /var was running out of space, I extended it:

sudo lvextend -L +30G /dev/mapper/kalilinux--vg-var
Enter fullscreen mode Exit fullscreen mode

Or, to use all available space:

sudo lvextend -l +100%FREE /dev/mapper/kalilinux--vg-var
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“Œ Step 6: Resizing the /var Filesystem

Now that the partition was larger, I had to resize the filesystem:

sudo resize2fs /dev/mapper/kalilinux--vg-var
Enter fullscreen mode Exit fullscreen mode

For XFS filesystems, use:

sudo xfs_growfs /var
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“Œ Step 7: Verify the New Space

To confirm that /var had more space, I ran:

df -h
Enter fullscreen mode Exit fullscreen mode

Output After Resizing:

Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/kalilinux--vg-var  40G   7.2G  32G   20% /var
Enter fullscreen mode Exit fullscreen mode

โœ… /var now had plenty of space for updates!


๐Ÿ“Œ Step 8: Running the Upgrade Again

Now that /var had enough space, I retried the upgrade:

sudo apt-get update && sudo apt-get upgrade
Enter fullscreen mode Exit fullscreen mode

This time, the upgrade completed successfully without any storage issues! ๐ŸŽ‰


๐Ÿ”š Conclusion

If you're running Kali Linux in VMware and get a "Not Enough Free Space in /var" error, follow these steps:

โœ” Expand the virtual disk in VMware

โœ” Resize the partitions (/dev/sda5)

โœ” Update LVM with pvresize, lvextend, and resize2fs

โœ” Retry the upgrade!

This method works not only for Kali Linux, but for any LVM-based Linux system running in a VM or a physical machine.

If this guide helped you, feel free to share it! ๐Ÿš€๐Ÿ”ฅ


โœ๏ธ Author: Khuram Murad

๐Ÿ“Œ Follow me for more Linux tips!

Top comments (0)