- Install QEMU.
- Since the recent Raspberry Pi OS has removed the preset user, use a
legacy version like
2022-01-28will work. Download the Raspberry Pi OS and extract these files from the image:
bcm2710-rpi-3-b.dtbkernel8.img
- Resize the image to 8G to avoid the disk error. Since the disk space has to be the square of 2 and the image itself occupies 3.8G already. If you want to make more actions, please allocate a larger space.
qemu-img resize 2022-01-28-raspios-bullseye-arm64.img 8Gqemu-system-aarch64 \
-M raspi3b \
-cpu cortex-a53 \
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" \
-dtb bcm2710-rpi-3-b.dtb \
-sd 2022-01-28-raspios-bullseye-arm64.img \
-kernel kernel8.img \
-m 1G -smp 4 \
-serial stdio \
-usb -device usb-mouse -device usb-kbd \
-device usb-net,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::2222-:22,hostfwd=tcp::9090-:9090 \and add the permission to run the script by
chmod +x launch.shYou can now run the OS by
./launch.sh- The default user for logging in:
pi
raspberry
- Open SSH connection on the raspberry pi, use the command
sudo raspi-configAnd then go to [Interface Options]->[SSH]->[Yes]->[Finish], reboot the system. And on the host side, use the command to connect to the raspberry pi by SSH.
ssh -p 2222 pi@localhost- Extend the disk. First check the sector number by
$ sudo fdisk -l
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 532479 524288 256M c W95 FAT32 (LBA)
/dev/mmcblk0p2 532480 8118271 7585792 3.6G 83 Linuxnote down the start section of mmcblk0p2 (here is 532480). Next change the partition by fdisk:
pi@raspberrypi:~$ sudo fdisk /dev/mmcblk0 # mmcblk0 is the device
Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d # delete the partition
Partition number (1,2, default 2): 2 # number 2
Partition 2 has been deleted.
Command (m for help): n # new a partition
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p # primary
Partition number (2-4, default 2): 2 # the second
First sector (2048-16777215, default 2048): 532480 # the start section noted before
Last sector, +/-sectors or +/-size{K,M,G,T,P} (532480-16777215, default 16777215): # use default end
Created a new partition 2 of type 'Linux' and of size 7.7 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: N # just extend, no need to remove the signature
Command (m for help): w # execute.
The partition table has been altered.
Syncing disks.
Now reboot the system
sudo rebootAnd then take the change into effect.
sudo resize2fs /dev/mmcblk0p2You can now see the space is extended:
pi@raspberrypi:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 7.6G 3.3G 4.0G 46% /
# ...- To avoid the certificate expired error, we need to calibrate the date and time.
sudo date --s="2022-12-07 22:30:00"