1

I have a question. I have Vmware workstation and one of my Vms is nextcloud with ubuntu 1804.

I like to have a snappy instance so I use these commando's found here:

sudo e4defrag /                         
dd if=/dev/zero of=wipefile bs=1M; sync; rm wipefile            
sudo vmware-toolbox-cmd disk shrinkonly

For a while this worked fine. But now on step 2: dd if=/dev/zero of=wipefile bs=1M; sync; rm wipefile I get error:

64172396544 bytes (64 GB, 60 GiB) copied, 56.5438 s, 1.1 GB/s
ncadmin@cloud:~$ error writing 'wipefile': No space left on device

But when I do a: df -Th I have plenty of space:

Filesystem                        Type      Size  Used Avail Use% Mounted on
udev                              devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                             tmpfs     796M  1.4M  794M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4      103G   39G   60G  40% /
tmpfs                             tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs                             tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs                             tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda2                         ext4      976M  157M  753M  18% /boot
/dev/loop0                        squashfs   89M   89M     0 100% /snap/core/739            6
/dev/loop1                        squashfs   55M   55M     0 100% /snap/lxd/1210            0
/dev/loop2                        squashfs   55M   55M     0 100% /snap/lxd/1198            5
/dev/loop3                        squashfs   90M   90M     0 100% /snap/core/771            3
tmpfs                             tmpfs     796M     0  796M   0% /run/user/1000

I only have basic linux understanding

roT-
  • 11
  • 3

1 Answers1

1

No space left on device was expected. This command

dd if=/dev/zero of=wipefile bs=1M

reads from /dev/zero and writes to wipefile. The special file /dev/zero cannot be depleted. The command runs until wipefile cannot grow anymore (or until you manually terminate it first).

So you clogged the filesystem, there was indeed no space left on device. Then you flushed cache with sync and removed the file with rm. The file was exactly 64172396544 bytes before removal, this space was reclaimed when you removed the file. Now you have about 60 GiB available on /. All fits.

The point of creating this file was to fill available space with zero bytes; the point of syncing was to make sure all zeros actually got to the device; the point of removing the file was to formally mark zeroed blocks as empty again. You didn't need the file itself; you needed to write zeros to "empty" blocks. A file that later gets removed is just a simple way to do it.

I guess vmware-toolbox-cmd can now do its job: shrink. I don't know this tool at all but the idea of filling empty space with zeros is quite sane when you keep (or want to keep) the entire filesystem as a file and you want the file to be as small as possible. The main filesystem of your VM is just a file from the point of view of the host, right? Compare this answer of mine where the same method is used to prepare a filesystem to be effectively stored as a regular file. My code explicitly says

## Long wait here. Expect "no space left on device".