I’ve used Clonezilla to backup and restore many a hard drive, but what if I just want to mount it and pull off data? Turns out, there is no good way to do this. However, using Arch Linux, one can backup and mount disk images using ddrescue.
I recently had a Clonezilla image that I wanted to mount like a hard drive. Of course, this is easier said than done. I ran the parts through gzip and created an image file, but I still could not for the life of me mount it. What I didn’t know is that ddrescue is built into the Arch Linux install disk.
The main instructions are all at “Guide to Using DDRescue to Recover Data – Technibble“. Basically, using this and some other guides I found, it is quite do-able.
First, you will need to boot into the Arch Linux install media and mount your destination (it is not advisable to mount the source, but we are going to create a directory to mount the image afterwards). Assuming you want to use /dev/sdc1 for the backup drive and your original data is on /dev/sda4:
mkdir -p /mnt/sdc1
mkdir -p /mnt/sda4
mount /dev/sdc1 /mnt/sdc1
Second, run ddrescue to create the image:
ddrescue -d -r3 /dev/sda mysda.img mysda.log
- -d only works on disks, and uses direct access. This is useful if the disk is damaged.
- -r3 gives 3 passes if it cannot read the data the first time. Again, useful if the disk is damaged.
- /dev/sda is the source disk. You can make your life easier by doing a partition instead, /dev/sda4 in our example system, depending upon what you are going to do with the results.
- mysda.img is the destination image file.
- mysda.log isn’t so much a log file as it is a means of tracking failures during the passes. If everything is successful the first time, then only one pass is needed. Otherwise, this file tells ddrescue which sectors to retry.
If the objective is to clone the image, then you can use dd to put it back:
dd of=mysda.img /dev/sda
If the objective is to mount the drive and read-write the data directly, then you have to watch partition boundaries. If you simply used ddrescue to pull of /dev/sda4 instead of the entire disk, then this should work:
mount -o loop mysda4.img /dev/sda4
If it is an NTFS partition, you might have to specify:
mount -t ntfs-3g -o loop mysda4.img /dev/sda4
However, if you created an image of the entire disk, it is a little more complicated. You will need to determine the offset of the partition:
fdisk -l mysda.img
Disk mysda.img: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Device Start End Sectors Size Type
/dev/sda1 2048 718847 716800 350M EFI System
/dev/sda2 718848 751615 32768 16M Microsoft reserved
/dev/sda3 751616 2430975 1679360 820M Windows recovery environment
/dev/sda4 2430976 212146175 209715200 100G Microsoft basic data
Notice the size of the sectors at the beginning. Most systems will have 512 bytes as the size. Then, look at your source, /dev/sda4, which starts at sector 2430976. Simply multiply them for your offset.
expr 512 \* 2430976
You can also use parted to avoid the math (bolded text is prompt):
parted mysda.img [Enter]
Unit? [compact]? B [Enter]
(parted) print [Enter]
Disk sda.img: 2000398934016B
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
4 1244659712B 108618842111B 107374182400B ntfs Basic data partition msftdata
So, you then use that offset to mount:
mount -t ntfs-3g -o loop,offset=1244659712 mysda.img /mnt/sda4