Articles

How to mount an HDD image

In Uncategorized on 20/04/2010 by pier0w

In linux it is very easy to create and mount and HDD image. No need for Nortan Ghost or anything like that.

To create the image firat decide on whether you want to image the whole HDD or just a single partition.

Note: All the commands bellow must be run as root unless specified otherwise.

If you want to image the whole drive it can be done simply, first list your drives with fdisk and select the one you want.

# fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x35dc388f


Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 7 HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 19458 156185600 7 HPFS/NTFS


Disk /dev/sdb: 160.0 GB, 160000000000 bytes
255 heads, 63 sectors/track, 19452 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x9e499e49


Device Boot Start End Blocks Id System
/dev/sdb1 * 1 19452 156248158+ 7 HPFS/NTFS


Disk /dev/sdc: 160.0 GB, 160000000000 bytes
255 heads, 63 sectors/track, 19452 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xbb15bb15


Device Boot Start End Blocks Id System
/dev/sdc1 * 1 19330 155268193+ 83 Linux
/dev/sdc2 19331 19452 979965 82 Linux swap / Solaris

For this example we’ll image the first HDD /dev/sda, this is done with the following command:


# dd if=/de/sda of=sda.img bs=512

This command is using dd to image the whole drive, it is broken down as follows:

dd - The application that will make the image. All this app does is do a straight copy of the bits from one location to another.
if - The input for the dd command, so this tells dd where to copy the bits from. We have told dd to copy the whole of the first HDD. This can be seen because we have given dd the device file of the HDD not any of it's partitions e.g. /dev/sda1
of - The output for the dd command, this tells dd where to copy the bits to. In this case we have specified a file.
bs - The block size that dd uses when coping, this tells dd the size of the chunks it should use when copying. Here we have told dd to copy the bits 512 at a time. It is much faster than copying 1 bit at a time.

Now that we have an image we can mount it, well actually we can mount the partitions within the image. So first we need to find out where the partitions reside within the file. To do this we will use the parted application.
Note: You do not need to be super user for this command.

~ parted sda.img unit s print
WARNING: You are not superuser. Watch out for permissions.
Model: (file)
Disk /home/karl/Backup/Software/winxp.img: 4194892800B
Sector size (logical/physical): 512B/512B
Partition Table: msdos


Number Start End Size Type File system Flags
1 32256B 4194892799B 4194860544B primary ntfs boot

This command uses the parted program to inpect the HDD image for partition information. The command is broken down as follows:

parted - The parted application, this is a very powerful command line partitioning program. Use it with care.
sda.img - The path to our HDD image that we wish to inspect.
Now we start the commands for parted. If we had put nothing here we would have entered parted's command line and we could have entered the commands on after the other there.
unit B - Unit sets the block size that parted represents its output in. We have selected 'B' for Bits that is it will display the size of the partitions in 1bit chunks.
print - This just tells parted to print the partition information.

Now that we know the start and end values of the partition we can mount it:

# mount -o loop,ro,offset=32256 sda.img /mnt/image

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: