How to unzip or mount an IMG file on a Linux system

Source: Internet
Author: User

IMG File compression and decompression
The initrd.img in the 2.6 kernel is cpio compressed and is no longer a ext2 format used by the 2.4 kernel and cannot be mounted using the Mount-o loop. Need to decompress with gunzip and then use Cpio to unpack

The code is as follows:
Cp/boot/initrd-***.img initrd.img.gz
Gunzip initrd.img.gz
mkdir INITRD
MV Initrd.img INITRD
CD INITRD
CPIO-IVMD < initrd.img
By using the above command, the initrd.img is decompressed, and you can edit it now, and then use the following command to suppress it again.

The code is as follows:
Find. | Cpio-cv-o > ... /initrd.new.img
Gzip.. /initrd.new.img
IMG File Mount method
In Linux, for an img file (for example, an IMG file for a virtual machine), it is sometimes necessary to mount it in order to modify its contents. Can you mount it like an ISO file?
In fact, the method is very simple, only need two steps:

The code is as follows:
#kpartx-av xxx.img
Get the following information:

The code is as follows:
Add Map Loop0p1 ...
At this point only need Mount Loop0p1 can

The code is as follows:
#mount/dev/mapper/loop0p1/mnt
OK, so you can enter MNT to modify the contents of the IMG file
Uninstalling is also simple, and is also two steps:

The code is as follows:
Umount/mnt
Kpartx-d xxx.img

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.