How to mount an img file on Linux

Source: Internet
Author: User


One, some files can be mounted directly, not boot files, just img files,

LOSETUP/DEV/LOOP1 zenith.img

Kpartx-av/dev/loop1

mount/dev/loop1/mnt/zenith/


Second, if the system disk is virtual machine, the direct mount may be problematic, choose to mount the corresponding LV

# Fdisk-ul Xxx.img

Disk 3059.img:4294 MB, 4294967296 bytes

255 heads, Sectors/track, 522 cylinders, Total 8388608 sectors

Units = sectors of 1 * MB = bytes

Sector size (logical/physical): bytes/512 bytes

I/O size (minimum/optimal): bytes/512 bytes

Disk IDENTIFIER:0X000BDBDC

Device Boot Start End Blocks Id System

3059.IMG1 * 7903979 3951958+ Linux

3059.img2 7903980 8385929 240975 5 Extended

3059.img5 7904043 8385929 240943+, Linux Swap/solaris


From the above information can be seen, starting from 63, where the LVM disk starts from 7904043.

This information is available, sector size is 512

Units = sectors of 1 * MB = bytes

So we need to start from the 512*63 and mount it.

Final execution:

(sudo) mount-o loop,offset=32256 xxx.img/mnt/xxx ...

# ls/mnt/

config-2.6.32-279.el6.x86_64 initramfs-2.6.32-279.el6.x86_64.img system.map-2.6.32-279.el6.x86_64

EFI Lost+found vmlinuz-2.6.32-279.el6.x86_64

Grub SYMVERS-2.6.32-279.EL6.X86_64.GZ

This mounts the first disk, which may not be the system we want. So you should mount the following LVM


[Email protected] file]# Fdisk-lu centos.img

You must set cylinders.

You can do this from the extra functions menu.

Disk centos.img:0 MB, 0 bytes

255 heads, sectors/track, 0 cylinders, Total 0 sectors

Units = sectors of 1 * MB = bytes

Sector size (logical/physical): bytes/512 bytes

I/O size (minimum/optimal): bytes/512 bytes

Disk identifier:0x0001905c

Device Boot Start End Blocks Id System

CENTOS.IMG1 * 2048 1026047 512000 Linux

Partition 1 does not end on cylinder boundary.

Centos.img2 1026048 62914559 30944256 8e Linux LVM

Partition 2 has different physical/logical endings:

phys= (1023, 254, logical=) (3916, 63, 51)

[[email protected] file]# echo $ ((1026048*512))

525336576

[Email protected] file]# LOSETUP/DEV/LOOP3 centos.img-o 525336576

[Email protected] file]# Pvscan

PV/DEV/MAPPER/LOOP0P2 VG VolGroup lvm2 [29.51 gib/0 Free]

Total:1 [29.51 Gib]/in use:1 [29.51 GIB]/in no vg:0 [0]

[Email protected] file]# Vgchange-ay VolGroup

2 Logical Volume (s) in volume group ' VolGroup ' now active

[[email protected] file]# LVS

LV VG Attr lsize Pool Origin data% Move Log cpy%sync Convert

Lv_root volgroup-wi-a-----27.54g

Lv_swap volgroup-wi-a-----1.97g

[Email protected] file]# mount/dev/volgroup/lv_root/mnt/

[Email protected] file]# ls/mnt/

Bin Dev Home lib64 media opt root selinux sys usr

Boot etc lib Lost+found mnt proc sbin SRV tmp var



This will mount the LVM to the corresponding system and then you can modify the system files.

In the example above, the final steps are to see if the profile area is really a KVM host. After the mount has been used, it can be uninstalled and deleted by the following methods


[Email protected] file]# umount/mnt/

[Email protected] file]# Vgchange-an VolGroup

0 Logical Volume (s) in volume group ' VolGroup ' now active

[Email protected] file]# losetup-d/DEV/LOOP3


How to mount an img file on Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.