What Is a VDI File? The VirtualBox Disk Image File, and How to Open, Convert and Check One
A VDI file is the virtual hard disk of a VirtualBox virtual machine. Three readers opened all 10 of our test files, and they gave one answer on only 5 of 21 damaged copies. Jump to your question below, or work through it in order.
What Is a VDI File? The hard disk of a VirtualBox machine, and what the ending hides
Short answer
A VDI file is a virtual hard disk image, and it is the native disk format of Oracle VirtualBox. It is one file with a text line, a header, a map of blocks and the data. All 10 of our test files end in .vdi, and they are two kinds.
We tested 10 VDI files with 3 readers, and all 10 opened in all 3. We then damaged one file in 21 ways, and the 3 readers gave one answer on only 5 copies.
To see inside one, use the open steps. To make a raw disk from one, use the convert steps. If your VDI file will not open, begin with the causes.
A VDI file is a virtual hard disk image, and it is the native disk format of Oracle VirtualBox. It is one file with a text line, header, block map and data. All 10 of our test files end in .vdi, and they are two kinds.
Picture a folder named after a virtual machine. Inside it is a VDI file, and that file is the hard disk of the machine. FileInfo names the type VirtualBox Virtual Disk Image and lists Oracle as the developer.
Wikipedia says VDI is the native disk format of VirtualBox. VirtualBox also supports VMDK files from VMware and VHD files from Microsoft, and it can resize VDI and VHD images since version 4.0.
The ending is not unique. FileInfo lists two other file types that use .vdi, a disk image from Virtuo CD Manager and a debug file from StepMania. We had neither, so this page is about the VirtualBox disk.
Where our VDI files come from
We studied 10 VDI files. We made 9 of them with qemu-img 8.2.2 from one 16 MiB disk image, and 3 of the 9 have a longer disk with zeros added at the end. The image has a small file system with 7 files in it.
The 10th VDI file is a public test file from the dissect.hypervisor project, and we had no source disk for it. We made no VDI file with VirtualBox. All 10 files show the text line of QEMU, even the public one.
So our results show how readers treat VDI files, and they do not show what VirtualBox accepts. Our three readers are qemu-img, dissect.hypervisor 3.21 and 7-Zip 23.01.
We also damaged one dynamic VDI file in 21 ways, cut it in 48 places and changed one byte in 24 places. Our lab uses Linux and has no VirtualBox, so we opened no VDI file in VirtualBox.
VDI file facts at a glance
| Property | Value |
|---|---|
| Meaning | A virtual disk image, the native disk format of VirtualBox, per Wikipedia. |
| Ending |
.vdi. FileInfo names the type VirtualBox Virtual Disk Image and lists two other types with the same ending.
|
| Maker | Oracle, per FileInfo. |
| Pieces | One VDI file, with a text line, a header, a block map and data blocks. |
| Signature |
7F 10 DA BE at offset 64, after a text line of 64 bytes.
|
| Block size | 1 MiB in all 10 of our files. The qemu source for VDI accepts only 1 MiB. |
| Readers | qemu-img, dissect and 7-Zip, all tested. FileInfo shows Oracle VM VirtualBox, Aryson VDI Recovery and File Viewer for Android. |
| Our tests | 10 files, 21 damaged copies, 3 readers in the grid, a check script of 29 lines and a repair script of 17 lines. |
Is it a compressed archive and not a disk image? The ZIP file overview covers the ZIP format.
Which Kind of VDI File Is Yours? Four kinds, and the name does not decide
Two kinds of VDI disk showed up in our tests, dynamic and static, and both opened in all 3 readers. Two more kinds are named in the format notes, and FileInfo lists two other file types with the same ending. We tested none of those four.
Anyone can see the ending, and it does not name the kind. We sorted our 10 files by signature and by image type. Follow the figure.
The kinds in detail
| Kind | Files and results |
|---|---|
| A dynamic disk | 8 of 10 files. The header says image type 1, and the file grows as data arrives. A 16 MiB disk took 3,146,752 bytes in our file, because only 3 of 16 blocks have data. All 3 readers opened every one. |
| A static disk | 2 of 10 files. The header says image type 2, and the file has full size. Ours has 16,778,240 bytes for a 16 MiB disk and 67,109,888 bytes for a 64 MiB disk. In our 16 MiB file the block map lists blocks 0 to 15 in order. |
| An undo or differencing disk | 0 of 10 files. The Kaitai format file names image type 3 as undo and type 4 as diff. We had none, so we tested neither. |
| Another file type | 0 of 10 files. FileInfo lists a Virtuo CD Manager disk image and a StepMania debug file with the .vdi ending. The signature at offset 64 is the first clue. We had neither type. |
Look at the first bytes
Every VDI file in our set starts with a text line, and the signature comes at offset 64. Command one prints the text line. Command two prints 32 bytes from offset 64.
head -n 1 disk.vdi
<<< QEMU VM Virtual Disk Image >>>
xxd -s 64 -l 32 disk.vdi
00000040: 7f10 dabe 0100 0100 8001 0000 0100 0000 ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
Offset 64 has 7f10 dabe, which is the signature. The next 4 bytes, 0100 0100, give version 1.1. Then come the header size, 8001 0000, which is 384, and the image type, 0100 0000, which is 1 for dynamic.
| Value | What we measured |
|---|---|
| Text line | The same 34 characters, <<< QEMU VM Virtual Disk Image >>>, in all 10 files. Copy A1 changes its first character, and all 3 readers ignored the change. |
| Signature |
7F 10 DA BE at offset 64 in all 10 files. The Kaitai format file gives the same four bytes.
|
| Version and header size |
Version 1.1, stored as 0x00010001, and a header size of 384 bytes in all 10 files.
|
| Image type | Type 1 in 8 files and type 2 in 2 files. |
| Block size | 1,048,576 bytes in all 10 files, with an extra field of 0 bytes per block. |
| Disk size and blocks | From 10,485,760 to 67,108,864 bytes of disk, and from 10 to 64 blocks. |
| Map and data | The block map starts at offset 512 and the data starts at offset 1,024 in all 10 files. The sector size is 512 bytes. |
Is it an Access database and not a disk? The ACCDB file page covers the Access format.
What Is Inside a VDI File? A header, a block map and blocks of data
A dynamic VDI file has a 64 byte text line, header, block map and data blocks of 1 MiB. Our example has 3,146,752 bytes and 3 data blocks. The qemu header layout lists no checksum, and we found none in the blocks.
We looked inside one dynamic VDI file, because its layout explains the results later on this page. It has 16 MiB of disk and 3,146,752 bytes of file. The two commands below show how qemu-img describes it and how 7-Zip lists the files inside the disk.
qemu-img info disk.vdi
image: disk.vdi
file format: vdi
virtual size: 16 MiB (16777216 bytes)
disk size: 3 MiB
cluster_size: 1048576
7z l disk.vdi
D.... lost+found
..... 3400 4096 file1.txt
..... 6800 8192 file2.txt
..... 10200 12288 file3.txt
..... 13600 16384 file4.txt
..... 17000 20480 file5.txt
..... 20400 20480 file6.txt
..... 300000 303104 random.bin
..... 4194304 4194304 [SYS]/Journal
4565704 4579328 8 files,
7-Zip shows the file system of our disk, with 7 files and a journal. So disks contain file systems, and VDI files are containers around them. Follow the figure for the layout.
The parts, one by one
The header starts at offset 64. Its fields give the signature, version, image type, offsets, sector size, disk size, block size and block counts. The size field says 384 bytes in all 10 files.
The block map starts at offset 512, and our dynamic file has 16 entries of 4 bytes. Entry 0 says 0, entry 1 says 1 and entry 5 says 2. The other 13 say FFFFFFFF. So virtual blocks 0, 1 and 5 have data, and the data is in blocks 0, 1 and 2 of the file.
Data starts at offset 1,024, and every block has 1 MiB. Our 3 data blocks take 3,145,728 bytes, and the file has 3,146,752. A static file lists all 16 blocks in order and has 16,778,240 bytes.
What every part stores
| Part | What it stores |
|---|---|
| Text line | The first 64 bytes. Copy A1 changes the first character, and all 3 readers returned the original disk. |
| Header | Signature, version, image type, offsets, sizes and counts. Copy A2 changes the signature, and qemu-img and dissect refused it. Our repair script restores it. |
| Block map | One entry for every block. Copy C4 zeroes the map, and all 3 readers returned another disk with no error. Copy C5 frees the first entry, and the same happened. |
| Data blocks | The data. Copy C6 changes one byte, and all 3 readers gave another answer with no warning. |
| The file cut short | Copy C7 cuts the file at 2,000,000 bytes. qemu-img and dissect returned another disk with no error, and 7-Zip returned other files. |
What the public pages say about the layout
The qemu source file for VDI lists the header fields in order. It names type 1 dynamic and type 2 static. It marks a block as unallocated with FFFFFFFF and as discarded with FFFFFFFE, and it accepts only version 1.1.
The Kaitai format file for VDI adds type 3 for undo and type 4 for diff, and it says every field is little-endian. We had no file of those two types, so we did not test them.
The structure is small. Our script checks the header, block map and file size. It never looks at data blocks, so it printed OK for copy C6, where one byte changed.
What Did We Find in 10 Test VDI Files? Three readers, and all ten files opened in all of them
We tested 10 VDI files with 3 readers, and all 10 opened in all 3. The 9 files with a source disk gave back the original bytes in qemu-img and dissect, and 7-Zip extracted the original files from all 9. The 10th file has no source, so we could only open it.
We made 7 of the VDI files from raw disks of 16 MiB, 64 MiB and 17,000,448 bytes. We made 2 more from a VMDK file and a QCOW2 file of the 16 MiB disk. The 10th is the public test file.
A file counts as same when qemu-img and dissect return the original disk by SHA-256 and 7-Zip extracts all 7 original files.
What the numbers show
| Finding | What we measured |
|---|---|
| Every reader opened every file | qemu-img, dissect and 7-Zip opened all 10 files. None refused one. The 9 files with a source disk gave the original disk in the 3 readers. |
| Dynamic files stay small | The 16 MiB and the 64 MiB dynamic files have the same size, 3,146,752 bytes, because both have 3 blocks of data. Our 64 MiB map has 64 entries and the 16 MiB map has 16. |
| Static files have the full disk | The 16 MiB file has 16,778,240 bytes and the 64 MiB file has 67,109,888. Both are 1,024 bytes more than the disk. The first 1,024 bytes are text line, header and block map. |
| The write options changed nothing we could see | Files made with the falloc and full options have the same size and 3 blocks, like the default dynamic file. All 3 readers opened them. |
| An odd disk size works | Our disk of 17,000,448 bytes has 17 blocks of 1 MiB, and the file has 3,146,752 bytes. qemu-img returned a raw disk of exactly 17,000,448 bytes. |
| Other formats feed VDI files | The files made from a VMDK file and from a QCOW2 file opened in all 3 readers and gave the original disk. |
| The public file opened too | It has 9,438,208 bytes, a disk of 10,485,760 bytes and 9 of 10 blocks in use. All 3 readers opened it, and we had no source to compare with. |
We do not know which of these files VirtualBox would accept, because we made none with it. The 10 files show that three readers agree on small VDI files that are in good shape.
What this study cannot show you
These are small files. Our biggest disk has 64 MiB, and a disk from a working machine can have hundreds of gigabytes. A reader that passes here has shown that it opens small samples.
We opened no VDI file in VirtualBox. We tested no differencing file, no undo file, no encrypted disk and no file over 67,109,888 bytes. We compared full disks by SHA-256 and the 7 files inside our disk. We did not start any virtual machine.
What Happens When a VDI File Is Damaged? 21 broken copies, and a zeroed map that nobody flags
We damaged one VDI file in 21 ways. The 3 readers gave the original answer on 5 copies and refused 3. A zeroed block map and one changed byte opened in every reader with no warning, and our script printed OK for the changed byte.
Our base file is disk.vdi, a dynamic file of 3,146,752 bytes. We changed one thing at a time and saved 21 copies. Same means the reader returned the original disk, and for 7-Zip it means all 7 original files. Refused means an error and no data.
Differs means a reader opened the copy and gave another answer. For copies C4 to C7 that is a fact about the data, because the data now differs. Follow the figure.
What the grid shows
| Copies | What happened |
|---|---|
| The text line | Copy A1 changes the first character of the text line. All 3 readers gave the original answer, so they ignored the text line. |
| The signature | Copy A2 changes the last byte of the signature. qemu-img and dissect refused it. 7-Zip printed a warning and an error, and then made files of 0 bytes. |
| Version and header size | Copy A3 sets the version to 2.1 and qemu-img refused it. Copy A4 sets it to 1.0 and qemu-img refused it again. Copy A5 sets the header size to 0 and 7-Zip gave other files. All three are in the repair list. |
| The image type | Copy A6 sets the type to 0 and A7 sets it to 2. All 3 readers gave the original answer on both, so the type did not change the result in our tests. |
| Offsets to the map and the data | Copy B1 sets the map offset to 0 and B2 sets it to 99,999,999. Copy B3 sets the data offset to 0. B2 was refused by all 3 readers, and B1 and B3 opened in some readers with another disk. |
| Sector size, disk size and block size | Copy B4 sets the sector size to 0, B5 sets the disk size to 0 and B6 sets the block size to 0. B7 sets the block size to 2 MiB. B6 was refused by all 3 readers, and B5 opened everywhere with another answer. |
| The counts | Copy C1 sets the block count to 0 and all 3 readers refused it. Copy C3 sets the count to 17 and C2 sets the used blocks to 99. All 3 readers gave the original answer on both. |
| The block map | Copy C4 zeroes the map. Copy C5 frees the first used entry. All 3 readers opened both and returned another disk with no warning. |
| One changed byte | Copy C6 inverts one byte in the first data block. All 3 readers opened it and gave another answer with no warning. |
| A cut file | Copy C7 keeps the first 2,000,000 bytes. All 3 readers opened it and gave another answer. |
The pattern has two sides. A broken header is easy to see, because most readers refuse it. A broken map or block is hard to see, because the header is fine and nothing checks the data.
The readers differ in how much they accept. dissect gave the original answer on 9 copies and refused 5. qemu-img gave it on 6 and refused 8. 7-Zip gave it on 6 and refused 5.
The silent failures
Two tests point to a risk. First, we cut the file at 48 places, from 65,536 bytes up to 3,145,728 in steps of 65,536. qemu-img and dissect refused none of the 48. dissect gave another answer on all 48, and qemu-img gave the original on the 10 longest cuts.
7-Zip refused 18 of the cuts, gave other files on 20 and gave the original files on 10. So a short VDI file can open and look fine in a reader. Compare its size with the size of the original.
Second, we inverted one byte at 24 places, 8 in every data block. qemu-img and dissect opened all 24 and returned another disk, and neither warned. 7-Zip extracted the original files on 21 and other files on 3, because changing those 21 bytes left all 7 files as they were.
So an open VDI file is not proof that the data is right. Our script cannot see a changed byte either, because headers and maps do not change. Only a hash of the disk shows it.
Our script and the repairs
Our check script of 29 lines printed OK for 3 copies, WARN for 2 and FLAG for 16. One of the 3 OK copies, C6, did not match the original in any reader, because it checks headers and maps and not data. See the script.
It also printed WARN or FLAG on 3 copies that all 3 readers treated as the original. They are A6, C2 and C3. So a flag is a reason to look and not proof of damage.
The repair script of 17 lines restored 10 copies, A2 to A5, B1 to B4, B6 and C1. After it all 3 readers gave the original answer on those ten, so 15 of the 21 copies end with the original answer.
It cannot restore cut files, zeroed maps, changed bytes or the disk size in B5. We did not test repaired VDI files in VirtualBox.
What Does Our Expert Say About VDI Files? A note from Neeraj Singh on trusting a disk that opens
We asked our expert what the grid means for someone who has a VDI file and has to decide if it is right. He looked at the 21 copies and at the zeroed block map.
Expert insight
Treat a VDI file as a container, and keep a hash of the disk inside it. A zeroed block map made every block show the first block with no error, so an open file is not proof that the data is there.
That advice fits our lab. All 3 readers opened the zeroed map and a changed byte, so a quick open proves little. Convert the disk to raw, and compare its hash with one from a good time.
How Do You Open a VDI File? Three readers, with the commands we tested
To open a VDI file without VirtualBox, use qemu-img, dissect or 7-Zip. All 3 opened all 10 of our files and left the files unchanged. We did not test VirtualBox. Copy the files first, and compare more than one reader.
VirtualBox is the usual route. FileInfo lists Oracle VM VirtualBox, Aryson VDI Recovery and File Viewer for Android for the type. Our lab uses Linux and has no VirtualBox, so we tested 3 readers that need none.
Your options
Copy first, then look
Work on copies of VDI files, and keep their names. Our readers only looked at the files. SHA-256 hashes of a dynamic file and of a static file were the same before and after qemu-img, dissect and 7-Zip opened them. Copies cost nothing, and they keep the original safe from your own mistakes.
Look at the size of the disk
Start with disk size. Command one asks dissect for it. Command two checks the file with qemu-img. The first prints 16777216 bytes, which matches the 16 MiB qemu-img reported.
python3 -c "from dissect.hypervisor.disk.vdi import VDI; v = VDI(open('disk.vdi', 'rb')); print(v.size)"
16777216
qemu-img check -f vdi disk.vdi
No errors were found on the image.
The check looks at maps. It found 16 errors in copy C4, where the map is zeroed, and 1 error in copy C5, where entry 0 is freed.
It found no errors in copy C6, where one byte changed, or in copy C7, which is cut short. So a good check is a start, and it does not prove data.
| Result | Copies |
|---|---|
| Errors found | B1 had 16 errors, C2 had 1, C3 had 2, C4 had 16 and C5 had 1. C2 and C3 still gave the original disk in all 3 readers. |
| Refused to open | 8 copies, A2 to A4, B2, B4, B6, B7 and C1. |
| No errors | 8 copies, A1, A5 to A7, B3, B5, C6 and C7. Five of them, A5, B3, B5, C6 and C7, did not give the original disk in every reader. |
Is it a database and not a disk? The SQLITE file overview covers the SQLite format.
How Do You Convert a VDI File to Another Disk Format? Five targets, tested on one disk
To convert VDI files to raw disks, use qemu-img. Our example gave a raw file with the same SHA-256 as our source disk. QCOW2, VMDK and VHDX gave the same bytes back, and VHD added 4,096 bytes of size. We tested no VirtualBox converter.
All conversions left the VDI file unchanged in our tests. We checked every result by converting it back to raw and comparing SHA-256 hashes. Raw files are disks as bytes, and they have the full size of a disk, 16,777,216 bytes for ours.
Convert it to raw
Command one converts a VDI file. Command two makes a hash that matches our source disk. Command three lists files in the raw disk with debugfs, so you can see data is there.
qemu-img convert -f vdi -O raw disk.vdi disk.raw
sha256sum disk.raw
df77962264738a5775e4ccf3b7b7c595cfcd9adbf4951cc3d835e4412cc59321 disk.raw
debugfs -R "ls -l" disk.raw
11 40700 (2) 0 0 16384 7-Nov-2026 00:56 lost+found
12 100644 (1) 0 0 3400 7-Nov-2026 00:56 file1.txt
Static files gave the same raw disk as dynamic files. The raw files from both matched byte for byte.
Convert it to other formats
The same command makes other formats when you change the -O option. We converted our VDI file to QCOW2, VMDK, VHDX and VHD, and then back to raw. We compared raw files with the source.
| Target | Result |
|---|---|
| Raw | 16,777,216 bytes. The SHA-256 matches the source disk. |
| QCOW2 | The file has 1,048,576 bytes. The SHA-256 after a conversion back to raw matches. |
| VMDK | The file has 786,432 bytes. The SHA-256 after a conversion back to raw matches. |
| VHDX | The file has 16,777,216 bytes. The SHA-256 after a conversion back to raw matches. |
| VHD |
The file has 4,197,888 bytes and the virtual size is 16,781,312 bytes, which is 4,096 more. The first 16 MiB match. The option force_size=on kept 16,777,216 bytes, and the hash matched.
|
Our odd disk of 17,000,448 bytes shows the same effect. VHD gave a virtual size of 17,025,024 bytes, and the first 17,000,448 bytes matched the source.
Make a VDI file
Use -O vdi to make VDI files. We made them from raw, VMDK and QCOW2 disks. Dynamic files have 3,146,752 bytes for our disk. The option static=on makes static files, and ours has 16,778,240 bytes. All of them opened in 3 readers.
qemu-img convert -f raw -O vdi -o static=on disk.raw disk.vdi
What we did not test. We converted disks of 16 MiB, 17,000,448 bytes and 64 MiB. We did not test converters from VirtualBox, web converters, differencing files, encrypted disks or disks over 64 MiB. We did not start a virtual machine from any converted disk.
Is the disk image a ZIP of files? The ZIP file page covers archives.
How Do You Check a VDI File? Six steps and a script of 29 lines
Check VDI files in six steps. Copy one first. Then print its signature, check its header and map, convert it to raw in two readers, list the files inside and compare hashes with a known good copy. Our script of 29 lines does the header and map step.
- Copy the VDI file, and keep the original.
-
Print 4 bytes at offset 64 with
xxd -s 64 -l 4 disk.vdi. They must be7f10 dabe. -
Check the header and the map with
python3 vdi_peek.py disk.vdi. A good file prints OK. Then useqemu-img check -f vdi disk.vdi. - Convert the copy to raw in two readers, and compare the SHA-256 of the two raw files.
- List the files inside the raw disk with 7-Zip or debugfs, and open a few.
- Keep a SHA-256 hash of the raw disk from a good time, and compare it with the disk you have now. Only comparing hashes finds silent changes.
The check in Python
Our script of 29 lines checks VDI file headers with the standard library. It prints OK, WARN or FLAG with the problem it found. It checks the signature, version, sizes, offsets and block counts. For dynamic files it reads the block map and the size of the file. It never looks inside data blocks.
import sys, struct, os
def peek(p):
n = os.path.getsize(p); b = open(p, 'rb').read(65536)
if len(b) < 0x188: return 'FLAG', 'file shorter than the header'
sig, ver, hs, ty = struct.unpack('<4I', b[0x40:0x50])
ob, od, cy, hd, sc, ss = struct.unpack('<6I', b[0x154:0x16c])
ds, bs, bx, bt, ba = struct.unpack('<QIIII', b[0x170:0x188])
bad, warn = [], []
if sig != 0xbeda107f: bad.append('signature %08x' % sig)
if ver >> 16 != 1: bad.append('major version %d' % (ver >> 16))
elif ver & 0xffff != 1: warn.append('minor version %d' % (ver & 0xffff))
if hs < 0x180: bad.append('header size %d' % hs)
if ty not in (1, 2): warn.append('image type %d' % ty)
if bs == 0 or bs & (bs - 1): bad.append('block size %d' % bs)
if ss not in (512, 4096): bad.append('sector size %d' % ss)
if ds == 0: bad.append('disk size 0')
if ob == 0 or ob >= n: bad.append('block map offset %d' % ob)
if od == 0 or od >= n: bad.append('data offset %d' % od)
if bs and bt != -(-ds // bs): bad.append('blocks %d, expected %d' % (bt, -(-ds // bs)))
if ba > bt: bad.append('allocated %d over total %d' % (ba, bt))
if not bad and ty == 1:
m = struct.unpack('<%dI' % bt, open(p, 'rb').read(ob + bt * 4)[ob:])
used = [x for x in m if x < 0xfffffffe]
if len(used) != ba: bad.append('block map has %d, header says %d' % (len(used), ba))
if len(set(used)) != len(used): bad.append('block map repeats a block')
if used and n < od + (max(used) + 1) * (bs + bx): bad.append('file shorter than the data')
return ('FLAG', '; '.join(bad)) if bad else (('WARN', '; '.join(warn)) if warn else ('OK', 'header looks fine'))
for p in sys.argv[1:]:
s, m = peek(p); print('%s %-5s %s' % (os.path.basename(p), s, m))
What the script prints
First comes a good dynamic file. Next is copy A2, with its signature changed. Then copy B6, which has a block size of 0. Then comes copy C4, with a zeroed map, and the script flags it. Last is C6, where one byte changed. The script cannot see C6, and all 3 readers returned another disk.
python3 vdi_peek.py disk.vdi A2.vdi B6.vdi C4.vdi C6.vdi
disk.vdi OK header looks fine
A2.vdi FLAG signature beda107e
B6.vdi FLAG block size 0
C4.vdi FLAG block map has 16, header says 3; block map repeats a block
C6.vdi OK header looks fine
The repair script
The repair script of 17 lines changes VDI file headers only. It restores the signature, version, header size and image type. It fixes a bad block size, sector size, offset or block count. It restored 10 of our 21 damaged copies.
It guesses 1 MiB blocks and 512 byte sectors when a field is bad. Those values fit our file, and files made with other values need other numbers.
python3 vdi_fix.py B6.vdi B6_fixed.vdi
python3 vdi_peek.py B6.vdi B6_fixed.vdi
B6.vdi FLAG block size 0
B6_fixed.vdi OK header looks fine
import sys, struct, shutil
src, dst = sys.argv[1:3]
shutil.copyfile(src, dst)
f = open(dst, 'r+b'); b = f.read(65536)
sig, ver, hs, ty = struct.unpack('<4I', b[0x40:0x50])
ob, od, cy, hd, sc, ss = struct.unpack('<6I', b[0x154:0x16c])
ds, bs, bx, bt, ba = struct.unpack('<QIIII', b[0x170:0x188])
if ds == 0: ds = cy * hd * sc * 512 or ds
if bs == 0 or bs & (bs - 1): bs = 1 << 20
if ss not in (512, 4096): ss = 512
bt = -(-ds // bs)
if ob == 0 or ob >= 1 << 20: ob = 512
if od == 0 or od > 1 << 30: od = ob + -(-bt * 4 // 512) * 512
raw = open(dst, 'rb').read(ob + bt * 4)
if len(raw) == ob + bt * 4: ba = sum(x < 0xfffffffe for x in struct.unpack('<%dI' % bt, raw[ob:]))
f.seek(0x40); f.write(struct.pack('<4I', 0xbeda107f, 0x10001, max(hs, 0x180), ty if ty in (1, 2) else 1))
f.seek(0x154); f.write(struct.pack('<7IQ4I', ob, od, cy, hd, sc, ss, 0, ds, bs, bx, bt, ba)); f.close()
Copy B6 had a block size of 0. The script sets the size to 1 MiB and writes the header again. All 3 readers then gave the original disk, and that is the only proof we have. We did not test repaired VDI files in VirtualBox.
Know the limits. The script printed OK for 3 copies, and in one of them, C6, the readers did not give the original disk. It cannot see changed bytes. So an OK from one script is only a start, and comparing hashes with a known good copy is the test.
Is a VDI File Safe to Open? The file is data, and the risk is the disk inside
Opening a VDI file with a reader looks at bytes and starts nothing. The risk is the disk inside, because it can contain any file, program or private data. Our readers left every file unchanged. We started no virtual machine and scanned nothing for malware.
VDI files are copies of disks. Anything on the disk is in the file, including documents, settings and programs. So treat an unknown VDI file like a stranger's hard drive.
Our own disk has 7 files that we made. We did not scan any file with a security tool, and we did not start a virtual machine from any disk.
Five steps for a file you do not know
- Get the file from a source you trust, and keep the original.
-
Print 4 bytes at offset 64 with
xxd -s 64 -l 4 file.vdi. A VirtualBox disk shows7f10 dabe. - Make a copy, and list the files inside the disk with a reader.
- Look at the file list before you open any file from the disk.
- Do not start a virtual machine from a disk you do not know.
What we did not test. We scanned no file for malware and started no machine from any disk. These steps lower the risk of surprises and do not remove it.
Why Will Your VDI File Not Open? Seven causes, and what to do about every one
Seven causes stop VDI files from opening or make disks look wrong, and the file causes only some of them. Start with the first bytes. The signature at offset 64 shows if the file is a VirtualBox disk at all.
Work down the list in order. Every cause comes from our 10 files, our 21 damaged copies or our cut and byte tests, so every fix names copies or counts. If you still have the virtual machine, copy the disk again. New copies are the safest fix for damaged files.
7f10 dabe.
How Does a VDI File Differ From Other Disk Files? Raw, QCOW2, VMDK and VHD, measured on one disk
A VDI file is one of several disk formats, and our readers converted it to the others with no change in the bytes. QCOW2, VMDK and VHDX gave the same bytes back, and VHD added 4,096 bytes of size. We tested conversions only, and no virtual machine.
The table lists neighbors of the VDI file. We made every file from one 16 MiB disk with qemu-img, so sizes show how one tool wrote the disk and do not rank formats.
| Format | What we measured |
|---|---|
| VDI dynamic | 3,146,752 bytes for our disk. All 3 readers returned the original bytes. |
| VDI static | 16,778,240 bytes for our disk. The raw disk from it matched the dynamic one byte for byte. |
| Raw | 16,777,216 bytes, the full size of the disk. debugfs listed the files in it with no other tool. |
| QCOW2 | 1,048,576 bytes. The bytes came back the same after a conversion to raw. |
| VMDK | 786,432 bytes. The bytes came back the same after a conversion to raw. |
| VHD and VHDX | VHDX has 16,777,216 bytes and gave the same bytes back. VHD has 4,197,888 bytes and a virtual size of 16,781,312 bytes. |
VDI or raw
Raw files are disks as bytes, with no header and no map. They have the full size of the disk. Dynamic VDI files add a text line, a header and a block map, and our file is 3,146,752 bytes for the same 16 MiB disk.
Raw is the easiest format to check, because a hash of the file is a hash of the disk. We use raw as the common ground for every comparison on this page.
VDI or VMDK
Wikipedia notes that VirtualBox supports VMDK and VHD files besides VDI, which allows exchange of disks with other programs. Our VMDK file for the same disk has 786,432 bytes and converted back to the same bytes. We opened neither file in VirtualBox, so we make no claim about what it accepts.
Static or dynamic
A dynamic file grows as data arrives, and ours has 3,146,752 bytes. A static file has the full disk plus 1,024 bytes, and ours has 16,778,240. Both gave the same raw disk. The 64 MiB dynamic file had the same size as the 16 MiB one, because both have 3 blocks of data.
What Is the VDI File Format Made Of? The facts we could check, and where they came from
A VDI file stores a disk as a text line, header, block map and data blocks of 1 MiB. Facts below come from our checks of 10 files and 21 damaged copies. Sources are Wikipedia, FileInfo, the qemu source and the Kaitai format file.
| Part | What we could check |
|---|---|
| Maker | Oracle. FileInfo lists Oracle as the developer and names the type VirtualBox Virtual Disk Image. |
| Name | Virtual Disk Image, per Wikipedia, which calls it the native format of VirtualBox. |
| Container | One file with a text line, a header, a block map and data blocks. We tested the dynamic and the static kind. |
| Signature |
7F 10 DA BE at offset 64, after a text line of 64 bytes.
|
| Byte order | Little-endian in our files, and the Kaitai format file declares little-endian. |
| Header version | Version 1.1 in all 10 files, and a header size of 384 bytes. The qemu source accepts only version 1.1. |
| Image types | 1 dynamic and 2 static in the qemu source. The Kaitai format file adds 3 undo and 4 diff, and we had none of those. |
| Block size | 1 MiB in all 10 files. The qemu source rejects any other size. |
| Block map |
4 bytes per block. FFFFFFFF is unallocated and FFFFFFFE is discarded in the qemu source.
|
| Checksum | We found none in the header, the map or the data blocks of our files. |
| Readers | FileInfo lists Oracle VM VirtualBox, Aryson VDI Recovery and File Viewer for Android. We tested qemu-img, dissect and 7-Zip. |
About the values we list
Layout facts come from our own tests of 10 VDI files and from the pages we name. The Wikipedia page on VirtualBox gives the name and the supported formats. The FileInfo record for VDI gives maker and programs.
The qemu source and the Kaitai format file give the header fields and the image types. We did not use any VirtualBox specification, and we make no claim beyond what we list.
What we left out
We used no Windows machine and no VirtualBox. We did not test differencing files, undo files, encrypted disks, disks over 64 MiB, VirtualBox converters or web converters. We started no virtual machine. Our readers worked on Linux, and other software can accept or refuse files that they treat differently.
We made 9 of the 10 files with qemu-img, and all 10 show the text line of QEMU. So the files show how that tool writes VDI files. Our damaged copies come from one file and change one thing at a time. We compared full disks by SHA-256.
Sources checked
For the format name and supported formats, see Wikipedia on VirtualBox. For the file type, see FileInfo on the .vdi ending.
Our readers are qemu-img in the QEMU project and dissect.hypervisor from Fox-IT. The layout comes from the qemu source and the Kaitai format file linked above. Our public test file comes from dissect.hypervisor. 7-Zip is reader three.
Frequently Asked Questions About VDI Files
What is a VDI file?
A VDI file is the virtual hard disk of a VirtualBox machine. Wikipedia calls VDI the native disk format of VirtualBox, and FileInfo lists Oracle as the developer. All 10 of our test files end in .vdi, and they are two kinds.
What does VDI stand for?
VDI stands for Virtual Disk Image, per Wikipedia. FileInfo names the type VirtualBox Virtual Disk Image. The ending is also used by a Virtuo CD Manager disk image and a StepMania debug file, which we did not test.
How do I open a VDI file?
Oracle VM VirtualBox opens it, per FileInfo, and we did not test it. Without it, qemu-img, dissect and 7-Zip all opened all 10 of our files. Copy the file first, and compare more than one reader.
How do I convert a VDI file to a raw disk?
Use `qemu-img convert -f vdi -O raw disk.vdi disk.raw`. The raw file from our example had the same SHA-256 as the source disk. QCOW2, VMDK and VHDX gave the same bytes back, and VHD added 4,096 bytes of size. We tested no VirtualBox converter.
Why is my VDI file smaller than the disk?
A dynamic VDI file grows as data arrives. Our file for a 16 MiB disk has 3,146,752 bytes, because only 3 of 16 blocks have data. A static file has the full disk, and ours has 16,778,240 bytes. The header says which kind you have.
How do I find out if a VDI file is dynamic or static?
Print 16 bytes from offset 64 with `xxd -s 64 -l 16 file.vdi`. The last four bytes are the image type. Ours were `0100 0000` for a dynamic file and `0200 0000` for a static file.
Is a VDI file safe to open?
Opening one with a reader starts nothing. The risk is the disk inside, which can contain any file or private data. Our readers left every file unchanged. We started no virtual machine and scanned nothing for malware.
Why will my VDI file not open?
One cause is a different kind of .vdi file, which the signature at offset 64 shows. Others are damaged headers, bad counts, cut files and readers that treat files differently. Start with the first bytes, then work down the cause list in the part called Why Will Your VDI File Not Open.
Can I repair a damaged VDI file?
In part. Our repair script restored 10 of our 21 damaged copies, all of them header damage. It cannot restore cut files, a zeroed map or changed bytes. We did not test a repaired file in VirtualBox. Keep the original, and work on a copy.
Why do two readers give different results?
dissect gave the original disk on 9 of our 21 damaged copies, and qemu-img and 7-Zip gave it on 6. All 3 agreed on only 5. dissect opened files that qemu-img refused. We did not check what VirtualBox accepts.
Is a file that opens a good file?
No. Zeroing the block map gave another disk in all 3 readers with no error. Changing one byte at 24 places opened 24 times in qemu-img and dissect with no warning. Convert the disk to raw and compare hashes with known good copies.
Can I resize a VDI file?
VirtualBox can resize VDI and VHD images since version 4.0, per Wikipedia. We did not test it. Copy the file first, and compare hashes of the raw disk before and after, because we tested no resize.
Still Stuck With a VDI File? Where to go next, depending on what went wrong
Print the bytes at offset 64 and look at the signature. The cause list names what to try in order.
The cause can be the map or a block and not the header. The last causes name what we saw in copies C4 to C6.
Is it an archive of files? The page on ZIP archives covers the compressed archive.
Is it a database from the disk? The SQLITE file page covers the SQLite format.
Is it a generic data file? The DAT file page covers the .dat file type.
Is it a file type you do not know? Browse the file extension resource library, or send it on the submit a file type page.
Do you need the format facts? Use the format part for the layout and the sources of VDI files.