VirtualBox

Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#14977 closed enhancement (wontfix)

Compacting encrypted VDI

Reported by: i8329 Owned by:
Component: virtual disk Version: VirtualBox 5.0.12
Keywords: Cc:
Guest type: all Host type: all

Description

I am doing the following steps to compact VDI:

  1. Clean disk
  2. Defragment disk
  3. Zero free space
  4. Compact VDI

It works for unencrypted VDI.

For encrypted VDI: At step 3 disk size grows to maximum size. At step 4 disk size does not reduce.

Evidently, this happens because zero blocks are encrypted. I think the problem could be solved if VirtualBox encrypted only non-zero blocks.

Change History (4)

comment:1 by aeichner, 8 years ago

Guest type: Windowsall
Host type: Windowsall
priority: majorminor
Resolution: wontfix
Status: newclosed
Type: defectenhancement

This will not be implemented in the foreseeable future. The encryption of the guest data is done very early so the disk format backends never sees the unencrypted data to omit writing zero blocks. This would also result in a mix of unencrypted (although the data consists of just zeros) and encrypted data in the final disk image which we don't want.

comment:2 by gggeek, 5 years ago

I guess that a workaround to this would be to add 2 steps to the above procedure:

  • Clean disk
  • Defragment disk
  • Zero free space
  • Unencrypt disk
  • Compact VDI
  • Encrypt disk

Can anyone confirm that this works ?

comment:3 by Socratis, 5 years ago

@gggeek, I don't see why it wouldn't.

But remember, at the "Zero free space" step your VDI will increase to its maximum size, make sure you have the space for it. Because usually people remember to shrink their VDIs when they run out of space...

in reply to:  2 comment:4 by Maxxim, 5 years ago

Replying to gggeek:

I guess that a workaround to this would be to add 2 steps to the above procedure:

  • Clean disk
  • Defragment disk
  • Zero free space
  • Unencrypt disk
  • Compact VDI
  • Encrypt disk

Can anyone confirm that this works ?

I tested this and can confirm that it does NOT work this way. The compacted VDI expands to full size again when re-encrypting. Tested with VirtualBox 5.2.26.

I came up with a different workaround:

  • start VM, clean disk, defragment disk, zero free space, shutdown VM
  • add new VDI of equal size to VM
  • edit .vbox file of VM to add encryption to new VDI (refer to old VDI for format; could not find any way to do this via GUI)
  • add live CD to VM (e.g. SystemRescueCD), start VM, boot into live CD
  • transfer partition table + bootloader to new disk (e.g. 'dd if=/dev/sda of=/dev/sdb bs=512 count=63')
  • transfer partition data using ntfsclone (e.g. 'ntfsclone --overwrite /dev/sdb1 /dev/sda1'; repeat for other partitions)
  • shutdown VM, remove old VDI

-> done. tested, works fine.

Last edited 5 years ago by Maxxim (previous) (diff)
Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use