Compacting btrfs-based vdi

Discussions about using Linux guests in VirtualBox.

Compacting btrfs-based vdi

Postby nekton » 30. Nov 2021, 06:33

I am running Windows as a host and parrot OS as a guest under virtualbox. parrot OS uses the btrfs file system.

I am trying to reduce the size of the vdi. I successfully did this with Ubuntu and zerofree and then running the vboxmanage modifymedium disk.vdi -compact under Windows.

zerofree does not support the btrfs file system.

I tried as a suggested alternative
dd if=/dev/zero of=file
rm file

But all that did was maximize the Windows host parrot OS vdi to defined value within virtualbox. Running the above vboxmanage command had no effect on the vdi size.

What do people do who want to zero out free space on the btrfs file system so that one can compact it with vboxmanage command under Windows.

The guest drive is defined as dynamic.

Thanks.
nekton
 
Posts: 9
Joined: 9. Feb 2021, 22:51

Re: Compacting btrfs-based vdi

Postby mpack » 30. Nov 2021, 10:31

nekton wrote:I tried as a suggested alternative
dd if=/dev/zero of=file
rm file

But all that did was maximize the Windows host parrot OS vdi to defined value within virtualbox. Running the above vboxmanage command had no effect on the vdi size.

That should have worked. "VBoxManage --compact" discards zero blocks from the VDI. So, the only requirement is that the zero-fill command worked. Let's concentrate on that.

Is your filesystem encrypted? That would ensure that the contents can't be zeroed.

Alternatively, perhaps BTRFS supports sparse files, meaning it doesn't actually write zero filled sectors to a file. Perhaps this would explain why zerofree doesn't support BTRFS, since otherwise I'd expect that simple tool to be agnostic about filesystems.
mpack
Site Moderator
 
Posts: 35178
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting btrfs-based vdi

Postby nekton » 30. Nov 2021, 17:36

Is your filesystem encrypted? That would ensure that the contents can't be zeroed.

Alternatively, perhaps BTRFS supports sparse files, meaning it doesn't actually write zero filled sectors to a file. Perhaps this would explain why zerofree doesn't support BTRFS, since otherwise I'd expect that simple tool to be agnostic about filesystems


I took the defaults when I installed parrot OS. I don't believe it is encrypted by default.

ext4 and BTRFS both support sparse files is my understanding. I don't know why zerofree doesn't support BTRFS but it only seems to support the extX family of file systems. I do know from my reading that BTRFS supports Copy on Write (COW) which is not supported by extX. Not sure why that would make a difference.

I am trying to find another command or commands I could try to zero out free blocks in parrot OS which is based on Debian. Not having much luck.
nekton
 
Posts: 9
Joined: 9. Feb 2021, 22:51

Re: Compacting btrfs-based vdi

Postby nekton » 30. Nov 2021, 17:39

Sorry, but forgot to include in my previous post I have also tried the sfill command in parrot OS.
sfill -l -l -z /

After running VBoxManage modifymedium disk --compact /

The .vdi file remains the same size even though df in the virtual machine shows only about half of it in use.
nekton
 
Posts: 9
Joined: 9. Feb 2021, 22:51

Re: Compacting btrfs-based vdi

Postby mpack » 30. Nov 2021, 20:33

I'm afraid I have nothing much to add to my previous post: VBoxManage compaction requires only that 1MB blocks in the VDI are zero filled. So failure to compact means that those blocks have not been zero filled.

Mind you, an additional gotcha did just occur to me. If you are using snapshots but failed to mention it then be aware that zero filling would affect only the current state (a VDI in the Snapshots subfolder), it would do nothing for the base disk (the VDI in the VM folder) which I assume you are running VBoxManage on.
mpack
Site Moderator
 
Posts: 35178
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting btrfs-based vdi [SOLVED]

Postby nekton » 30. Nov 2021, 21:56

I figured out a way to compact the vdi of my parrot OS guest on a Windows 10 host.

I attached a Knoppix live CD iso to the optical device in VirtualBox associated with parrot OS.

Knoppix started up.

As root I did the following:
apt update
apt-get install secure-delete
mount /dev/sda5 /mnt where /dev/sda5 is where the / partition is
sfill -l -l -z -v /mnt #this does an insecure single pass writing zeros to the unused space

It takes a while for this last step.

umount /mnt

Then I shutdown Knoppix and without starting the virtual machine up again I immediately ran
VBoxManage.exe modifymedium disk "C:path of vdi" --compact

I then disconnected the Knoppix ISO from the optical device in VirtualBox.

I read something about the BTRFS mounting partitions with compression so the first time I ran this I must of run the virtual machine before running the VBoxManage command and it compressed the zeros. Just guessing here.

Regardless my problem is solved. I hope others find this useful as there is not a lot of information about how to compact a BTRFS file system vdi out there in a single place.
nekton
 
Posts: 9
Joined: 9. Feb 2021, 22:51


Return to Linux Guests

Who is online

Users browsing this forum: No registered users and 28 guests