Raspberry pi https://keopx.net/ es Exploring .img Files on Linux and create your custom one https://keopx.net/blog/exploring-img-files-linux-and-create-your-custom-one <span>Exploring .img Files on Linux and create your custom one</span> <div class="text-content clearfix field field--name-body field--type-text-with-summary field--label-hidden field__item"><ul><li>Discover the hidden secrets of a monolithic <code>.img</code> file</li> <li>Mount the partitions in an <code>.img</code> file using <code>losetup</code>, <code>kpartx</code> and <code>mount</code></li> <li>Create your own <code>.img</code> files and use them as virtual disks</li> <li>Write out your virtual disk image to a thumb drive (or any drive for that matter) for use later</li> </ul><h2>Install packages</h2> <p><code>$ sudo aptitude install kpartx xz-utils</code></p> <h2>Decompress image</h2> <p>Once its downloaded you will want to uncompress it with <code>xz --decompress</code>:</p> <p><code>$ xz --decompress Retrobro128KillerHomeConsole.img.img.xz</code></p> <h2>Mount image</h2> <p>We’re going to attach the image file to what is known as a <a href="https://web.archive.org/web/20210118104618/https://en.wikipedia.org/wiki/Loop_device">loopback device</a>.</p> <p><code>$ sudo losetup /dev/loop0 Retrobro128KillerHomeConsole.img</code></p> <p>Note: We used <code>/dev/loop0</code> in this example. If <code>/dev/loop0</code> wasn’t available to us (that is, it was already in use), we could have chosen <code>/dev/loop1</code>, etc.</p> <p><code>$ sudo losetup -a /dev/loop0: [65026]:28970069 (/home/keopx/Retrobro128KillerHomeConsole.img)</code></p> <p>Now <code>/dev/loop0</code> is attached. How about look at the partition table with <code>fdisk</code>?</p> <p><code>$ sudo fdisk -l /dev/loop0 Disco /dev/loop0: 119,8 GiB, 128579534848 bytes, 251131904 sectores Unidades: sectores de 1 * 512 = 512 bytes Tamaño de sector (lógico/físico): 512 bytes / 512 bytes Tamaño de E/S (mínimo/óptimo): 512 bytes / 512 bytes Tipo de etiqueta de disco: dos Identificador del disco: 0xf2d3cb4f Disposit. Inicio Comienzo Final Sectores Tamaño Id Tipo /dev/loop0p1 * 8192 124927 116736 57M e W95 FAT16 (LBA) /dev/loop0p2 124928 251131903 251006976 119,7G 83 Linux </code></p> <p>To see what <code>kpartx</code> <em>would</em> map, run it with the <code>-l</code> option:</p> <p><code>$ sudo kpartx -l /dev/loop0 loop0p1 : 0 116736 /dev/loop0 8192 loop0p2 : 0 251006976 /dev/loop0 124928</code></p> <p>Let’s go ahead and run it and add the maps:</p> <p><code>$ sudo kpartx -a /dev/loop0 </code></p> <p>Now you can see new devices on <strong>dolphin</strong>.</p> <p>Running a shell:</p> <p>Now that the partitions are mapped, let’s examine the filesystems on each partition with <code>file</code> and the <code>--special-files</code> and <code>--dereference</code> options.</p> <p><code>$ sudo file -sL /dev/mapper/loop0p1 /dev/mapper/loop0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, reserved sectors 4, root entries 512, Media descriptor 0xf8, sectors/FAT 116, sectors/track 32, heads 64, sectors 116736 (volumes &gt; 32 MB), serial number 0xb13de1e5, label: "boot ", FAT (16 bit)</code></p> <p><code>$ sudo file -sL /dev/mapper/loop0p2 /dev/mapper/loop0p2: Linux rev 1.0 ext4 filesystem data, UUID=c50e928e-5669-44d0-8e3c-a59d21ad3da2, volume name "retropie" (extents) (64bit) (large files) </code></p> <p>Now that we have our partitions mapped, we can mount them. Create two directories to serve as mountpoints:</p> <p><code>$ mkdir boot # We will mount the FAT partition here $ mkdir retropie # We will mount the ext4 partition here</code></p> <p>Once they are created, <code>mount</code> the filesystems (only system in my case).</p> <p><code>$ sudo mount /dev/mapper/loop0p2 retropie</code></p> <h2>Umount image</h2> <p>Once you are done and want to “let go” of the <code>.img</code> file, reverse the process with:</p> <p><code>$ sudo umount retropie $ sudo kpartx -d /dev/loop0 $ sudo losetup -d /dev/loop0</code></p> <p>Reference:</p> <ul><li><a href="https://web.archive.org/web/20210118104618/https://dev.iachieved.it/iachievedit/exploring-img-files-on-linux/">https://dev.iachieved.it/iachievedit/exploring-img-files-on-linux/</a></li> </ul></div> <span><span lang="" about="/users/keopx" typeof="schema:Person" property="schema:name" datatype="">keopx</span></span> <span>Jue, 26/12/2019 - 11:50</span> <div class="field field--name-field-tax-cat field--type-entity-reference field--label-above"> <div class="field__label">Categoria</div> <div class="field__items"> <div class="field__item"><a href="/categoria/debian-10" hreflang="es">Debian 10</a></div> <div class="field__item"><a href="/categoria/raspberry-pi" hreflang="es">Raspberry pi</a></div> </div> </div> <div class="field field--name-field-tax-tag field--type-entity-reference field--label-above"> <div class="field__label">Tag</div> <div class="field__items"> <div class="field__item"><a href="/tag/bash" hreflang="es">bash</a></div> <div class="field__item"><a href="/tag/terminal" hreflang="es">Terminal</a></div> <div class="field__item"><a href="/tag/consola" hreflang="es">consola</a></div> </div> </div> <section data-drupal-selector="comments" class="comments"> <h2 class="comments__title">Comentarios</h2> <div class="add-comment"> <div class="add-comment__form"> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=308&amp;2=field_comments&amp;3=comment" token="O6DJWUhWDSOQytsmVQ9idBx3ufl7Pw7sSFZCnZvlKQU"></drupal-render-placeholder> </div> </div> </section> Thu, 26 Dec 2019 10:50:37 +0000 keopx 308 at https://keopx.net