How to create image for raspberry pi and virtual box
- Efetue login ou registre-se para postar comentários
To create an image for a Raspberry Pi, you generally have two main scenarios:
- Starting fresh with a new OS (e.g., Raspberry Pi OS, Ubuntu, Home Assistant OS).
- Cloning or backing up your existing Pi setup into a custom image.
Here, I'll explain the first method. The steps are:
- Download your desired OS image
- Go to the Raspberry Pi OS download page or your preferred OS site.
- Download the
.img
or.zip
file.
- Write the image to a microSD card
- Install Raspberry Pi Imager.
- Select your OS, your SD card, and click Write.
- Alternatively, use
balenaEtcher
or thedd
command (Linux/macOS).
- Configure before first boot (optional)
- After writing, open the SD card’s
boot
partition. - Create an empty file named
ssh
to enable SSH. - Edit
wpa_supplicant.conf
to preconfigure Wi-Fi.
- After writing, open the SD card’s
Making a Smaller, Distributable Image (Optional)
If your SD card is big but you don’t need all that empty space:
- Use PiShrink to shrink
.img
files so they only take up as much space as actual data.
Now, such an image would not run in Virtual Box, because VirtualBox expects disk formats like VDI, VHD, or VMDK. But you can convert img files to vdi, and back.
To convert img to vdi:
VBoxManage convertfromraw my-raspi.img my-raspi.vdi --format VDI
You could also use --format VMDK
for VMware compatibility.
and to convert a vdi file to img, use this command:
VBoxManage clonemedium disk mydisk.vdi mydisk.img --format RAW
Alternatively, you can use qemu like so:
qemu-img convert -f vdi -O raw mydisk.vdi mydisk.img
.