Change file in VDI without starting it.

Discussions related to using the OSE version of VirtualBox.
Post Reply
Monty
Posts: 1
Joined: 29. Jul 2016, 00:45

Change file in VDI without starting it.

Post by Monty »

Suppose, you got a instance running Windows XP, and there is a file called image.png in the C:\users\Monty\Documents path.
Is it possible to change the file image.png to another file, without VirtualBox?

I want to start a project and I want to create customizable VDI's of an existing VDI.

This is my first time working with VirtualBox as a developer, so I am not "advanced" in this ;)
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Change file in VDI without starting it.

Post by noteirak »

Moved to "VirtualBox OSE".

What you are trying to accomplish can be done using the VDI header files and looking into VirtualBox source code.
There are also projects that already do that so you could inspire from them.
Search a bit in this specific forum, you should be able to find them.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Change file in VDI without starting it.

Post by socratis »

What you want to do is to mount the VDI file as another disk in your OS (what is your OS?). You should be searching for "mount VDI". There is a project called "vdfuse" that works with FUSE. It's quite old (3 years as of this writing), but I don't believe that the VDI format has changed in the meantime (actually I would bet that it hasn't).

Take a look also at a really old, but still relevant discussion: viewtopic.php?f=2&t=21628

I would simply launch the VM, make the changes and be done with it...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
StanleyArms
Posts: 2
Joined: 18. Jan 2017, 18:21

Re: First

Post by StanleyArms »

I need a post in order to post about a link you can use, so hopefully this is it. I have software that will do exactly what you need. It will make the contents of the vdi file available for read and write from the host.

Stu
StanleyArms
Posts: 2
Joined: 18. Jan 2017, 18:21

Re: Change file in VDI without starting it.

Post by StanleyArms »

I built some Java code that can do what you need, i.e. make the contents of the vdi available to host processing.

https://github.com/UW-APL-EIS/vmvols-java

Aspects of that code are platform-indepedent, such as the parsers for reading vdi and vmdk disks, but for accesing that data through system calls on the host, you'll need a platform that uses FUSE, and that pretty much ties you to Linux, though I think MacOS can do FUSE too.

Here is what you'd do, on a Linux host at least. Say your VM is called X, and lives at /path/to/X. Then

$ cd vmvols-java/fuse
$ mkdir mnt
$ vmmount -w /path/to/X mnt

Normally I just use vmmount w/out the -w option, as I just want to walk the vdi's content from the host, but in this case, you wish to update it. Then

$ fdisk mnt/X/sda

or somehing similar to fdisk. I actually would use the 'mmls' tool from the Sleuthkit toolkit (available via apt, yum). You need to figure out the sector offset of the file system you want to mount, i.e. where an NTFS 'partition' lives within the 'whole disk'. Let's say it is 2048. Convert that to a byte offset, in this case 1048576. Then

$ mkdir C
# mount -o offset=1048576 mnt/X/sda C
$ ls C

You should now be able to read + write files under local directory C. When finished, do 2 umounts:

# umount C
$ fusermount -u mount

For all this, you need FUSE installed. On most modern Linux distros it is. It may also work on MacOS, I haven't tested.

Hope this helps.

Stuart
Post Reply