How to mount img in linux

How to Mount IMG Files in Linux

ISO images are often used to contain CD-ROM or DVD data, but Linux users will occasionally find themselves working with IMG files instead. These contain direct disk images, which can be worked with in a similar way. At one point these were generally used for writing an entire file system directly to a discrete diskette, but few people would ever wish to do that in today’s world. There are two major reasons modern Linux users would need to work with them, however. One is if an IMG file was used to distribute a driver or other piece of an operating system that needed to be restored. The IMG file can be mounted and the individual file from inside of it’s contained system could then be copied over to a booted file structure. The other reason, which is becoming extremely popular, is for working with virtual machines and other forms of hardware virtualization.

Linux provides several different ways to work with these contained structures. Depending on your distribution, you might be able to work with them in a purely graphical environment. The same CLI tools that mount ISO images could also mount IMG if this isn’t possible for you, however.

Method 1: Mount With Graphical Menus

If you’re using PCManFM or another file manager that supports mounting an image directly via the /media folder with a menu driven system such as some versions of Nautilus, then you should hold launch your manager to start. You’ll either need to launch this from the Panel Menu in LXDE or from the Applications menu in GNOME. Once you’re open, navigate to the Downloads folder by clicking the link in the left panel and then right click on the disk image you downloaded. It’s generally smart to have ensured that your browser didn’t detect any malware before proceeding.

picture-a

Once the context menu appears, select the “mount disk image” option. The label for this command will change depending on your particular distribution. The image will automatically mount at /media/USERNAME/disk, with USERNAME being replaced with your actual user name. Click on the left panel of the file manager where it reads the size of the image in question. In our example we used an image of an older Linux distribution called tomsrtbt (pronounced Tom’s Root Boot), which fit an entire operating system in less than three megabytes. Hence the “2.9 MB Volume” label refers to the image in question.

picture-b

You may now drag or right click and copy any of these files to any other section of your file system for safekeeping. When you’re done you can click on the X logo next to the label to close it. If you’re using a file manager that doesn’t support this method of unmounting an image, then start the GNOME Disks utility from the Panel Menu or the Applications tab. Click on the device that has the same name as the label from the file manager and then click on the square stop button to close down the file system.

Читайте также:  Узнать где лежит python linux

picture-c

Method 2: Via the Loopback Device

Disk images could be mounted via the loopback device as well, in much the same way as ISO images can be. This technique will be necessary if you use Thunar, Konqueror or any other file manager that doesn’t support direct mounting via graphical techniques. If you haven’t been able to mount an image graphically, then hold down CTRL, ALT and T at the same time. Type ls /mnt to make sure your /mnt directory is empty. If it’s not or if you don’t feel comfortable using it directly, then you can use sudo mkdir /mnt/toms to create a mountable directory. You could theoretically call the directory whatever you’d like. Type sudo mount -o loop tomsrtbt-2.0.103.ElTorito.288.img /mnt and press enter. You will be prompted to enter your password, which you will be required to do. The /mnt directory can then be explored via the CLI or the file manager you prefer. Naturally you’ll need to replace tomsrtbt-2.0.103.ElTorito.288.img with the image you’re using and /mnt with the directory tree segment you’re using.

picture-d

Hold down CTRL and E to open your graphical manager or start it from the Applications or Whisker menu depending on which desktop environment you are using. Select the File System option from the left pain, navigate to /mnt and then select the /mnt folder. You’ll now be able to examine the contents of the image file.

picture-e

At the CLI type sudo umount /mnt and press enter to umount the image. You would need to substitute whatever mount point you used for /mnt when you do so.

Источник

Create, Mount And Unmount .img Files In Ubuntu

Recently I moved from Windows to Ubuntu on one of my laptops and since then I was trying to look for the way to create a VHDs or some sort of image files that I can use as a container. So I looked up for the solution and found a working solution scattered though places. So here I am putting it in a blog post to have all it in one place.

First we need to create an image file (.img) by using the dd command. The dd command is used to copy and convert the file. The reason it is not called cc is because it is already being used by C compiler. Here goes the command.

$ dd if=/dev/zero of=cdata.img bs=1G count=5

Note: The command execution time depends on the size of the image you have opted out for.

dd command

The if param stands for input file to refer the input file. As if , of stands for output file and this will create the .img file with the name you specify. The third param bs stands for block size . This will let you set the size of the image file. The G in the above command stands for GigaByte (GB). You can set the image size by specifying the block size. In this case G stands for GigaBytes (GB), K for KiloBytes (KB), T for TeraBytes (TB), P for Petabytes (PB) and so on. Here I am creating a 5 blocks of 1 GB each for the image file name cdata .

Читайте также:  Linux режим восстановления системы

This command will create the .img file but you cannot mount this file as of yet. To do that you have to format the image so that it can have a file system. To do this make use of mkfs command.

I am creating an ext3 filesystem on my image file. -F is to force the operation. Here is the output of the command.

mkfs command

Now we can mount the image file by using the mount command:

$ sudo mount -o loop cdata.img ~/Desktop/HDD/

With the success of the above command, you can see the image mounted on your desktop. You can unmount the image by clicking the eject or unmount button as shown in the below screenshot or you can execute the umount command to do that.

