EmuELEC/img 镜像

EmuELEC/img 镜像

获取 img 镜像内容

需要在 Linux 下操作。


[/mnt/android_img]@OS $foo
-> file system.raw.img 
system.raw.img: Squashfs filesystem, little endian, version 4.0, 471060833 bytes, 1605 inodes, blocksize: 131072 bytes, created: Mon Aug 20 08:29:25 2018


[/mnt/android_img]@OS $foo
-> sudo unsquashfs -d root system.raw.img
[sudo] password for foo: 
Parallel unsquashfs: Using 48 processors
1316 inodes (9847 blocks) to write

[===============================================================================================================================\] 9847/9847 100%

created 1140 files
created 289 directories
created 176 symlinks
created 0 devices
created 0 fifos
[/mnt/android_img]@OS $foo
-> ls
root  system.raw.img  vendor.raw.img

直接获取 img 镜像里文件


7z 可以直接打开 img 镜像。对于多分区的 img 镜像,打开后列出的"文件"为 0.fat, 1.img ... "解压缩" 1.img 后再次用 7z 打开就可以访问此分区里所有文件。

losetup (linux)

注意:WSL (Windows Subsystem for Linux) 里这种方法不可用,因为 WSL 目前(2020-05)仍然不支持 loop 设备。

Linux 下推荐用 losetup 配合 mount 挂载分区的 img 或 iso 镜像文件。需要较新版本的 losetup (支持 -P 参数)

# losetup 时如果提示 device busy, 尝试换用 loop1, loop2, loop3...
losetup -P /dev/loop0 file.img
ls /dev/loop2p*
# /dev/loop2p1, /dev/loop2p2
mount /dev/loop2p2 /mnt/abc

Old way (linux)


Try running the command fdisk -l . Typically if the .img files are entire disks from say a KVM VM then they're technically a virtual disk.

I've got a CentOS KVM VM which shows up like so with the file command:

$ file centostest.img
centostest.img: x86 boot sector; partition 1: ID=0x83, active, starthead 1, startsector 63, 208782 sectors; partition 2: ID=0x8e, starthead 0, startsector 208845, 20755980 sectors, code offset 0x48
Running fdisk with it:

$ sudo /sbin/fdisk -lu /kvm/centostest.img
last_lba(): I don't know how to handle files with mode 81ed
You must set cylinders.
You can do this from the extra functions menu.

Disk /kvm/centostest.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes

          Device Boot      Start         End      Blocks   Id  System

/kvm/centostest.img1 * 63 208844 104391 83 Linux
/kvm/centostest.img2 208845 20964824 10377990 8e Linux LVM
Partition 2 has different physical/logical endings:
phys=(1023, 254, 63) logical=(1304, 254, 63)
If you'd like to mount one of these partitions you can do so as follows:

fdisk (cylinder output)
block-size of 512 bytes and the start-block is 63.
The offset is 512 * 63 = 32256.
fdisk (sector output)
block-size of 512 bytes and the start-block is 1.
The offset is 512 * 1 = 512.
So the mount command would be:

in cylinders
$ mount -o loop,offset=32256 centostest.img /mnt/tmp
To mount the other partition (512 * 208845 = 106928640):

$ mount -o loop,offset=106928640 centostest.img /mnt/tmp
in sectors
$ mount -o loop,offset=512 centostest.img /mnt/tmp
To mount the other partition (512 * 14 = 7168):

$ mount -o loop,offset=7168 centostest.img /mnt/tmp
This will only work if mount can determine the type of filesystem within the "partition" you're attempting to mount. You may need to include -t auto, or be specific and tell mount that's it's -t ext4 for example.


Last update: 2020-05-29 02:49:20 UTC