Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Feb 20, 2024
1 parent fe1a0a4 commit 42b7bc1
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ Or install directly with go:
go install github.com/u-root/mkuimage/cmd/mkuimage@latest
```

**Note: The `mkuimage` command will end up in `$GOPATH/bin/mkuimage`, so you may
need to add `$GOPATH/bin` to your `$PATH`.**
> [!NOTE]
> The `mkuimage` command will end up in `$GOPATH/bin/mkuimage`, so you may
> need to add `$GOPATH/bin` to your `$PATH`.
## Examples

Expand All @@ -42,73 +43,61 @@ git clone https://github.com/u-root/cpu
Build gobusybox binaries of these two commands and add to initramfs:

```shell
mkuimage ./u-root/cmds/core/{init,gosh}
```
<details>
<summary>Result</summary>
$ mkuimage ./u-root/cmds/core/{init,gosh}

<pre>
$ cpio -ivt < /tmp/initramfs.linux_amd64.cpio
...
-rwxr-x--- 0 root root 4542464 Jan 1 1970 bbin/bb
lrwxrwxrwx 0 root root 2 Jan 1 1970 bbin/gosh -> bb
lrwxrwxrwx 0 root root 2 Jan 1 1970 bbin/init -> bb
...
</pre>
</details>
```

Add symlinks for shell and init:

```shell
mkuimage -initcmd=init -defaultsh=gosh ./u-root/cmds/core/{init,gosh}
```
<details>
<summary>Result</summary>
# mkuimage -initcmd=init -defaultsh=gosh ./u-root/cmds/core/{init,gosh}

<pre>
$ cpio -ivt < /tmp/initramfs.linux_amd64.cpio
...
lrwxrwxrwx 0 root root 12 Jan 1 1970 bin/defaultsh -> ../bbin/gosh
lrwxrwxrwx 0 root root 12 Jan 1 1970 bin/sh -> ../bbin/gosh
...
lrwxrwxrwx 0 root root 9 Jan 1 1970 init -> bbin/init
...
</pre>
</details>
```

Build everything from core without ls and losetup:

```shell
mkuimage ./u-root/cmds/core/* -./u-root/cmds/core/{ls,losetup}
$ mkuimage ./u-root/cmds/core/* -./u-root/cmds/core/{ls,losetup}
```

Build an initramfs with init, gosh and cpud in a gobusybox binary.
Build an initramfs with init, gosh and cpud in a gobusybox binary:

Note that these are 2 different modules, and cpud has a dependency on u-root.
Since no go.mod is found in the current directory, one will be synthesized as
the warning advertises.
> [!IMPORTANT]
> Since the commands are in 2 different modules, and cpud has a dependency on
> u-root, we can't build one binary without resolving the dependency issue.
>
> Since no go.mod is found in the current directory, one will be synthesized as
> the warning advertises.
```
mkuimage ./u-root/cmds/core/{init,gosh} ./cpu/cmds/cpud
```shell
$ mkuimage ./u-root/cmds/core/{init,gosh} ./cpu/cmds/cpud
...
01:24:15 INFO GBB_STRICT is not set.
01:24:15 INFO [WARNING] github.com/u-root/cpu/cmds/cpud depends on github.com/u-root/u-root @ version v0.11.1-0.20230913033713-004977728a9d
01:24:15 INFO Using github.com/u-root/u-root @ directory /home/u-root to build it.
...
```

<details>
<summary>Result</summary>
<pre>
$ cpio -ivt < /tmp/initramfs.linux_amd64.cpio
...
-rwxr-x--- 0 root root 6365184 Jan 1 1970 bbin/bb
lrwxrwxrwx 0 root root 2 Jan 1 1970 bbin/cpud -> bb
lrwxrwxrwx 0 root root 2 Jan 1 1970 bbin/gosh -> bb
lrwxrwxrwx 0 root root 2 Jan 1 1970 bbin/init -> bb
...
</pre>
</details>
```

`GBB_PATH` is a place that mkuimage will look for commands. Each colon-separated
`GBB_PATH` element is concatenated with patterns from the command-line and
Expand Down Expand Up @@ -162,10 +151,8 @@ $ cpio -ivt < /tmp/initramfs.linux_amd64.cpio
For example on Debian, if 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.
```shell
$ mkuimage -files $HOME/hello.ko -files $HOME/hello2.ko ./u-root/cmds/core/*
$ mkuimage -files "$HOME/hello.ko:etc/hello.ko" -files "$HOME/hello2.ko:etc/hello2.ko" ./u-root/cmds/core/*
$ qemu-system-x86_64 -kernel /boot/vmlinuz-$(uname -r) -initrd /tmp/initramfs.linux_amd64.cpio
```

Expand Down

0 comments on commit 42b7bc1

Please sign in to comment.