How to mount image files .img and .qcow2 format in Linux system


To explain the procedure to mount .img file, I have downloaded an img file named "ubuntu-16.04-server-cloudimg-amd64-disk1.img" from https://cloud-images.ubuntu.com/releases/16.04/release/

You can download the image file just by executing the below command
$ wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img

Install qemu-utils
$ sudo apt-get install qemu-utils
Load nbd module into system kernel
$ sudo modprobe nbd
Note: using modprobe command to load kenel modules doesn't ensure the module gets loaded into system when ever the system boots up. Follow instruction given in this Link to configure your system to load kernel modules in persistent way

Connect the image to the first nbd device
$ sudo qemu-nbd -c /dev/nbd0 ~/ubuntu-16.10-server-cloudimg-amd64.img

Mount the image. For nbd0, see all the devices available (/dev/nbd0<some-number-or-string>) and try attaching to starting from the first one
$ mkdir /tmp/aroot
$ sudo mount /dev/nbd0p1 /tmp/aroot
Accessing the image contents

In the previous step, the image has been mounted on /tmp/aroot directory, hence you can access or modify the image files as like the way you do in any Linux file system

$ ls /tmp/aroot 
Unmount the image
$ sudo umount /tmp/aroot
Disconnect the image
$ sudo qemu-nbd -d /dev/nbd0

Note:
  1. The same steps described above should work for mounting qcow2 image files

Post a Comment

2 Comments

  1. Top notch substance to get exact data's and i get a kick out of the chance to peruse this assortments of weblog submit for having composing data. that is well worth considering. For real the data ones are diverting to consider in light of the fact that it makes it additional like tension. i adore this content. it's far give more insights to me. Feel free to surf College paper writing service

    ReplyDelete
  2. During this website, you will see this shape, i highly recommend you learn this review. https://onohosting.com/

    ReplyDelete