Following this tutorial you can emulate the Raspberry Pi 2 on Linux, but keep in mind that it will not be really fast.
First of all, download the official
Raspbian image. If
you're not interested in the desktop environment, I suggest to download the stretch lite version. Then unzip the image and convert into the qcow format:
$ unzip raspbian_stretch_lite.zip raspbian_stretch_lite.img
$ qemu-img convert -f raw -O qcow2 raspbian_stretch_lite.img raspbian_stretch.qcow
Then, download the
kernel-qemu-4.4.1-vexpress and
vexpress-v2p-ca9.dtb clicking the links or from
this repository.
Put all the files in the same folder and run the following command to start the emulator with raspbian:
$ sudo qemu-system-arm -m 1024M -M vexpress-a9 -cpu cortex-a9 -kernel kernel-qemu-4.4.1-vexpress -no-reboot -dtb vexpress-v2p-ca15-tc1.dtb -sd ./raspbian-stretch.qcow -append "root=/dev/mmcblk0p2 rw rootfstype=ext4" -net nic -net user,hostfwd=tcp::2222-:22
-smp cpus=4,maxcpus=4
The emulator should boot the raspbian image, remember that the user is
pi and the password
raspberry by default.
You can enable the ssh service with
systemctl enable ssh or using the
raspi-config commands.
Expand the image size
At this point we need to resize the image, because the raspberry has few memory available by default (i.e. we can't install too many applications, etc.).
-
Expand the virtual size of the image using:
$ qemu-img resize raspbian_stretch.qcow +10G
-
Boot raspbian and inside the emulator use fdisk to manage the partitions:
$ fdisk /dev/sda
Display the partitions using the p command. Note the beginning of the second partition block of the output (call this value INITP). Delete the second partition with the d command then
2. If you again display the partitions it has disappeared. Create a new partition with n then p then 2. There fdisk provides a value for the starting block. This must match the value
that you have identified earlier (INITP). The following value is the end block that is the largest possible to fill all the space If you display the information again you will see that your new partition has a end higher so that means
that the partition is larger. Back up the information with w command. Restart the machine.
-
Enlarge the filesystem. Once again connected, your partition is not increasing ! The partition has been resized well but not the filesystem ! And this is our last step. It is very simple, you just need to run $ resize2fs /dev/sda2.
You can check the result running $ df -h before and after resize2fs.