Last active
October 9, 2025 02:52
-
-
Save plembo/c4920016312f058209f5765cb9a3a25e to your computer and use it in GitHub Desktop.
Revisions
-
plembo revised this gist
Mar 5, 2025 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,12 +18,10 @@ missing key information. with arm processors like the Pi. 2. Create an emulation project directory, "~/Projects/rpitest" to hold the emulation files. 3. Clone the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) repo to another directory using git. 4. Copy the kernel image and matching versatile-pb.dtb file into the project directory (e.g. "rpitest"). Rename the kernel file to "kernel-qemu". 5. Download the latest Raspbian disk image and unzip into the project directory. 6. Find starting sector of the image's second partition using fdisk: ```bash $ fdisk -l 2018-06-27-raspbian-stretch.img -
plembo revised this gist
Apr 5, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,7 +53,7 @@ This will enable devices like keyboards and mice to work in the emulator. 10. Unmount and rename the file to "rpitest.img". ``` $ sudo umount /mnt $ mv 2018-06-27-raspbian-stretch.img rpitest.img ``` 12. Convert the raw img file to qcow2 format: -
plembo revised this gist
Apr 5, 2022 . 1 changed file with 13 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ Rename the kernel file to "kernel-qemu". 7. Find starting sector of the image's second partition using fdisk: ```bash $ fdisk -l 2018-06-27-raspbian-stretch.img Disk 2018-06-27-raspbian-stretch.img: 4.5 GiB, 4823449600 bytes, 9420800 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes @@ -42,27 +42,31 @@ Device Boot Start End Sectors Size Id Type image: ```bash $ sudo mount 2018-06-27-raspbian-stretch.img -o offset=50331648 /mnt ``` 9. Edit the ld.so.preload file to comment out its one and only line: ``` $ sudo vi /mnt/etc/ld.so.preload ``` This will enable devices like keyboards and mice to work in the emulator. 10. Unmount and rename the file to "rpitest.img". ``` $ sudo umount 2018-06-27-raspbian-stretch.img $ mv 2018-06-27-raspbian-stretch.img rpitest.img ``` 12. Convert the raw img file to qcow2 format: ```bash $ qemu-img convert -f raw -O qcow2 rpitest.img rpitest.qcow2 ``` ## Starting the virtual machine Copy the following code into a startup script called something like "rpistart.sh": ```bash #!/usr/bin/env bash $ sudo qemu-system-arm -kernel kernel-qemu \ -cpu arm1176 -m 256 \ -M versatilepb -dtb versatile-pb.dtb \ -no-reboot \ @@ -85,13 +89,13 @@ to be expanded in size. The following steps will accomplish that. 1. Shut down the virtual machine and run qemu-img to increase the disk size: ``` $ qemu-img resize rpitest.qcow2 +4G ``` 2. Start up the machine again and log in. Run fdisk to delete and then re-create the second partition. ``` $ sudo fdisk /dev/sda ``` The commands to run within fdisk are: @@ -113,7 +117,7 @@ w - to write all changes to disk 3. Complete the resizing operation by running resize2fs on the partition: ```bash $ resize2fs /dev/sda2 ``` 4. Run df -h to confirm the expanded disk size is recognized by the system. -
plembo revised this gist
Aug 6, 2018 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,9 @@ Goal: Emulate a [Raspberry Pi](https://www.raspberrypi.org/) with [QEMU](https://www.qemu.org/) in order to run the [Raspbian O/S](https://www.raspberrypi.org/downloads/raspbian/) (based on Debian Linux). The current setup is not ideal. For one thing, the maximum RAM allowed using the "versatile-pb" firmware is 256 Mb. In addition, only the most basic peripherals, a keyboard and mouse, are supported. A number of articles have been written on this topic. Most are outdated, and the few recent ones are missing key information. -
plembo revised this gist
Aug 6, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,12 +13,12 @@ missing key information. ## Procedure 1. Install qemu-system-arm (on Ubuntu, "sudo apt-get qemu-system-arm") to allow the emulation of devices with arm processors like the Pi. 2. Create an emulation project directory, "~/Projects/rpitest" to hold the emulation files. 3. Clone the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) repo to another directory using git. 4. Follow the instructions in the repo for building a versatile-pb.dtb file for your kernel of choice (or simply use the kernel and matching .dtb file provided by default -- currently kernel-4.9.41-stretch). 5. Copy the kernel image and matching versatile-pb.dtb file into the project directory (e.g. "rpitest"). Rename the kernel file to "kernel-qemu". 6. Download the latest Raspbian disk image and unzip into the project directory. 7. Find starting sector of the image's second partition using fdisk: -
plembo revised this gist
Aug 6, 2018 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,8 @@ with arm processors like the Pi. 3. Clone the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) repo to another directory using git. 4. Follow the instructions in the repo for building a versatile-pb.dtb file for your kernel of choice (or simply use the kernel and matching .dtb file provided by default -- currently kernel-4.9.41-stretch). 5. Copy the kernel image and matching .dtb file into the project directory (e.g. "rpitest"). Rename the kernel file to "kernel-qemu". 6. Download the latest Raspbian disk image and unzip into the project directory. 7. Find starting sector of the image's second partition using fdisk: @@ -47,7 +48,7 @@ sudo vi /mnt/etc/ld.so.preload ``` This will enable devices like keyboards and mice to work in the emulator. 10. Unmount and rename the file to "rpitest.img". 11. Convert the raw img file to qcow2 format: ```bash qemu-img convert -f raw -O qcow2 rpitest.img rpitest.qcow2 -
plembo revised this gist
Aug 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ with arm processors like the Pi. 2. Create an emulation project directory, like "rpitest" to hold the emulation files. 3. Clone the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) repo to another directory using git. 4. Follow the instructions in the repo for building a versatile-pb.dtb file for your kernel of choice (or simply use the kernel and matching .dtb file provided by default -- currently kernel-4.9.41-stretch). 5. Copy the kernel image and matching .dtb file into the project directory (e.g. "rpitest"). 6. Download the latest Raspbian disk image and unzip into the project directory. 7. Find starting sector of the image's second partition using fdisk: -
plembo revised this gist
Aug 6, 2018 . 1 changed file with 13 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,9 +11,10 @@ missing key information. 3. Latest Debian Stretch kernel from the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) project. ## Procedure 1. Install qemu-system-arm (on Ubuntu, "sudo apt-get qemu-system-arm") to allow the emulation of devices with arm processors like the Pi. 2. Create an emulation project directory, like "rpitest" to hold the emulation files. 3. Clone the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) repo to another directory using git. 4. Follow the instructions in the repo for building a versatile-pb.dtb file for your kernel of choice (or simply use the kernel and matching .dtb file provided by default). 5. Copy the kernel image and matching .dtb file into the project directory (e.g. "rpitest"). @@ -44,10 +45,10 @@ sudo mount 2018-06-27-raspbian-stretch.img -o offset=50331648 /mnt ``` sudo vi /mnt/etc/ld.so.preload ``` This will enable devices like keyboards and mice to work in the emulator. 10. Unmount and rename the file to something short, like rpitest.img. 11. Convert the raw img file to qcow2 format: ```bash qemu-img convert -f raw -O qcow2 rpitest.img rpitest.qcow2 ``` @@ -69,8 +70,14 @@ sudo qemu-system-arm -kernel kernel-qemu \ ``` Login using username "pi" and password "raspberry". Your machine should be fully functional at this point, and able to reach the Internet over the virtual network (vnet0) created along with it. Do not update the system at this point, as the shipping image is 97% full. ## Expand the disk size To update and do useful work with the system, the root partition (/dev/sda2) will need to be expanded in size. The following steps will accomplish that. 1. Shut down the virtual machine and run qemu-img to increase the disk size: ``` -
plembo revised this gist
Aug 6, 2018 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,8 @@ missing key information. 1. Install qemu-system-arm (on Ubuntu, "sudo apt-get qemu-system-arm"). 2. Create an emulation project directory, like "rpitest". 3. Clone the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) repo using git. 4. Follow the instructions in the repo for building a versatile-pb.dtb file for your kernel of choice (or simply use the kernel and matching .dtb file provided by default). 5. Copy the kernel image and matching .dtb file into the project directory (e.g. "rpitest"). 6. Download the latest Raspbian disk image and unzip into the project directory. 7. Find starting sector of the image's second partition using fdisk: @@ -76,7 +77,7 @@ This is necessary because the shipping image is 97% full. qemu-img resize rpitest.qcow2 +4G ``` 2. Start up the machine again and log in. Run fdisk to delete and then re-create the second partition. ``` sudo fdisk /dev/sda -
plembo revised this gist
Aug 6, 2018 . 1 changed file with 8 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -71,7 +71,12 @@ Login using username "pi" and password "raspberry". ## Expand the disk size This is necessary because the shipping image is 97% full. 1. Shut down the virtual machine and run qemu-img to increase the disk size: ``` qemu-img resize rpitest.qcow2 +4G ``` 2. While logged into the virtual machine, run fdisk to delete and then re-create the second partition. ``` sudo fdisk /dev/sda @@ -94,9 +99,9 @@ Enter - to accept the last sector of the disk as the end of the partition w - to write all changes to disk ``` 3. Complete the resizing operation by running resize2fs on the partition: ```bash resize2fs /dev/sda2 ``` 4. Run df -h to confirm the expanded disk size is recognized by the system. -
plembo revised this gist
Aug 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,7 @@ Copy the following code into a startup script called something like "rpistart.sh #!/usr/bin/env bash sudo qemu-system-arm -kernel kernel-qemu \ -cpu arm1176 -m 256 \ -M versatilepb -dtb versatile-pb.dtb \ -no-reboot \ -serial stdio \ -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \ -
plembo created this gist
Aug 6, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,102 @@ # Emulating a Raspberry Pi with QEMU Goal: Emulate a [Raspberry Pi](https://www.raspberrypi.org/) with [QEMU](https://www.qemu.org/) in order to run the [Raspbian O/S](https://www.raspberrypi.org/downloads/raspbian/) (based on Debian Linux). A number of articles have been written on this topic. Most are outdated, and the few recent ones are missing key information. ## Software Required 1. QEMU system emulation binaries for ARM processors. On Ubuntu, qemu-system-arm. 2. [Raspbian Stretch with Desktop](https://downloads.raspberrypi.org/raspbian_latest), disk image. 3. Latest Debian Stretch kernel from the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) project. ## Procedure 1. Install qemu-system-arm (on Ubuntu, "sudo apt-get qemu-system-arm"). 2. Create an emulation project directory, like "rpitest". 3. Clone the [qemu-rpi-kernel](https://github.com/dhruvvyas90/qemu-rpi-kernel) repo using git. 4. Follow the instructions in the repo for building a versatile-pb.dtb file for your kernel of choice. 5. Copy the kernel image and matching .dtb file into the project directory (e.g. "rpitest"). 6. Download the latest Raspbian disk image and unzip into the project directory. 7. Find starting sector of the image's second partition using fdisk: ```bash fdisk -l 2018-06-27-raspbian-stretch.img Disk 2018-06-27-raspbian-stretch.img: 4.5 GiB, 4823449600 bytes, 9420800 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: 0xbd98648d Device Boot Start End Sectors Size Id Type 2018-06-27-raspbian-stretch.img1 8192 96663 88472 43.2M c W95 FAT32 (LBA) 2018-06-27-raspbian-stretch.img2 98304 9420799 9322496 4.5G 83 Linux ``` 8. Multiply that sector number by 512 and use the result as the offset in mounting the image: ```bash sudo mount 2018-06-27-raspbian-stretch.img -o offset=50331648 /mnt ``` 9. Edit the ld.so.preload file to comment out its one and only line: ``` sudo vi /mnt/etc/ld.so.preload ``` 10. Unmount and rename the file to something short, like rpitest.img. 11. Convert the raw img file to qcow2 format: ```bash qemu-img convert -f raw -O qcow2 rpitest.img rpitest.qcow2 ``` ## Starting the virtual machine Copy the following code into a startup script called something like "rpistart.sh": ```bash #!/usr/bin/env bash sudo qemu-system-arm -kernel kernel-qemu \ -cpu arm1176 -m 256 \ -M versatilepb -dtb versatile-pb.dtb \ -no-reboot \ -serial stdio \ -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \ -hda rpitest.qcow2 \ -net nic -net user \ -net tap,ifname=vnet0,script=no,downscript=no ``` Login using username "pi" and password "raspberry". ## Expand the disk size This is necessary because the shipping image is 97% full. 1. While logged into the virtual machine, run fdisk to delete and then re-create the second partition. ``` sudo fdisk /dev/sda ``` The commands to run within fdisk are: ``` print - to show the current disk layout ``` (note the starting sector of the second partition) ``` d - to delete a partition 2 - choose partition 2 n - create a new partition p - make it primary 2 - partition number xxxxx - the starting sector of the original partition 2 Enter - to accept the last sector of the disk as the end of the partition w - to write all changes to disk ``` 2. Complete the resizing operation by running resize2fs on the partition: ```bash resize2fs /dev/sda2 ``` 3. Run df -h to confirm the expanded disk size is recognized by the system.