Ubuntu Disk Image Manipulation

From richud.com
Jump to: navigation, search

Manipulating Disk Images

Initial preparation

Add yourself to disk group

First thing you need to do is add yourself (USERNAME) to the 'disk' group to get anything done easily. This will let you manipulate block devices like /dev/loop

sudo usermod -a -G disk USERNAME

Install hexedit

sudo apt-get install hexedit

Install ms-sys

This is for creating the boot sectors (and changing the MBR's if you wish) ms-sys is available here

cd ~
wget http://prdownloads.sourceforge.net/ms-sys/ms-sys-2.2.1.tar.gz
tar zxvf ms-sys-2.2.1.tar.gz
cd ms-sys-2.2.1
make

You can then run it from ~/ms-sys-2.2.1/bin/ms-sys

Image types

Simplistically the MBR is the first 512 bytes of data on the disk, the first part is the boot code, the last part the partition table. They can exist without the other, which can be useful.

  • I am going to try and explain this using userspace mounting only (rather than needing root with sudo). Images are mounted on a special block device /dev/loopX (X is a number starting at 0). If you ls -al in /dev/ you will see the loopX and sdX devices are part of the 'disks' group. A good idea may be to add youself to that (sudo usermod -a -G username disks)
  • To find out what type of image you are dealing with use 'file'

Small and simple images (Floppy/Superfloppy)

  • Filesystem begins right at the start of the image
$file /tmp/itkclean.img 
/tmp/itkclean.img: x86 boot sector, Microsoft Windows 98 Bootloader IO.SYS+MSDOS.SYS, code offset 0x3c, 
OEM-ID "*V+|LIHC" cached by Windows 9M, sectors/cluster 2, root entries 240, sectors 5760 (volumes <=32 MB) ,
 sectors/FAT 9, serial number 0x18ec2374, label: "BOOT98SC   ", FAT (12 bit)

To create floppy images with an MBR see here

Larger images with an MBR

  • Image with a MBR inc partition table.
$file /tmp/DQ45CB.IMA 
/tmp/DQ45CB.IMA: x86 boot sector, Microsoft Windows XP MBR; partition 1: ID=0x1, active, starthead 1,
 startsector 32, 32736 sectors, code offset 0xc0

To create hard drive images with an MBR see here

External Links

FAT16 structure info FAT32 structure info ms-sys for creating the boot sectors