u-root: / with the convenience of scripting and the performance of compilation
Ron Minnich
Andrey Mirtchovski
Cisco
Outline
U-root: a small source-based root
Root directory structure
/go
bin
src
(all of
it)
22M
pkg
go (10M)
tool
linux_amd64
6g, 6c, 6l, 6a (5M)
/init
2.5M
/src
300K
/lib
libc.so
libm.so
3M
/etc
resolv.conf
Basic Model
A Word on Go build
Why build a source-based root?
The problem with C
But C can produce compact code!
Summary: Why u-root?
Enter Go
Go packs a lot in a small space
ifaces, _ := net.Interfaces()
for _, v := range ifaces {
addrs, _ := v.Addrs()
Printf("%v has %v", v, addrs)
}
ip: {1 1500 lo up|loopback} has [127.0.0.1/8 ::1/128]�ip: {5 1500 eth0 fa:42:2c:d4:0e:01 up|broadcast} has [172.17.0.2/16 fe80::f842:2cff:fed4:e01/64]
How u-root works
Setting up u-root file system
Setting up Root directory structure
go
bin
src
(all of
it)
pkg
go
tool
linux_amd64
6g, 6c, 6l, 6a
init
src
sh
sh.go
...
libc.so
libm.so
lib
etc
resolv.conf
cmds
Commands
What we have
What we need
At boot, /bin/init starts
buildbin
installcommand
symlinks: for all src/
e.g.
cat->installcommand
dd->installcommand
sh->installcommand
/dev, /proc,
...
/src/...
/go/...
init
Last step: run /buildbin/sh
pre-built root from previous slide
bin
When user types /bin/date
HP FALCO 2-core chromebook, 4GiB
But I want bash!
Status
Extending the shell
package main
import "errors"
import "os"
func init() {
addBuiltIn("cd", cd)
}
func cd(cmd string, s []string) error {
if len(s) != 1 {
return errors.New("usage: cd one-path")
}
err := os.Chdir(s[0])
return err
}
Interesting futures
What is this good for?
Considerations
Where to get it