PROJET AUTOBLOG


Planet-Libre

source: Planet-Libre

⇐ retour index

Uggy : Monter une image disque (.img) contenant plusieurs partitions

mercredi 8 mai 2013 à 23:35

Le RaspberryPi nécessite 2 partitions et les OS sont généralement founis en .img

J'avais besoin de comparer certains fichiers entre mon installation Rasbian et la distribution Raspbmc.

Je télécharge donc raspbmc-final.img sur mon laptop puis:

$ mkdir mount
$ sudo fdisk -l raspbmc-final.img

Disk raspbmc-final.img: 1363 MB, 1363148800 bytes
4 heads, 32 sectors/track, 20800 cylinders, total 2662400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d692e

Device Boot Start End Blocks Id System
raspbmc-final.img1 4096 147455 71680 c W95 FAT32 (LBA)
raspbmc-final.img2 151552 2662399 1255424 83 Linux

Si on veut monter la 1ère partition qui démarre au sector 4096, l'offset à utiliser est donc 512x4096=2097152

$ sudo mount -o loop,offset=2097152 raspbmc-final.img mount/
$ cat mount/cmdline.txt
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 noatime quiet rootwait loglevel=1 zram.num_devices=2
$ sudo umount mount/

Si on veut monter la 2ème partition qui démarre au sector 151552, l'offset à utiliser est donc 512x151552=77594624

$ sudo mount -o loop,offset=77594624 raspbmc-final.img mount/
$ cat mount/etc/hostname
raspbmc
$ sudo umount mount/

man fdisk
[...] starting offset and the size of each partition is stored in two ways: as an absolute number of sectors [...]

man mount
[...] mount knows about four options, namely loop, offset, sizelimit and encryption [...]



[Edit:] Tassatux m'indique dans le commentaires que kpartx est créé a cet effet:

This tool, derived from util-linux' partx, reads partition tables on specified device and create device maps over partitions segments detected. It is called from hotplug upon device maps creation and deletion.

Voir les commentaires pour les informations supplémentaires.

Gravatar de Uggy
Original post of Uggy.Votez pour ce billet sur Planet Libre.