Skip to content

Emulating Jessie image with 4.x.xx kernel

Steven Conaway edited this page Aug 29, 2017 · 3 revisions

To emulate Jessie image with 4.x.xx kernel in this repo, steps differ slightly compared to a lot of (and standard) wheezy emulating guides on the internet.

In order to prepare your image for the first time, you will need a Linux box (or any other OS that can mount an ext4 file from a .img file).

I'm assuming that you have:

  1. Latest jessie image
  2. 4.x.xx qemu-kernel for versatilepb.

Steps:

  1. fdisk -l <image-file>. It should show output like this one :
Disk 2015-11-21-raspbian-jessie.img: 3.7 GiB, 3934257152 bytes, 7684096 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
Disklabel type: dos
Disk identifier: 0xea0e7380

Device                          Boot  Start     End Sectors  Size Id Type
2015-11-21-raspbian-jessie.img1        8192  131071  122880   60M  c W95 FAT32 (LBA)
2015-11-21-raspbian-jessie.img2      131072 7684095 7553024  3.6G 83 Linux

The filesystem (.img2) starts at sector 131072, which equals 512 * 131072 = 67108864 bytes. Use this as the offset, ie. mount -v -o offset=67108864 -t ext4 your-image-file.img /path/to/mnt/

  1. cd /path/to/mnt
  2. sudo nano ./etc/ld.so.preload
  3. Comment out every entry in it, Ctrl-x » Y to save and exit
  4. sudo nano ./etc/fstab
  5. Comment out entries containing /dev/mmcblk, Ctrl-x » Y to save and exit
  6. cd ~
  7. sudo umount /path/to/mnt

Once done with these changes, you can emulate it on Qemu by:

qemu-system-arm -kernel /path/to/kernel/kernel-name -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda /path/to/image/image-file-name.img

Mount using kpartx

Another option to mount Raspberry Pi image (tested with Jessie lite) is to use the kpartx tool (kpartx package on Debian, sys-fs/multipath-tools ebuild on Gentoo). All steps are done with root rights:

  1. create image partitions mappings (-a add mapping, -v makes verbose output to list mappings):

    kpartx -av 2017-07-05-raspbian-jessie-lite.img
    add map loop0p1 (254:0): 0 85405 linear 7:0 8192
    add map loop0p2 (254:1): 0 3276162 linear 7:0 94208```
    
    As one can see, the tool creates two mappins:
    
    + `loop0p1` -- first aprtition
    + `loop0p2` -- second partition, this need to be mounted
    
  2. prepare partition to mount:

    mkdir /tmp/raspi
    
  3. mount mapped partition:

    mount /dev/mapper/loop0p2 /tmp/raspi/
    
  4. edit the /tmp/raspi/etc/ld.so.preload as described above

  5. after save changes and close editor unmount partition:

    umount /tmp/raspi
    
  6. after unmounting partition close mappings:

    kpartx -dv 2017-07-05-raspbian-jessie-lite.img
    del devmap : loop0p2
    del devmap : loop0p1
    loop deleted : /dev/loop0
    
  7. Done, now you can boot your Raspberry Pi image in QEMU.

Hope it helps.