[Libguestfs] Read MBR and store in a file?

Richard W.M. Jones rjones at redhat.com
Fri Nov 22 16:24:13 UTC 2013


On Fri, Nov 22, 2013 at 01:58:24PM +0000, adrelanos wrote:
> Hi!
> 
> Is it possible to read the MBR of an image and to store it inside a file?

Yes, easily :-)

  guestfish --ro -a disk.img run : pread-device /dev/sda 512 0 > mbr

This will work for any format of disk.  Of course for a raw format
disk this is just a slower way of reading the first 512 bytes from the
raw file.

Since what you want are simply virtual sectors from a disk image, it
could be quicker to use qemu-io.  Something like this:

  qemu-io -c 'read -v 0 512' disk.img

(Unfortunately the format returned by qemu-io is a hexdump which is
not exactly useful ...  I can't work out how to get it to dump the raw
bytes but there may be a way.)

> (If you want to know what I really want to do:
> Creating a report on all contents of an vm image. [1] [2] Create the
> image on two different machines, compare them and see, that there are
> no important differences besides temporary files.)
> 
> Cheers,
> adrelanos
> 
> [1] https://github.com/Whonix/Whonix/issues/113
> [2] https://github.com/Whonix/Whonix/blob/master/release/analyze_image

You might also want to take a look at virt-ls (although that *only*
compares files, not the other data outside the filesystem):

http://libguestfs.org/virt-ls.1.html#differences-in-snapshots-and-backing-files

I keep meaning to write a comprehensive "virt-diff" tool.  I needed it
myself just yesterday.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list