Giter Site home page Giter Site logo

rminnich / u-root Goto Github PK

View Code? Open in Web Editor NEW

This project forked from u-root/u-root

13.0 5.0 1.0 131.52 MB

A universal root. You mount it, and it's mostly Go source with the exception of 5 binaries.

License: BSD 3-Clause "New" or "Revised" License

Shell 0.02% Go 99.01% Assembly 0.13% HTML 0.37% CSS 0.06% Dockerfile 0.23% Python 0.17% Makefile 0.01%

u-root's Introduction

u-root

Build Status Go Report Card GoDoc License

Description

u-root contains simple Go versions of many standard Linux tools, similar to busybox. It's a pure Go userland!

u-root stands for "universal root". It can create an initramfs in two different modes:

  • source mode: Go toolchain binaries + simple shell + Go source for tools to be compiled on the fly by the shell.

    When you try to run a command that is not built, it is compiled first and stored in tmpfs. From that point on, when you run the command, you get the one in tmpfs. Don't worry: the Go compiler is pretty fast.

  • bb mode: One busybox-like binary comprising all the Go tools you ask to include.

    In this mode, u-root copies and rewrites the source of the tools you asked to include to be able to compile everything into one busybox-like binary.

Usage

Make sure your Go version is 1.11. Make sure your GOPATH is set up correctly.

Download and install u-root:

go get github.com/u-root/u-root

You can now use the u-root command to build an initramfs. Here are some examples:

# Build a bb-mode cpio initramfs of all the Go cmds in ./cmds/...
u-root -build=bb

# Generate a cpio archive named initramfs.cpio.
u-root -format=cpio -build=source -o initramfs.cpio

# Generate a bb-mode archive with only these given commands.
u-root -format=cpio -build=bb ./cmds/{init,ls,ip,dhclient,wget,tcz,cat}

-format=cpio and -build=source are the default flag values. The default set of packages included is all packages in github.com/u-root/u-root/cmds/....

In addition to using paths to specify Go source packages to include, you may also use Go package import paths (e.g. golang.org/x/tools/imports) to include commands. Only the main package and its dependencies in those source directories will be included. For example:

You can build the initramfs built by u-root into the kernel via the CONFIG_INITRAMFS_SOURCE config variable or you can load it separately via an option in for example Grub or the QEMU command line or coreboot config variable.

A good way to test the initramfs generated by u-root is with qemu:

qemu-system-x86_64 -kernel path/to/kernel -initrd /tmp/initramfs.linux_amd64.cpio

Note that you do not have to build a special kernel on your own, it is sufficient to use an existing one. Usually you can find one in /boot.

NOTE: you can compress the initramfs but for xz compression, the kernel has some restrictions on the compression options and it is suggested to align the file to 512 byte boundaries shell xz --check=crc32 -9 --lzma2=dict=1MiB --stdout /tmp/initramfs.linux_amd64.cpio \ | dd conv=sync bs=512 of=/tmp/initramfs.linux_amd64.cpio.xz

You may also include additional files in the initramfs using the -files flag. If you add binaries with -files are listed, their ldd dependencies will be included as well. As example for Debian, you want to add two kernel modules for testing, executing your currently booted kernel:

NOTE: these files will be placed in the $HOME dir in the initramfs.

u-root -files "$HOME/hello.ko $HOME/hello2.ko"
qemu-system-x86_64 -kernel /boot/vmlinuz-$(uname -r) -initrd /tmp/initramfs.linux_amd64.cpio

To specify the location in the initramfs, use <sourcefile>:<destinationfile>. For example:

u-root -files "root-fs/usr/bin/runc:usr/bin/run"

Getting Packages of TinyCore

Using the tcz command included in u-root, you can install tinycore linux packages for things you want.

You can use QEMU NAT to allow you to fetch packages. Let's suppose, for example, you want bash. Once u-root is running, you can do this:

% tcz bash

The tcz command computes and fetches all dependencies. If you can't get to tinycorelinux.net, or you want package fetching to be faster, you can run your own server for tinycore packages.

You can do this to get a local server using the u-root srvfiles command:

% srvfiles -p 80 -d path-to-local-tinycore-packages

Of course you have to fetch all those packages first somehow :-)

Build an Embeddable U-root

You can build this environment into a kernel as an initramfs, and further embed that into firmware as a coreboot payload.

In the kernel and coreboot case, you need to configure ethernet. We have a dhclient command that works for both ipv4 and ipv6. Since v6 does not yet work that well for most people, a typical invocation looks like this:

% dhclient -ipv4 -ipv6=false

Or, on newer linux kernels (> 4.x) boot with ip=dhcp in the command line, assuming your kernel is configured to work that way.

Updating Dependencies

# The latest released version of dep is required:
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure

Hardware

If you want to see u-root on real hardware, this board is a good start.

Contributions

See CONTRIBUTING.md

Improving existing commands (e.g., additional currently unsupported flags) is very welcome. In this case it is not even required to build an initramfs, just enter the cmds/ directory and start coding. A list of commands that are on the roadmap can be found here.

u-root's People

Contributors

rminnich avatar rjoleary avatar hugelgupf avatar thienhoang23 avatar rminnichcodeu avatar jbeta51 avatar ananya-joshi avatar tklauser avatar insomniacslk avatar bkochendorfer avatar bensallen avatar ryukinix avatar rck avatar trevorfarrelly avatar laconicpneumonic avatar mishrashivendra avatar rhiguita avatar xchenan avatar n-canter avatar tfg13 avatar claudiozz avatar ganshun avatar teknoraver avatar ddiss avatar bluecmd avatar mirtchovski avatar rafaelcn avatar flammit avatar floren avatar shwoop avatar

Stargazers

1v4n avatar  avatar Viktor Slavkovic avatar Raptor Lin avatar Satoru Takeuchi avatar  avatar Joseph Lewis III avatar J Farkas avatar BVK Chaitanya avatar  avatar caivega avatar  avatar Eric Myhre avatar

Watchers

 avatar  avatar James Cloos avatar  avatar  avatar

Forkers

agileinsider

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.