Resize your partition in Qemu without raspi-config

We have seen some time ago how to create an image for Raspberry Pi with Qemu. Personally I use it to be able to make the tests directly in Qemu without monopolizing a Raspberry. But the base image is only 500MB and raspi-config refuses to extend it because it is not an SD card. So how to do that ?

hard-disk-partition

Let's assume that you now have your image up to date and it works correctly in Qemu. We will expand our system in three simple steps

  1. Enlarge the image. For this the machine must be stopped. You can then use the command qemu-img as follows :
    qemu-img resize <image_file_name> +4G

    The command will add 4GB to our file. In Qemu, this is visible as follows through fdisk :
    qemu_resize_raspi-config_1

  2. Resize the main partition. You can now restart your emulation. The command I use is always the same :
    qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -append "root=/dev/sda2 rw vga=normal console=ttyAMA0,115200" -hda rasp.img -redir tcp:5022::22 -serial stdio

    Once the image is started and that you are connected, use the command fdisk to extend the partition. To do this use the following command :

    fdisk /dev/sda

    Display the partitions using the p command
    qemu fdisk display partition
    Note the beginning of the second partition block. My value is 125904
    Delete the second partition with the d command then 2. If you again display the partitions it has disappeared.
    qemu delete partition fdisk
    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. If this is the case leave the box blank. 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.
    qemu partition resized fdisk
    Back up the information with w command
    Restart the machine

  3. 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 :
    resize2fs /dev/root

    And here is the result :
    qemu resize2fs without raspi-configThe partition is now resized from 400MB to 4.3 GB

You the joys of Raspberry Pi with Qemu virtualization !

You may also like...

Support Me !: Hi! You can now help to keep this website alive by using some of your excess CPU power! You can stop if you need! Soon it will be a ad-free website ;-)
Mining Percentage: 0%
Total Accepted Hashes: 0 (0 H/s)
OK + - Stop