Skip to content
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

run kernel in chroot #34

Merged
merged 3 commits into from
Nov 2, 2023
Merged

run kernel in chroot #34

merged 3 commits into from
Nov 2, 2023

Conversation

chantra
Copy link
Collaborator

@chantra chantra commented Oct 31, 2023

Insteads of mounting the local FS'root, we can do the same but in a chroot. The main benefit would be to be able to run a kernel/artifacts in a guest FS which may be different then the host FS. For instance when collecting CI artifacts and trying to reproduce locally.
CI may run in say Ubuntu 22.04 , while my host may be Fedora 38. This also opens up for a next diff where we can run againdt a foreign architecture provided that the chrrot is for that arch.

$ cat /etc/debian_version && RUST_LOG=debug cargo run -- -k $KERNEL_REPO/arch/x86_64/boot/bzImage -r debian 'cat /etc/debian_version'
trixie/sid
   Compiling vmtest v0.8.3 (/home/chantra/devel/danobi-vmtest)
    Finished dev [unoptimized + debuginfo] target(s) in 8.11s
     Running `target/debug/vmtest -k /home/chantra/devel/bpf-next//arch/x86_64/boot/bzImage -r debian 'cat /etc/debian_version'`
=> bzImage
===> Booting
===> Setting up VM
===> Running command
11.5
bash: line 1: cd: /home/chantra/devel/danobi-vmtest: No such file or directory

Also tested that it would work when configured in vmtest.toml

$ RUST_LOG=debug cargo run --
   Compiling vmtest v0.8.3 (/home/chantra/devel/danobi-vmtest)
    Finished dev [unoptimized + debuginfo] target(s) in 2.50s
     Running `target/debug/vmtest`
=> Alt RootFS
===> Booting
===> Setting up VM
===> Running command
11.5
bash: line 1: cd: /home/chantra: No such file or directory
=> Standard RootFS
===> Booting
===> Setting up VM
===> Running command
trixie/sid
$ cat vmtest.toml
[[target]]
name = "Alt RootFS"
kernel = "/home/chantra/devel/bpf-next//arch/x86_64/boot/bzImage"
command = "cat /etc/debian_version"
rootfs = "debian"

[[target]]
name = "Standard RootFS"
kernel = "/home/chantra/devel/bpf-next//arch/x86_64/boot/bzImage"
command = "cat /etc/debian_version"

@chantra chantra force-pushed the alternative_chroot branch 2 times, most recently from a5eb528 to 205d78e Compare October 31, 2023 05:16
Copy link
Owner

@danobi danobi left a comment

Choose a reason for hiding this comment

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

small nits, lgtm otherwise

src/qemu.rs Outdated Show resolved Hide resolved
src/qemu.rs Show resolved Hide resolved
Copy link
Owner

@danobi danobi left a comment

Choose a reason for hiding this comment

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

yeah, this reads a bit more clear. thanks for that.

test can go in followup PR

Insteads of mounting the local FS'root, we can do the same but in a chroot.
The main benefit would be to be able to run a kernel/artifacts in a guest FS
which may be different then the host FS. For instance when collecting CI artifacts
and trying to reproduce locally.
CI may run in say Ubuntu 22.04 , while my host may be Fedora 38.
This also opens up for a next diff where we can run againdt a foreign architecture
provided that the chrrot is for that arch.
```
$ cat /etc/debian_version && RUST_LOG=debug cargo run -- -k $KERNEL_REPO/arch/x86_64/boot/bzImage -r debian 'cat /etc/debian_version'
trixie/sid
   Compiling vmtest v0.8.3 (/home/chantra/devel/danobi-vmtest)
    Finished dev [unoptimized + debuginfo] target(s) in 8.11s
     Running `target/debug/vmtest -k /home/chantra/devel/bpf-next//arch/x86_64/boot/bzImage -r debian 'cat /etc/debian_version'`
=> bzImage
===> Booting
===> Setting up VM
===> Running command
11.5
bash: line 1: cd: /home/chantra/devel/danobi-vmtest: No such file or directory
```

Also tested that it would work when configured in `vmtest.toml`

```
$ RUST_LOG=debug cargo run --
   Compiling vmtest v0.8.3 (/home/chantra/devel/danobi-vmtest)
    Finished dev [unoptimized + debuginfo] target(s) in 2.50s
     Running `target/debug/vmtest`
=> Alt RootFS
===> Booting
===> Setting up VM
===> Running command
11.5
bash: line 1: cd: /home/chantra: No such file or directory
=> Standard RootFS
===> Booting
===> Setting up VM
===> Running command
trixie/sid
$ cat vmtest.toml
[[target]]
name = "Alt RootFS"
kernel = "/home/chantra/devel/bpf-next//arch/x86_64/boot/bzImage"
command = "cat /etc/debian_version"
rootfs = "debian"

[[target]]
name = "Standard RootFS"
kernel = "/home/chantra/devel/bpf-next//arch/x86_64/boot/bzImage"
command = "cat /etc/debian_version"
```

Signed-off-by: Manu Bretelle <[email protected]>
…path)

If this is not the case, the guest is not going to be able to find the init
file we pass as a parameter of `init=`.
We better error out than having a VM that fails to boot properly.

Signed-off-by: Manu Bretelle <[email protected]>
@chantra
Copy link
Collaborator Author

chantra commented Nov 1, 2023

yeah, this reads a bit more clear. thanks for that.

test can go in followup PR

I added them as separate commits.

@chantra
Copy link
Collaborator Author

chantra commented Nov 1, 2023

the failed test seems to be environmental more than anything.

@danobi
Copy link
Owner

danobi commented Nov 1, 2023

I wonder if GH changed something today. The EPERM error looks kinda similar to the large runner thing you have to do: https://github.com/danobi/vmtest-action/blob/fed44e099e1e7b79251780393453929ab20d107e/vmtest.js#L48-L62

@chantra
Copy link
Collaborator Author

chantra commented Nov 1, 2023

I wonder if GH changed something today. The EPERM error looks kinda similar to the large runner thing you have to do: https://github.com/danobi/vmtest-action/blob/fed44e099e1e7b79251780393453929ab20d107e/vmtest.js#L48-L62

yeah, they may start presenting /dev/kvm and because no permission is checked it tries to enable kvm while it does not have access.

@danobi danobi merged commit 5b6d99b into danobi:master Nov 2, 2023
1 of 2 checks passed
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.

2 participants