disk mounted

Unmounting the image by using command line.

Источник

How to Mount Disk Image (*.img) File on Linux

In some cases, we need to mount disk image to modify O/S files. Let’s review the Mount Disk Image (*.img) File on Linux.

There are many cases I used and remember one of them during the ODA VM Cloning process to get zero down time I change the IP configuration to not get IP conflict.

Mount Disk Image (*.img) File on Linux

[[email protected] test]# losetup -f /dev/loop0 [[email protected] test]# losetup /dev/loop0 System.img [[email protected] test]# kpartx -a /dev/loop0 [[email protected] test]# vgscan Reading all physical volumes. This may take a while. Found volume group "vg_crpapp" using metadata type lvm2 [[email protected] test]# vgchange -ay vg_crpapp 2 logical volume(s) in volume group "vg_crpapp" now active [[email protected] test]# ls -lrt /dev/mapper/vg_crpapp* brw-rw---- 1 root disk 252, 67 Nov 5 16:32 /dev/mapper/vg_crpapp-lv_swap brw-rw---- 1 root disk 252, 66 Nov 5 16:32 /dev/mapper/vg_crpapp-lv_root [[email protected] test]# mkdir /image [[email protected] test]# mount /dev/mapper/vg_crpapp-lv_root /CRP2/ vi /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet BOOTPROTO=none IPADDR=1.1.1.2 PREFIX=24 GATEWAY=1.1.1.1 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="eth0" UUID=60ba15ca-4460-40bf-9ae5-c041539f83ad ONBOOT=yes DEVICE=eth0 USERCTL=no LAST_CONNECT=1471983821

Источник

How to mount a disk image from the command line?

I know how to mount a drive that has a corresponding device file in /dev, but I don’t know how to do this for a disk image that does not represent a physical device and does not have an analogue in /dev (e.g. an ISO file or a floppy image). I know I can do this in Mac OS X by double-clicking on the disk image’s icon in Finder, which will mount the drive automatically, but I would like to be able to do this from the terminal. I’m not sure if there is a general Unix way of doing this, or if this is platform-specific.

Читайте также:  Session manager for linux

Do you mean you want to do it on the command line on OS X? You mention it, but it might be better to be explicit if the question is specific to a certain os. Also, what type of a disk image do you mean? .iso?

4 Answers 4

If it was a hard-drive image with a MBR partition table, I would fdisk the image to find the offset for the partition I need to mount.

Then I would mount it passing the offset.

mount -o loop,offset=xxxx /path/disk.img /mnt/disk.img.partition 

The offset value is in bytes, whereas fdisk shows a block count, so you should multiply the value from the «Begin» or «Start» column of the fdisk output by 512 (or whatever the block size is) to obtain the offset to mount at.

+1 This is the solution that worked for me. Thank you for including details on how to calculate the offset as well.

On most modern GNU system the mount command can handle that:

mount -o loop file.iso /mnt/dir 

to unmount you can just use the umount command

If your OS doesn’t have this option you can create a loop device:

losetup -f # this will print the first available loop device ex:/dev/loop0 losetup /dev/loop0 /path/file.iso #associate loop0 with the specified file mount /dev/loop0 /mnt/dir #It may be necessary specify the type (-t iso9660) 
umount /mnt/dir losetup -d /dev/loop0 

If the file have partitions, example a HD image, you can use the -P parameter (depending on you OS), it will map the partitions in the file content:

losetup -P /dev/loop0 /path/file.iso # will create /dev/loop0 ls /dev/loop0p* #the partitions in the format /dev/loop0pX 

losetup and mount -o loop are Linux specific. It won’t work on GNU distributions using a different kernel (like hurd, illumos or kFreeBSD though illumos and FreeBSD will have the equivalent with a different syntax)

I don’t understand the meaning of a «loop device» nor why you need -o loop to mount the image file as one. Can you explain please? I see the Wikipedia link but still don’t understand. I have an embedded Linux rootfs.ext2 roof filesystem image, and it doesn’t seem to make any difference when I mount it with vs without -o loop to inspect the files.

losetup -P automation for multi partition images

How to mount a disk image from the command line? | Unix & Linux Stack Exchange mentioned losetup -P , and here are some handy Bash functions to further automate things. Usage:

$ los my.img /dev/loop0 /mnt/loop0p1 /mnt/loop0p2 $ ls /mnt/loop0p1 /whatever /files /youhave /there $ sudo losetup -l NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO /dev/loop1 0 0 0 0 /full/path/to/my.img $ # Cleanup. $ losd 0 $ ls /mnt/loop0p1 $ ls /dev | grep loop0 loop0 
los() ( img="$1" dev="$(sudo losetup --show -f -P "$img")" echo "$dev" for part in "$dev"?*; do if [ "$part" = "$p*" ]; then part="$" fi dst="/mnt/$(basename "$part")" echo "$dst" sudo mkdir -p "$dst" sudo mount "$part" "$dst" done ) losd() ( dev="/dev/loop$1" for part in "$dev"?*; do if [ "$part" = "$p*" ]; then part="$" fi dst="/mnt/$(basename "$part")" sudo umount "$dst" done sudo losetup -d "$dev" ) 

Источник

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