Skip to content

Commit b163957

Browse files
committed
add -device network information
1 parent b61481f commit b163957

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

README.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,50 +77,77 @@ Booting with `qemu-system-x86_64` and [passing kernel options like `ip=` using t
7777

7878
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:
7979

80-
1. Read the iPXE docs
80+
1. Read the [iPXE docs](https://ipxe.org/docs)
8181
2. Clone iPXE
8282
3. Write your own `script.ipxe`
8383
4. Build your own `iPXE` ISO which bundles that iPXE script
8484
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
8585
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)?).
8686

87+
Let's do the above for real!
88+
8789
```bash
88-
#1. iPXE.org docs https://ipxe.org/docs
90+
#1. Read iPXE.org docs https://ipxe.org/docs
8991

9092
# 2.
9193
git clone https://github.com/ipxe/ipxe.git
9294
cd ipxe/src
93-
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.
94-
# 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
95+
git checkout 2e8d45aeef813e7b25b4ac949d1407bc7ecd2ea8 # to keep docs valid. You may want to checkout a newer version by the time you read this
96+
make -j # yes you have to make initially, for all other build targets to be available.
97+
# When make fails, you'll probably be missing `build-essential` packages needed to build, so read the output, research and install any missing dependencies.
98+
# 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
99+
```
95100

96-
3. For example, given a manual `qemu` boot (which we'll put iPXE
101+
3. Now lets boot a kernel image & initramfs *without* iPXE first. For example, given a manual `qemu` boot (which we'll put iPXE
97102
in-front of momentarily) consider first the following which
98103
boots linux, and simulates a Network interface card (NIC) on
99104
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
100105
networking (using tun/tap is 'better'/faster):
101106

107+
To run the below, you'll need At this point you're wishing you have ran `build-all.sh` successfully, if you haven't [here's one](https://boot.karmacomputing.co.uk/iso/alpine-netboot/boot/vmlinuz-lts) and but please don't use those, build you own ([./build-all.sh](./build-all.sh)) so you know what's in it.
108+
109+
```bash
110+
# You should not use these, you should build you own! :) see build-all.sh
111+
# Get a linux kernel image
112+
wget https://boot.karmacomputing.co.uk/iso/alpine-netboot/boot/vmlinuz-lts
113+
# Get an external initramfs cpio bundle (for understanding read)
114+
# https://docs.kernel.org/filesystems/ramfs-rootfs-initramfs.html
115+
wget https://boot.karmacomputing.co.uk/iso/alpine-netboot/boot/initramfs-lts
116+
```
117+
118+
```bash
119+
102120

103121
qemu_args=(
104122
-enable-kvm # utilize hardware virtualization of processors
105123
-cpu max # Enables all features supported by the accelerator in the current host
106124
-smp 4
107125
-m 4096
108126
-kernel vmlinuz-lts
109-
-initrd new-initramfs-lts
127+
-initrd initramfs-lts
110128
-serial mon:stdio # multiplex the QEMU Monitor with the serial port output
111129

112130
# Since we're using -serial, ask linux to direct kernel log to the serial
113131
# so we can see it, without this -append, we won't see the kernel boot log
114132
# As there is no default graphical device we disable the display
115133
# as we can work entirely in the terminal.
134+
-append "console=ttyS0 init=/sbin/init"
116135
-display none
136+
# This '-device' option is what creates the emulated network hardware (amazing, thanks qemu) well, it's virtio based, but
137+
# think of this as qemu 'plugging in' a hardware network card for you- cool! It's not immediately obvious from the docs,
138+
# but to do *useful* things like provide networking options on the command line,
139+
# you also need to use the `-netdev` option as explained in the Qemu docs:
140+
# https://wiki.qemu.org/Documentation/Networking#:~:text=QEMU%20will%20require%20you%20to%20provide%20options%20sufficient%20to%20define%20and%20connect%20up%20both%20parts
117141
-device virtio-net-pci,netdev=mynet0
142+
# Oh look, the id= of the netdev matches the netdev option of the -device argument.
118143
-netdev user,id=mynet0,dns=1.1.1.1
119144
)
120145
# Start qemu with the above args
121146
qemu-system-x86_64 "${qemu_args[@]}"
122147
```
123148

149+
150+
124151
The above would start your linux instance, you'd then *manually* configure addressing on the virtual network card with the following:
125152

126153
```shell
@@ -177,10 +204,11 @@ Those same tedious networking steps above need to be:
177204

178205
See https://lists.gnu.org/archive/html/coreutils/2019-04/msg00001.html </strike> switched to using `musl`.
179206

207+
## Reading
180208

181-
# Reading
182209
See also
183210

211+
https://docs.kernel.org/filesystems/ramfs-rootfs-initramfs.html
184212
https://wiki.gentoo.org/wiki/Custom_Initramfs
185213
https://unix.stackexchange.com/a/305406
186214
https://landley.net/writing/rootfs-howto.html

0 commit comments

Comments
 (0)