Advertisement
theboogymaster

Emulating ARM on Debian

Aug 10th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. Emulating ARM on Debian/Ubuntu
  2.  
  3. https://gist.github.com/bdsatish/7476239
  4.  
  5. You might want to read this to get an introduction to armel vs armhf.
  6.  
  7. If the below is too much, you can try Ubuntu-ARMv7-Qemu but note it contains non-free blobs.
  8. Install QEMU
  9.  
  10. sudo apt-get install qemu
  11. Create a hard disk
  12.  
  13. Create a hard disk for your virtual machine with required capacity.
  14.  
  15. qemu-img create -f raw armdisk.img 8G
  16.  
  17. You can then install Debian using an ISO CD or directly from vmlinuz
  18. Netboot from vmlinuz
  19.  
  20. First, you should decide what CPU and machine type you want to emulate.
  21.  
  22. You can get a list of all supported CPUs (to be passed with -cpu option, see later below):
  23.  
  24. qemu-system-arm -cpu help
  25.  
  26. You can get a list of all supported machines (to be passed with -M option, see later below):
  27.  
  28. qemu-system-arm -machine help
  29.  
  30. In this example, I chose the cortex-a9 CPU and vexpress-a9 machine. This is an ARMv7 CPU which Debian calls as armhf (ARM hard float). You must download vmlinuz and initrd files for, say Wheezy armhf netboot. Cortex-A8, A9, A15 are all ARMv7 CPUs.
  31.  
  32. You can emulate ARMv6 which Debian calls as armel by downloading the corresponding files for Wheezy armel netboot. Note that you need armel for ARMv5, v6. Raspberry Pi uses ARMv6. In this case, the cpu is arm1176 and machine is versatilepb.
  33.  
  34. Create a virtual machine with 1024 MB RAM and a Cortex-A9 CPU. Note that we must -sd instead of -sda because vexpress kernel doesn't support PCI SCSI hard disks. You'll install Debian on on MMC/SD card, that's all it means.
  35.  
  36. qemu-system-arm -m 1024M -sd armdisk.img \
  37. -M vexpress-a9 -cpu cortex-a9 \
  38. -kernel vmlinuz-3.2.0-4-vexpress -initrd initrd.gz \
  39. -append "root=/dev/ram" -no-reboot
  40.  
  41. Specifying -cpu is optional. It defaults to -cpu=any. However, -M is mandatory.
  42.  
  43. This will start a new QEMU window and the Debian installer will kick-in. Just proceed with the installation (takes maybe 3 hours or so). Make sure you install "ssh-server" in tasksel screen.
  44.  
  45. NOTE: For creating ARMv6, just pass versatilepb:
  46.  
  47. qemu-system-arm -m 1024M -M versatilepb \
  48. -kernel vmlinuz-3.2.0-4-versatile -initrd initrd.gz \
  49. -append "root=/dev/ram" -hda armdisk.img -no-reboot
  50. Netboot from ISO
  51.  
  52. Download netboot ISO for armhf or armel as needed.
  53.  
  54. WAIT! Apparently, these Debian CD images are not bootable! But Ubuntu's ARM CD image works [2].
  55. First boot from newly installed system
  56.  
  57. You need to copy vmlinuz from the installed disk image and pass it again to qemu-system-img Qemu wiki.
  58. For armel
  59.  
  60. sudo modprobe nbd max_part=16
  61. sudo qemu-nbd -c /dev/nbd0 armel.img
  62. mkdir ~/qemu-mounted
  63. sudo mount /dev/nbd0p1 ~/qemu-mounted
  64. mkdir after-copy
  65.  
  66. cp ~/qemu-mounted/boot/* after-copy/
  67.  
  68. sudo umount ~/qemu-mounted
  69. sudo qemu-nbd -d /dev/nbd0
  70. sudo killall qemu-nbd
  71.  
  72. Then pass the copied kernel and initrd to qemu-system-img. Also note that we are now booting from /dev/sda1 because that is where Linux was installed
  73.  
  74. qemu-system-arm -M versatilepb -m 1024M \
  75. -kernel after-copy/vmlinuz-3.2.0-4-versatile \
  76. -initrd after-copy/initrd.img-3.2.0-4-versatile \
  77. -hda armel.img -append "root=/dev/sda1"
  78.  
  79. And there you go, play with ARM to your heart's extent!
  80. For armhf
  81.  
  82. Extract & copy the boot files exactly as before (but for armhf.img) and pass while invoking:
  83.  
  84. qemu-system-arm -m 1024M -M vexpress-a9 \
  85. -kernel armhf-extracted/vmlinuz-3.2.0-4-vexpress \
  86. -initrd armhf-extracted/initrd.img-3.2.0-4-vexpress \
  87. -append "root=/dev/mmcblk0p1" -sd armhf.img
  88.  
  89. Once again, note the device (mmcblk0p1) and partition (armhf.img) reflect SD-card usage.
  90. Connecting to the SSH server
  91.  
  92. Login to the guest OS and create a private/public key pair: ssh-keygen -t rsa.
  93.  
  94. On the host, just redirect some random port from the host to guest's port 22 (or whichever port the SSH server is running on, see /etc/ssh/sshd_config)
  95.  
  96. qemu-system-arm .... -redir tcp:5555::22 &
  97.  
  98. Then you can connect to SSH just like ssh -p 5555 localhost.
  99. References
  100.  
  101. [1] http://www.linuxforu.com/2011/05/quick-quide-to-qemu-setup/ [2] http://blog.troyastle.com/2010/07/building-arm-powered-debian-vm-with.html [3] Differences between ARM926, ARM1136, A8 and A9 [4] http://www.makestuff.eu/wordpress/running-debian-for-arm-powerpc-on-qemu/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement