Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Chroot into Raspberry Pi ARMv7 Image with Qemu
# install dependecies
apt-get install qemu qemu-user-static binfmt-support

# download raspbian image
wget https://downloads.raspberrypi.org/raspbian_latest

# extract raspbian image
unzip raspbian_latest

# extend raspbian image by 1gb
dd if=/dev/zero bs=1M count=1024 >> 2016-05-27-raspbian-jessie.img

# set up image as loop device
losetup /dev/loop0 2016-05-27-raspbian-jessie.img

# check file system
e2fsck -f /dev/loop0p2

#expand partition
resize2fs /dev/loop0p2

# mount partition
mount -o rw /dev/loop0p2  /mnt
mount -o rw /dev/loop0p1 /mnt/boot

# mount binds
mount --bind /dev /mnt/dev/
mount --bind /sys /mnt/sys/
mount --bind /proc /mnt/proc/
mount --bind /dev/pts /mnt/dev/pts

# ld.so.preload fix
sed -i 's/^/#/g' /mnt/etc/ld.so.preload

# copy qemu binary
cp /usr/bin/qemu-arm-static /mnt/usr/bin/

# chroot to raspbian
chroot /mnt /bin/bash
	# do stuff...
	exit

# revert ld.so.preload fix
sed -i 's/^#//g' /mnt/etc/ld.so.preload

# unmount everything
umount /mnt/{dev/pts,dev,sys,proc,boot,}

# unmount loop device
losetup -d /dev/loop0

Source

Awesome! finally got this working after finding ur gist

Note: on Slackware, and presumably other operating systems/versions of losetup, you need to add the -P flag when setting up image as loop device (e.g. losetup -P /dev/loop0 2016-05-27-raspbian-jessie.img) which forces the kernel to scan the partition table, otherwise it doesn't see the partitions in the Raspbian image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment