Skip to content

Commit fa9f84a

Browse files
Update README.md networking how to combine ipxe
1 parent 7453eea commit fa9f84a

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

README.md

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Goal is to have mimimal but realistic node with network capabilities build in (`
1515
- Rememebr busybox needs to be static build (see .config)
1616
- <strike>dropbear needs at least a `dropbear_rsa_host_key` key config or will not start see [gist](https://gist.github.com/mad4j/7983719) </strike>
1717
- Prefering openssh for end user compatability (statically built)
18+
19+
## Things you need to build
20+
21+
See [./build-all.sh](./build-all.sh)
1822

1923
### How do I extract an `initramfs` / `initrd` gz cpio archive, view it's `init` script and repackage?
2024

@@ -53,13 +57,79 @@ find . | cpio -o -H newc | gzip > ../my-new-rootfs.cpio.gz
5357

5458
You then might want to re-run your `qemu` debugging process: See [](https://github.com/KarmaComputing/minimal-linux-boot-coreutils/blob/c64027b54b12d488f83cef75b5fbfee3d444e661/run-qemu.sh#L5)- remembering to change the `-initrd rootfs.cpio.gz` argument.
5559

56-
<strike>TODO: add [iproute2](https://github.com/iproute2/iproute2) for minimal routing.</strike>
60+
## How do I use `ipxe` to provide dynamic kernel parameters at bootime, such as `ip=` kernel options?
5761

58-
## Things you need to build
62+
Booting with `qemu-system-x86_64` and [passing kernel options like `ip=` using the `append=` qemu options](https://github.com/KarmaComputing/minimal-linux-boot-coreutils/blob/7453eea727732761152ec306e822d54a4587934a/run-qemu.sh#L5) is great an all, (see also [debugging-linux-kernel-bootstrap-with-qemu](https://github.com/KarmaComputing/debugging-linux-kernel-bootstrap-with-qemu)), but how can I harness `iPXE` to provide `-append` kernel options dynamically via http✨?
63+
64+
Fun fact, qemu actually bundles/uses `iPXE` internally. But ignore that. We're going to build and pass iPXE as an ISO to demonstrate booting from `iPXE` to set dynamic kernel options, opening up the possibility to boot from anywhere. The steps in brief (explained in detail after) are:
65+
66+
1. Read the iPXE docs
67+
2. Clone iPXE
68+
3. Write your own `script.ipxe`
69+
4. Build your own `iPXE` ISO which bundles that iPXE script
70+
5. 'Start' your machine ( `qemu-system-x86_64` , in this instance simulating a bare metal server), passing qemu the `-boot d -cdrom image.iso` options
71+
6. Observe your virtual bare metal 'machine' do whatever you tell it to do (see step 1, did you see the [section about UEFI](https://ipxe.org/download#:~:text=128kB%20in%20size.-,UEFI,-iPXE%20supports%20both)?).
72+
73+
```
74+
#1. iPXE.org docs https://ipxe.org/docs
75+
76+
# 2.
77+
git clone https://github.com/ipxe/ipxe.git
78+
cd ipxe/src
79+
make # yes you have to do this, for all other build targets to be available. You'll probably be missing `build-essential` packages needed to build, so read the output, research and install any missing dependencies.
80+
# Again, the docs are helpful here https://ipxe.org/download#:~:text=You%20will%20need%20to%20have%20at%20least%20the%20following%20packages%20installed%20in%20order%20to%20build%20iPXE
81+
82+
3. For example, given a manual `qemu` boot (which we'll put iPXE infront of momenterily) consider first the following which boots linux, and simulates a Network interface card (NIC) on
83+
the host using [qemu SLIRP user networking](https://wiki.qemu.org/Documentation/Networking#:~:text=Network%20backend%20types) because its the most compatible friendly *documentation* approach for
84+
networking (using tun/tap is 'better'/faster):
85+
86+
```
87+
qemu_args=(
88+
-enable-kvm # utilize hardware virtualization of processors
89+
-cpu max # Enables all features supported by the accelerator in the current host
90+
-smp 4
91+
-m 4096
92+
-kernel vmlinuz-lts
93+
-initrd new-initramfs-lts
94+
-serial mon:stdio # multiplex the QEMU Monitor with the serial port output
95+
# Since we're using -serial, ask linux to direct kernel log to the serial
96+
# so we can see it, withou this -append, we won't see the kernel boot log
97+
# As there is no default graphical device we disable the display
98+
# as we can work entirely in the terminal.
99+
-display none
100+
-device virtio-net-pci,netdev=mynet0
101+
-netdev user,id=mynet0,dns=1.1.1.1
102+
)
103+
# Start qemu with the above args
104+
qemu-system-x86_64 "${qemu_args[@]}"
105+
```
106+
The above would start your linux instance, you'd then *manually* configure addressing on the virtual network card with the following:
107+
ip link set dev eth0 up
108+
ip addr add 10.0.2.10/24 dev eth0
109+
ip route get 1.1.1.1 # no root to host
110+
ip route add default via 10.0.2.2
111+
ip route get 1.1.1.1 # Now you have a route to host :)
112+
# Where did 10.0.2.2 come from? It's the gateway default when using qemu SLIRP network, see the image
113+
# on that page https://wiki.qemu.org/Documentation/Networking#:~:text=Network%20backend%20types it's trying
114+
# to tell you the default addressing scheme- did you notice valid host addresses start from address .9?
115+
# https://wiki.qemu.org/Documentation/Networking#:~:text=24%20instead%20of-,the%20default,-(10.0.2.0/24)%20and
116+
# I've read that page for years and it's still only just clicking.. they're not magic numbers they are defaults :)
117+
wget google.com # You'll see 'bad address'
118+
# For the same reasons (reading qemu SLIRP networking docs), you'll need to remember to set the nameserver to 10.0.2.3
119+
echo "nameserver 10.0.2.3" > /etc/resolv.conf
120+
wget google.com # Now DNS is configured, you'll hapily succeed with google.com being downloaded.
121+
# Pings won't work with SLIRP- unless enabled, if you need that agian, docs you've read the docs right?
122+
https://wiki.qemu.org/Documentation/Networking#:~:text=and%20guestfwd%20options.-,Enabling,-ping%20in%20the
123+
```
124+
Those same tedious networking steps above need to be
125+
- encoded into a `script.ipxe` (setting the if up - using the iPXE commands e.g. https://ipxe.org/cmd/ifopen , and all https://ipxe.org/cmd)
126+
.. TODO finish writing up
127+
128+
129+
<strike>TODO: add [iproute2](https://github.com/iproute2/iproute2) for minimal routing.</strike>
59130

60-
See [./build-all.sh](./build-all.sh)
61131

62-
# What does this repo not include (yet)
132+
## What does this repo not include (yet)
63133

64134
- Automated ci
65135

0 commit comments

Comments
 (0)