Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

mount kernel filesystems if run as pid1 #18

Merged
merged 8 commits into from Sep 29, 2022

Conversation

Vincinator
Copy link
Collaborator

Hi aurae community,

This PR adds first steps to make auraed boot as pid1, mainly mounting the kernel filesystems (devfs, procfs and sysfs), but also some minor fixes to make auraed boot without kernel panic.

  • Fixes kernel panic due to a rust panic thrown by syslog creation (missing unix sockets [1])
    • The rust panic causes auraed to stop, and if started as pid1 the kernel will in turn also panic because the init process ended.
  • Fixes hack/hack.mk for zsh users
  • Adds a SystemRuntime (analog to AuraedRuntime), which handles system preparation.
    • SystemRuntime Case: not-pid1
      • assume a systemd environment (currently only unix socket /var/run/syslog)
    • SystemRuntime Case: pid1
      • initializes logging without unix socket dependency. Using syslog crate would require creation of unix socket first, and I suggest to discuss this first if there is a use case to have a unix socket for logging.
      • mounts file based kernel interfaces
      • devfs, sysfs, procfs
  • Added helper functions for basic file io (currently for devfs, sysfs, procfs interfaces)
    • get content of e.g. /dev, /sys or /proc
    • or /sys/class/net/ to see available network interfaces

ToDo:

  • Discuss Logging targets
    • Same log targets for all SystemRuntime cases?
  • Network initialization
  • Stop auraed in pid1 case gracefully (kernel halt syscall to shutdown or reboot)

How to test

Steps to run auraed as pid in a qemu vm are documented in the hack/README.md. Copy pasted them here:

make build-container
make kernel
make initramfs

# create `vm-br0` bridge on your machine:
make network

# run auraed in a VM as pid 1:
make virsh-start virsh-console virsh-stop

# exit VM console with Ctrl+]

Screenshot 2022-09-27 at 17 01 29

Links

[1] https://docs.rs/syslog/latest/src/syslog/lib.rs.html#232-243

* Mount devfs, sysfs and procfs
* (optional and early draft): Basic fileio helper
  * depends on walkdir crate
* only use syslog logger if not run as pid1
  * Syslog requires unix sockets /dev/log or /var/run/syslog.
  * These sockets need to be set up first by auraed if we want to use them. Suggesting a discussion first.
@cla-bot
Copy link

cla-bot bot commented Sep 28, 2022

In order to contribute to an Aurae project you must sign and agree to the CLA.

@MalteJ
Copy link
Contributor

MalteJ commented Sep 28, 2022

@cla-bot check

@cla-bot
Copy link

cla-bot bot commented Sep 28, 2022

In order to contribute to an Aurae project you must sign and agree to the CLA.

@cla-bot
Copy link

cla-bot bot commented Sep 28, 2022

Rechecking your CLA permissions. Remember to add your GitHub username to the .clabot file. You can run @cla-bot check any time to check again.

@Vincinator
Copy link
Collaborator Author

@cla-bot check

@cla-bot
Copy link

cla-bot bot commented Sep 28, 2022

In order to contribute to an Aurae project you must sign and agree to the CLA.

@cla-bot
Copy link

cla-bot bot commented Sep 28, 2022

Rechecking your CLA permissions. Remember to add your GitHub username to the .clabot file. You can run @cla-bot check any time to check again.

@cla-bot
Copy link

cla-bot bot commented Sep 28, 2022

In order to contribute to an Aurae project you must sign and agree to the CLA.

@MalteJ
Copy link
Contributor

MalteJ commented Sep 28, 2022

@cla-bot check

@cla-bot
Copy link

cla-bot bot commented Sep 28, 2022

Rechecking your CLA permissions. Remember to add your GitHub username to the .clabot file. You can run @cla-bot check any time to check again.

@@ -0,0 +1,93 @@
use log::*;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add the header please?

// To Discuss (TODO):
// The "syslog" logger requires unix sockets.
// Syslog assumes that either /dev/log or /var/run/syslog are available [1].
// We need to discuss if there is a use case to log via unix sockets,
Copy link
Contributor

Choose a reason for hiding this comment

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

In general the project should support the ability to log to a unix socket, however this is a fine starting point for right now.

Opened #24 to track the work.

std::process::id()
}

pub fn print_logo() {
Copy link
Contributor

Choose a reason for hiding this comment

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

So I love the logo! I already tweeted it! https://twitter.com/krisnova/status/1575274332665815044

Can we break this into 2 functions?

pub fn banner() -> String {
    format!("...")
}

and a 2nd function that prints the output of the first?

pub fn print_logo() -> String {
    println!("{}", banner())
}

I plan on using the banner in other places in the program eventually :)


mount_vfs("none", "/dev", "devtmpfs");
mount_vfs("none", "/sys", "sysfs");
mount_vfs("proc", "/proc", "proc");
Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds a bit crazy, however I have a use case for a system where procfs is NOT mounted.

Is it possible to add a compile time flag or similar to run auraed in an extremely risky experimental mode where procfs is not mounted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure! Will add a simple and fast solution to this PR. Maybe it makes sense to have the mount points configurable? Opened an issue here to discuss and track #25

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a noprocfs kernel parameter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I was too optimistic that I can add this fast and simple. Added my comment to the discussion on discord.

I think this requires a second PR

@@ -0,0 +1,31 @@
use std::fs;
Copy link
Contributor

Choose a reason for hiding this comment

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

Header

Copy link
Contributor

@krisnova krisnova left a comment

Choose a reason for hiding this comment

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

My suggestion is to go ahead and merge this whenever you feel confident @Vincinator

You should be able to merge now. I will rebase #17 on top of your work, and I encourage you to iterate as you see best. If you would like to pick up more features in subsequent PRs please continue to work however is best for you.

@krisnova
Copy link
Contributor

Non blocker however I am wondering about the name system for a module for init. This seems to be overloaded. I am unsure how I feel about it. Does anyone else have any thoughts?

@Vincinator
Copy link
Collaborator Author

Non blocker however I am wondering about the name system for a module for init. This seems to be overloaded. I am unsure how I feel about it. Does anyone else have any thoughts?

My vote goes to naming it init. Current scope is just initialization of stuff for the user space.

@Vincinator Vincinator changed the title WIP: mount kernel filesystems if run as pid1 mount kernel filesystems if run as pid1 Sep 29, 2022
@Vincinator
Copy link
Collaborator Author

@kris-nova this PR is ready to be merged from my point of view
Thanks for your feedback!

@krisnova
Copy link
Contributor

Note for myself. Configuration to remove /proc procfs(5) is in this issue: #25

@krisnova krisnova merged commit e3a871d into aurae-runtime:main Sep 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants