- Mounting a raw partition file made with dd or dd_rescue in Linux
- Mounting Raw and qcow2 Images
- Mounting The Raw Image
- Unmounting The Raw Image
- Mounting The qcow2 Image
- Unmounting the qcow2 Image
- andremiller.net
- Mounting Disk Image in Raw format
- 3 Answers 3
- Tutorial: How to mount raw images (.img) images on Linux
Mounting a raw partition file made with dd or dd_rescue in Linux
This situation might not affect everyone, but it struck me today and left me scratching my head. Consider a situation where you need to clone one drive to another with dd or when a hard drive is failing badly and you use dd_rescue to salvage whatever data you can.
Let’s say you cloned data from a drive using something like this:
Once that’s finished, you should end up with your partition table as well as the grub data from the MBR in your image file. If you run file against the image file you made, you should see something like this:
What if you want to pull some files from this image without writing it out to another disk? Mounting it like a loop file isn’t going to work:
The key is to mount the file with an offset specified. In the output from file , there is a particular portion of the output that will help you:
This means that the filesystem itself starts on sector 63. You can also view this with fdisk -l :
Since we need to scoot 63 sectors ahead, and each sector is 512 bytes long, we need to use an offset of 32,256 bytes. Fire up the mount command and you’ll be on your way:
If you made this image under duress (due to a failing drive or other emergency), you might have to check and repair the filesystem first. Doing that is easy if you make a loop device:
Once that’s complete, you can save some time and mount the loop device directly:
Источник
Mounting Raw and qcow2 Images
Mounting Raw and qcow2 images in order to inspect and use them doesn’t have to be difficult. After searching the internet, we found a couple of recommendations on how to do it. Here is what we did ourselves on an Ubuntu 16.04 Linux host.
Mounting The Raw Image
Associate the raw image with a loop device:
Map the partitions to loop devices:
You should be able to mount the partitions now:
where /mnt/t01 is a previously-existing mount point or directory.
For LVM partitions, determine the volume group name and activate it:
Mount the desired logical volume:
where /mnt/t02 is another pre-existing mount point or directory.
Unmounting The Raw Image
Unmount the previously mounted partitions:
Deactivate the volume group:
Undo the mapping of the partitions to the loop devices:
Destroy the loop:
Mounting The qcow2 Image
Here, we shall use the QEMU Network Block Device Driver for the purposes of mounting the qcow2 image.
First, load the nbd driver.
Connect nbd to the image using qemu-nbd:
Using fdisk, check the existing partitions. Mount the regular Linux partitions as is:
For LVM partitions, associate a loopback device to the LVM partition:
See the LVM partitions under /dev/mapper:
You should also be able to display the logical partitions using lvdisplay and the volume groups with vgdisplay. Use vgchange as above to activate the volume group.
Mount the regular LVM partitions as usual:
Unmounting the qcow2 Image
Unmount the partitions from the qcow2 image:
Deactivate the volume group:
Remove the loopback device:
Disconnect the nbd device:
Finally, remove the nbd kernel module:
We have successfully used the above procedures in mounting and unmounting raw and qcow2 images used in Linux KVM.
The procedures described above have been adapted for this article from these URLs:
Источник
andremiller.net
A while ago I thought it would be a good idea to make a backup of my Linux server by just dumping the complete disk to a file. In retrospect, it would have been much easier had I just dumped the individual filesystems.
When I finally got around to using this backup, long after the 10GB disk had perished I realized that to use the loopback device to mount a filesystem it actually needs a filesystem to mount. What I had was a disk image, including partition table and individual partitions. To further complicate matters the data partition was also not the first partition inside this image.
For reference, I created this image using the Unix ‘dd’ tool:
I followed the instructions on http://www.trekweb.com/
jasonb/articles/linux_loopback.html to try and mount the partitions inside the disk image, but ran into two problems.
To mount a partition inside the disk image you need to calculate the offset of where the partition starts. You can use fdisk to show this information to you, but you need to specify the number of cylinders if you are using a disk image.
You then also need to multiply the start and end numbers with the calculated sectors to get a byte offset.
I found another tool more useful for this task, called parted. If you are using Ubuntu, you can install it with ‘apt-get install parted’
Now we have the offsets and we can use those to mount the filesystems using the loopback device:
That mounted the first partition, the ‘boot’ partition, but this didn’t have the data on it that I was looking for. Lets try to mount partition number 3.
Oops, that doesn’t look right. According the article referred to above if you are using a util-linux below v2.12b then you cannot specify an offset higher than 32bits. I’m using util-inux 2.13 which shouldn’t have that problem, and besides, my offset is well below the 32bit limit.
The article also offers an alternative loopback implementation that supports mounting partitions within an image, but that requires patching and recompiling your kernel which I would rather not do.
Instead I decided to extra ct the filesystem from the image which would then allow me to mount it without specifying an offset.
Doing this is quite straightforward with ‘dd’. You need to give ‘dd’ a skip count, or, how far into the source to start copying, and a count, how much to copy.
Here you can either use the single byte offsets retrieved with parted or divide them by 512 and let ‘dd’ use 512 byte blocks. Copying just one byte at a time takes a very long time, so I suggest using a larger block size.
Here is the command I used to extract my filesystem. Skip is 2313360 (1184440320/512) and Count is 17719695 (9072483840/4)
After extracting the filesystem I was able to mount it without any problems.
Источник
Mounting Disk Image in Raw format
While trying to mount a disk image in Raw(dd) format using the following command
I get the following error message
I know that using -t we can specify the file system but what is the terminology for a RAW (dd) file, which can be passed as an argument to the mount command. If my method to mount this file system is wrong please help me out in doing the same.
3 Answers 3
From http://major.io/2010/12/14/mounting-a-raw-partition-file-made-with-dd-or-dd_rescue-in-linux/, there’s a suggestion to use an offset. First obtain the offset via fdisk(8) and then specify it with the offset option to mount . Use fdisk to determine the starting sector of the partition and the sector size. Then calculate offset in bytes using the starting sector number and sector size in bytes. See Mount single partition from image of entire disk (device) for an example. Finally:
In a typical hard disk, the cells holding the data are grouped. The groupings are called sectors. The way we usually partition things, the first few sectors are kept aside for giving information about the partitions, leaving a gap. So if we have an image of an entire disk, these sectors also get included. Now, the mount command cannot directly start at the first byte, as the partition doesn’t start at the first byte. So, we will have to tell mount how many bytes to skip (so that it can avoid the extra information)and get to the actual partition. This is called the offset. Now each sector can store a certain amount of information in bytes, which is called the size of a sector. We take the total size of information that can be stored in this gap by multiplying the size of a sector, with the size of the gap in number of sectors.
From the output of fdisk there, you can see the sector size is 512 bytes and it starts at sector 1. So the offset is 1*512=512. Try the following command:
I added the filesystem type since fdisk gave it as FAT32. To mount it for writing as well, use -o offset=512,rw instead.
Источник
Tutorial: How to mount raw images (.img) images on Linux
If you have a few .img files coming as disk images from devices like floppies, CDs, DVDs, SD cards, etc, you will realize that you cannot mount the in Linux, because they contain a file system that has to be mounted.
In linux you would need to use the mount command as for any physical device, however you need to know the correct syntax that is based on understanding the information related to the partition(s) available in the image.
First step is to read the partition Start point using fdisk:
In the terminal type:
sudo fdisk -l imgfile.img
You will see an output similar to the one below:
Device boot Start End Blocks Id System
imgfile.img1 * 63 266544 722233 C W95 FAT32 (LBA)
imgfile.img2 25679 25367890 245667890+ 83 Linux
As you can see there are two partitions, one that is FAT32 and the other one that it’s ExtFS. This means that to mount the first partition we have to tell Linux that we need to start at the sector 63. The standard sector size is 512 bytes, however there are other possibilities like 128 or 1024. Assuming that the place from where you are downloading the image doesn’t specify any sector size, we can type in the terminal:
sudo mount -t vfat -o loop,offset=$((63 * 512)) imgfile.img /mnt/disk
To mount the second partition, as you can imagine:
mount -t ext4 -o loop,offset=$((25679 * 512)) imgfile.img /mnt/disk1
It’s important to copy the “Start” sector number correctly, otherwise you’ll get an error message like:
mount : wrong fs type, bad option, band superblock on /dev/loop,
missing codepage or helper proggram, or other error
In some cases useful info is found in syslog – try
dmesg | tail or so
One last thing, the standard sector size for CDs and DVDs is 2352 instead of 512. If you are opening such image, you’ll have to use this value instead of 512.
Источник