Skip to content

Support mounting rootfs from virtio-blk via initrd #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shengwen-tw
Copy link
Collaborator

@shengwen-tw shengwen-tw commented Jun 1, 2025

Overview

Due to the 1 GiB kernel space limit on RV32-Linux, embedding large root filesystems in the kernel image can be impractical for certain testing scenarios.

This commit introduces a script to generate a mountable ext4 rootfs image and modifies the init script to support switching the root filesystem to a virtio-blk device.

During boot, the init script checks whether /dev/vda contains a valid rootfs. If so, it switches the root to the virtio-blk device. Otherwise, it falls back to the default initramfs.

Testing Procedures

1. Build Linux kernel and rootfs CPIO

$ cd semu/
$ ./scripts/build-image.sh --all

2. Generate external rootfs image

$ ./scripts/build-image.sh --all --external-root

3. Launch the simulator

$ make check

Expected Output
The console output should indicate that the root filesystem was successfully mounted from /dev/vda:

[    5.383305] Run /init as init process
[*] Attempting to mount /dev/vda
[    6.029600] EXT4-fs (vda): recovery complete
[    6.029600] EXT4-fs (vda): mounted filesystem with ordered data mode. Quota mode: disabled.
[*] /dev/vda mounted successfully. Checking for root filesystem...
[*] Valid root filesystem found. Switching root to /dev/vda

References

@shengwen-tw shengwen-tw requested a review from jserv June 1, 2025 16:39
@jserv jserv requested a review from ChinYikMing June 1, 2025 16:40
@shengwen-tw shengwen-tw force-pushed the switch_root branch 2 times, most recently from df27770 to 5d4ca98 Compare June 2, 2025 15:06
@jserv
Copy link
Collaborator

jserv commented Jun 3, 2025

Testing Procedures

Can you refine the testing procedures? I expect to run scripts/build-image.sh to generate images, which are required for 'check' target, without post-processing.

Copy link
Collaborator

@ChinYikMing ChinYikMing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update the README to document support for this feature, including use cases for switching to this rootfs mounting method?

@shengwen-tw
Copy link
Collaborator Author

I've updated build-image.sh to support generating both initramfs and external rootfs. Additionally, I’ve introduced several new options to improve usability. Once we finalize the design, I’ll update the README.md accordingly.

Usage: ./scripts/build-image.sh [--buildroot] [--linux] [--all] [--external-root] [--clean-build] [--help]

Options:
  --buildroot         Build Buildroot rootfs
  --linux             Build Linux kernel
  --all               Build both Buildroot and Linux
  --external-root     Use external rootfs instead of initramfs
  --clean-build       Remove entire buildroot/ and/or linux/ directories before build
  --help              Show this message

@jserv
Copy link
Collaborator

jserv commented Jun 4, 2025

I plan to merge #82 prior to this pull request, so that we can validate Linux v6.12 (another LTS kernel).

Comment on lines 31 to 43
if [ ! -f buildroot/.config ]; then
echo "Copying buildroot.config -> buildroot/.config"
cp -f configs/buildroot.config buildroot/.config
else
echo "buildroot/.config already exists, skipping copy"
fi

if [ ! -f buildroot/busybox.config ]; then
echo "Copying busybox.config -> buildroot/busybox.config"
cp -f configs/busybox.config buildroot/busybox.config
else
echo "buildroot/busybox.config already exists, skipping copy"
fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create bash function to avoid duplication.

@jserv
Copy link
Collaborator

jserv commented Jun 4, 2025

Rebase the latest master branch.

@shengwen-tw shengwen-tw force-pushed the switch_root branch 2 times, most recently from 0794981 to 00a1cf7 Compare June 4, 2025 13:00
Due to the 1 GiB kernel space limit on RV32-Linux, embedding large root
filesystems in the kernel image can be impractical for certain testing
scenarios.

This commit introduces a script to generate a mountable ext4 rootfs image and
modifies the init script to support switching the root filesystem to a
virtio-blk device.

During boot, the init script checks whether /dev/vda contains a valid rootfs.
If so, it switches the root to the virtio-blk device. Otherwise, it falls back
to the default initramfs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants