[Libguestfs] Read MBR and store in a file?

Jason A. Kates jason at kates.org
Fri Nov 22 16:34:34 UTC 2013


what about just using dd?
dd if=disk.img of=mbr bs=512b count=1


On Fri, 2013-11-22 at 16:24 +0000, Richard W.M. Jones wrote:
> 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.
> 


-- 
----------------------------------------------------------------------------
Jason A. Kates (jason at kates.org) 
Fax:    208-975-1514
Phone:  660-960-0070
============================================================================




More information about the Libguestfs mailing list