14
Qemu in Chroot Make it easy

Qemu - Raspberry | while42 Singapore #2

  • Upload
    while42

  • View
    637

  • Download
    5

Embed Size (px)

DESCRIPTION

Presentation by Mathieu Feulvarch for the while42 Singapore #3

Citation preview

Page 1: Qemu - Raspberry | while42 Singapore #2

Qemu in ChrootMake it easy

Page 2: Qemu - Raspberry | while42 Singapore #2
Page 3: Qemu - Raspberry | while42 Singapore #2

QEMU is a hosted virtual machine monitor: It emulates central processing units through dynamic binary translation and provides a set of device models, enabling it to run a variety of unmodified guest operating systems.

Page 4: Qemu - Raspberry | while42 Singapore #2

Qemu

Page 5: Qemu - Raspberry | while42 Singapore #2

A chroot on Unix operating systems is an operation that changes the apparent root directory for the current running process and its children.

Page 6: Qemu - Raspberry | while42 Singapore #2

Chroot

Page 7: Qemu - Raspberry | while42 Singapore #2

The Raspberry Pi has a Broadcom BCM2835 system on a chip (SoC),[3] which includes an ARM1176JZF-S 700 MHz processor

Page 8: Qemu - Raspberry | while42 Singapore #2

Raspberry Pi

Page 9: Qemu - Raspberry | while42 Singapore #2

What about speed?

pi@raspberrypi:~$ cat /proc/cpuinfo | grep MIPS

BogoMIPS : 565.24

pi@raspberrypi:~$ cat /proc/cpuinfo | grep MIPS

BogoMIPS : 697.95

Not good!

Page 10: Qemu - Raspberry | while42 Singapore #2

# git clone http://git.qemu.org/git/qemu.git# ./configure --target-list="arm-softmmu arm-linux-user" --enable-sdl --static# make# sudo make install

Qemu compilationARM1176JZF-S

Page 11: Qemu - Raspberry | while42 Singapore #2

● Download the latest version of Raspbian (link)● Download the linux kernel for Qemu (link)

# qemu-system -kernel kernel-qemu -cpu arm1176 -M versatilepb -no-reboot -append "root=/dev/sda2 panic=0 ro single" -hda XXXXX-raspbian.img

# mount / -o remount,rw

● Edit fstab and change mmcblk0p1 and mmcblk0p2 to sda1 and sda2 respectively

● Create /etc/udev/rules.d/90-qemu.rules

KERNEL=="sda", SYMLINK+="mmcblk0"KERNEL=="sda?", SYMLINK+="mmcblk0p%n",

● Comment everything in /etc/ld.so.preload

Preparation

Page 12: Qemu - Raspberry | while42 Singapore #2

Enlarge it!

# cp XXXXX-raspbian.img raspbian.img# qemu-img resize raspbian.img +6G# qemu-system -kernel kernel-qemu -cpu arm1176 -M versatilepb -no-reboot -append "root=/dev/sda2 panic=1" -hda XXXXX-raspbian.img -hdb raspbian.img# sudo cfdisk /dev/sdb

●Delete the second partition and create a new partition with all space

# sudo resize2fs /dev/sdb2# sudo fsck -f /dev/sdb2# sudo halt# qemu-system -kernel kernel-qemu -cpu arm1176 -M versatilepb -no-reboot -append "root=/dev/sda2 panic=1" -hda raspbian.img

Page 13: Qemu - Raspberry | while42 Singapore #2

Chroot it# sudo kpartx -a -v 2012-12-16-wheezy-raspbian.img

add map loop0p1 (252:8): 0 114688 linear /dev/loop0 8192

add map loop0p2 (252:9): 0 5763072 linear /dev/loop0 122880

# sudo mount /dev/mapper/loop0p2 /mnt/temp# sudo mount -o bind /dev /mnt/temp/dev

# sudo mount -o bind /proc /mnt/temp/proc

# sudo mount -o bind /sys /mnt/temp/sys

Don’t forget to copy the qemu-arm binary to the image# sudo cp /usr/bin/qemu-arm /mnt/temp/usr/bin

# cat /usr/share/binfmts/qemu-arm

package qemu-user-static

interpreter /usr/bin/qemu-arm-static

credentials yes

offset 0

magic \x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00

mask \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff

Run sudo update-binfmts --import qemu-arm two times (yes, two times)

Page 14: Qemu - Raspberry | while42 Singapore #2

And we are good to go

Now, you should be able to chroot# sudo chroot /mnt/temp

Let’s check if it’s working# uname -a

Linux localhost 2.6.32 #58-Ubuntu SMP Thu Jan 24 15:28:10 UTC 2013 armv7l GNU/Linux