Ubuntu – zerofree on ubuntu 18.04

18.04disk-usagevirtualbox

I'm using Ubuntu 18.04 for development on VM VirtualBox on windows 10 pro host
I've compacted the virtual hard drive previously by following the steps from here:
https://www.howtogeek.com/312883/how-to-shrink-a-virtualbox-virtual-machine-and-free-up-disk-space/

apart from the usual updates – I have not messed around with it, (recently just had installed the update for virtualbox gues additions)

previously, I only had one /dev/sda1 showing up – today I had three and when I attempt to run zerofree on any of those, I get that the device is mounted in rw

enter image description here

I have followed some instructions here as well to stop some services and try to remount- but it didnt work

https://unix.stackexchange.com/questions/42015/mount-is-busy-when-trying-to-mount-as-read-only-so-that-i-can-run-zerofree

it still says mount point is busy

I'm unsure if this happened because of a recent update ?
I also tested by uninstalling the vmware guest additions – but it didn't work

Suggestions ?

Best Answer

As mentioned in one of the comments, you have three partitions mounted (sda1, sda2 and sda3) and several temporary filesystems used for other purposes.

The manual for zerofree indicates that if you want to run this on a filesystem, then that filesystem must be either mounted readonly, or unmounted. When you are running Ubuntu, it is certain that the root partition /, which is /dev/sda1 on your computer, is mounted thus the command will give a failure.

If you want to run zerofree on /dev/sda1 you will need to either boot from an alternate device, uch as a bootable USB or ISO image, or perform a chroot to an alternate linux image. The link that you reference has specific instructions for you, on how to run this program on your root partition. Please re-read their instructions on how to use this program in Linux:

  • Boot and access Grub before the OS loads
  • Choose 'Advanced Options' from the grub menu
  • Enter a recovery mode session
  • use the 'root' login
  • Identify the disk
  • Run zerofree
  • halt the machine
  • powerdown and restart the VM

2019-01-22

The current version Ubuntu makes running zerofree difficult from the recovery session - in this case, it is easier to run this program from a live USB:

  • Download a current Ubuntu iso file
  • Create a live USB / CD with the Ubuntu iso
  • Boot your device from the live media (this can also be done in VM's)
  • Install the program zerofree, if it is not already installed, with the command sudo apt install zerofree
  • Run the command
  • Reboot the machine
Related Question