Linux opening img files

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:

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.

Incoming search terms:

  • https://stefanoprenna com/blog/2014/09/22/tutorial-how-to-mount-raw-images-img-images-on-linux/
  • how to mount raw img disk linux

Источник

How would I extract a .img file

I am trying to extract a .img file (hard disk image with with Chromium OS on it). I have not been able to find any way to do this other than mounting it but that is not usable because it shows up as multiple drives so I cannot repack it.

5 Answers 5

You do not extract an .img ; you mount it. Example:

mkdir /mnt/ChromeOS mount -o loop image.img /mnt/ChromeOS/ 

and this will list the contents:

Читайте также:  Да винчи резолв линукс

Mind that .img can also be zipped. If that is the case (unlikely though) you also need to gunzip it.

This does not work if the img contains multiple partitions, at least it fails for me. Using kpartx works instead.

You can use kpartx — create device maps from partition tables

Install the package kpartx and run

kpartx [-a | -d | -l] [-v] wholedisk 

DESCRIPTION

This tool, derived from util-linux’ partx, reads partition tables on specified device and creates device maps over partitions segments detected. It is called from hotplug upon device maps creation and deletion.

EXAMPLE

To mount all the partitions in a raw disk image:

You can clone from the image file to a drive

You can clone from the .img [image] file to a drive, for example a USB pendrive, that is big enough. This is the basic intention of the file.

You can use mkusb for that purpose. It works with compressed image files too (when compressed with gzip and xz ), .img.gz and .img.xz files.

After the cloning you will see the partitions for example with

sudo lsblk -f sudo lsblk -m sudo parted -ls 

After cloning you can mount and unmount the partition(s) on the drive ‘as usual’.

Источник

How to view .img files?

I’m trying find software to view .img files. But its not expected. .img file its not all images, it contains some values too. So I would like to view the .img file. Please advise any software like that.

Are these DICOM (medical) images, by any chance? Sometimes that extension is used for that realm. Use a hex viewer to look for the 4CC of ascii DICM at offset 128.

definitely not programming (belongs on superuser.com or something), definitely not related to processing images that are pictures (entirely wrong tags). this appears to be about disk/VM «images», which are containers for file systems. voting to close. why would anyone ever put a bounty on this?

12 Answers 12

If you want to open .img files, you can use 7-zip, which is freeware.

Once installed, right click on the relevant img file, hover over «7-zip», then click «Open Archive». Bear in mind, you need a seperate program, or Windows 7 to burn the image to disc!

Edit: Proof that it works (not my video, credit to howtodothe on YouTube).

@matt-maclennan, I was checking Android ROM .img files. Still 7-zip is not compatible to open/extract them.

.img is way too unspecific. This file extension is widely used for a variety of (raw) file formats. It is an abbreviation for “image” and that can be any image you can imagine—or cannot imagine at all, as you have never heard of it.

Читайте также:  Install wiki on linux

For example, .IMG used to be a GEM bitmap image file. Does anyone remember GEM at all? It was the Windows competitor from Digital Research. The Atari ST version was widely used, but there was also a DOS version of GEM. One of the stripped down versions (which was necessary to avoid copyright claims from Apple) was ViewMAX included in DR DOS 3.41, 5.0 and 6.0 as well as Novell DOS 7.0. It is now open source and can be downloaded freely as OpenGEM. Still requires DOS and is included in the FreeDOS distribution. For viewing GEM bitmap images, Windows programs of that time (around DOS-based Windows 3.0) such as Ventura Publisher could open and consequently convert such “GEM images” or “Atari ST images” into other, more widely used formats.

But I doubt that this kind of .img -file is what you meant. Still, you have to be more specific.

Most widely .img is used as a raw filesystem image of e.g. a floppy disk. As mentioned by others, such images can be opened by a number of programs. Or directly mounted under Unix-like systems like BSD and Linux. 7-Zip is also able to extract files from such images for supported filesystems, such as FAT. At least the command-line version. Just type 7z x image.img and it will extract the included files.

Note however that there are also other image formats out there, such as IBM’s .dsk , sometimes using different file extensions. Such files can be raw floppy images, but they can also be in IBM’s SAVEDSKF/LOADDSKF format. These files are basically raw files with stripped zeros at the end, but with a header at the beginning of the files. I doubt that 7-Zip can extract such images, even though it would only be necessary to find the appropriate offset. Anyhow, since the image past the header is basically raw and uncompressed, using dd you can extract the image and make it a raw .img floppy image. Suppose the header is hex:291 bytes long (which you will have to figure out by looking inside the file e.g. using a hex editor). This equals 657 bytes to skip, resulting in dd if=image.dsk of=rawimage.img bs=1 skip=657 . The resulting rawimage.img would however be non-standard in size. This can be fixed, again, by using dd. dd if=/der/zero of=rawimage.img count=0 bs=1 seek=1474560 – this will make a sparse file out of it, resulting in the correct file size for a 1.44 MB floppy image and returning zeros at unused positions. Works with most programs under Linux.

But in general, .img can be any file that is classified as “an image”, thus any application can include a (proprietory) file with this extension. Such files can than only be used (opened) by said application.

Читайте также:  Linux show used memory

Источник

How can I open binary Android ROM image files? (.img)

I’m a Windows/Mac/Ubuntu and Android user, so I know what I’m talking about, when I say: How do I open binary image files? (.img) They just won’t open, on any OS… I’m an Android dev… I’m currently working on a ROM, (I also program, using Windows) but I need to extract files, from .img files. I’ve converted them to .ext4.img but they just aren’t recognized by Linux (Definitly not by Android), by Mac OS or Windows. In other words, I can’t open, extract or mount them. Can anyone help me? I’m kinda confused…

the fact that the person with the most useful answer has to first guess what your question really is about, says it all. Please try to ask a more specific and detailed question than ‘How do I open binary image files’.

5 Answers 5

Short Answer is, there are 3 types:

  • Regular filesystem images, that can be mounted with -o loop option
  • YAFFS2 filesystem images, which currently cannot be mounted in Ubuntu and have to be unpacked
  • EXT4 filesystem images that have been further processed by the Android toolchain and need to be converted to regular images with simg2img from the Android toolchain.

So, you have a binary image extracted from an Android device, is that correct?

What does the file command say about the file? Something like this?

$ file system.img system.img: VMS Alpha executable 

That system image is extracted via nandroid from a Samsung Galaxy i7500. Most of those old Android devices used yaffs as a file system. Knowing what you are dealing with greatly helps. (i.e. Which device are we talking about? Where is that image from?)

Converting images into other file systems will only produce garbage at best if you do not have installed support for the file system in question. Unfortunately there is no package for Ubuntu. But that question has already been asked and answered: Create yaffs2 file system on Ubuntu Server 11.10

There is also the possibility that this image is encrypted. But why would someone give you an encrypted image?

Since this is mostly about Android and you call yourself an Android Developer, please read the Android documentation, again. It’s supposed to be all in there. If not ask your question at android.stackexchange.com, XDA-Developers, RootzWiki and the like. And please do not put a ROM on the net for hundreds of people to use unless you REALLY know what you are doing and you read the documentation. Doing it for fame is dangerous and bad for the users!

Источник

Оцените статью
Adblock
detector