Skip to content

Commit fa0f2f1

Browse files
committed
tidy readme re quemu SLIRP userspace networking
1 parent fa9f84a commit fa0f2f1

File tree

4 files changed

+69
-35
lines changed

4 files changed

+69
-35
lines changed

.github/workflows/build-all.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
uses: actions/checkout@v4
1212

1313
- name: Install dependencies
14-
run: sudo apt-get update && sudo apt-get install -y build-essential wget git autoconf libncurses-dev bison flex libssl-dev libelf-dev
14+
run: sudo apt-get update && sudo apt-get install -y bc build-essential wget git autoconf libncurses-dev bison flex libssl-dev libelf-dev
1515

1616
- name: Run build-all.sh
1717
run: ./build-all.sh

README.md

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Fun fact, qemu actually bundles/uses `iPXE` internally. But ignore that. We're g
7070
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
7171
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)?).
7272

73-
```
73+
```bash
7474
#1. iPXE.org docs https://ipxe.org/docs
7575

7676
# 2.
@@ -79,56 +79,82 @@ cd ipxe/src
7979
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.
8080
# 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
8181

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
82+
3. For example, given a manual `qemu` boot (which we'll put iPXE
83+
in-front of momentarily) consider first the following which
84+
boots linux, and simulates a Network interface card (NIC) on
8385
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
8486
networking (using tun/tap is 'better'/faster):
8587
88+
89+
qemu_args=(
90+
-enable-kvm # utilize hardware virtualization of processors
91+
-cpu max # Enables all features supported by the accelerator in the current host
92+
-smp 4
93+
-m 4096
94+
-kernel vmlinuz-lts
95+
-initrd new-initramfs-lts
96+
-serial mon:stdio # multiplex the QEMU Monitor with the serial port output
97+
98+
# Since we're using -serial, ask linux to direct kernel log to the serial
99+
# so we can see it, without this -append, we won't see the kernel boot log
100+
# As there is no default graphical device we disable the display
101+
# as we can work entirely in the terminal.
102+
-display none
103+
-device virtio-net-pci,netdev=mynet0
104+
-netdev user,id=mynet0,dns=1.1.1.1
105+
)
106+
# Start qemu with the above args
107+
qemu-system-x86_64 "${qemu_args[@]}"
86108
```
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-
```
109+
106110
The above would start your linux instance, you'd then *manually* configure addressing on the virtual network card with the following:
111+
112+
```shell
107113
ip link set dev eth0 up
108114
ip addr add 10.0.2.10/24 dev eth0
109-
ip route get 1.1.1.1 # no root to host
115+
ip route get 1.1.1.1 # no root to host, oh no, read on!
116+
```
117+
118+
Now perform
119+
120+
```bash
110121
ip route add default via 10.0.2.2
111122
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 :)
123+
```
124+
125+
Where did 10.0.2.2 come from? It's the gateway default when using qemu SLIRP network, see the image on that page https://wiki.qemu.org/Documentation/Networking#:~:text=Network%20backend%20types it's trying
126+
to tell you the default addressing scheme.
127+
Did you notice valid host addresses start from address .9?
128+
129+
https://wiki.qemu.org/Documentation/Networking#:~:text=24%20instead%20of-,the%20default,-(10.0.2.0/24)%20and
130+
131+
(p.s) I've read that page for years and it's still only just clicking.. they're not magic numbers they are defaults :)
132+
133+
Now perform:
134+
135+
```bash
117136
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
137+
```
138+
139+
For the same reasons (reading qemu SLIRP networking docs), you'll need to remember to set the nameserver to `10.0.2.3`:
140+
141+
```bash
119142
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
143+
wget google.com # Now DNS is configured, you'll happily succeed with google.com being downloaded.
123144
```
124-
Those same tedious networking steps above need to be
145+
146+
Pings *won't* work with SLIRP- unless enabled, if you need that again, docs you've read the docs right?
147+
https://wiki.qemu.org/Documentation/Networking#:~:text=and%20guestfwd%20options.-,Enabling,-ping%20in%20the
148+
149+
150+
Those same tedious networking steps above need to be:
151+
125152
- 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)
126153
.. TODO finish writing up
127154

128155

129156
<strike>TODO: add [iproute2](https://github.com/iproute2/iproute2) for minimal routing.</strike>
130157

131-
132158
## What does this repo not include (yet)
133159

134160
- Automated ci
@@ -148,7 +174,8 @@ https://landley.net/writing/rootfs-programming.html
148174
- https://unix.stackexchange.com/questions/193066/how-to-unlock-account-for-public-key-ssh-authorization-but-not-for-password-aut
149175
- https://stackoverflow.com/a/79151188
150176
- https://z49x2vmq.github.io/2020/12/24/linux-tiny-qemu/
151-
177+
- https://unix.stackexchange.com/a/489843 `/sbin/init not found in new root. Launching emergency recovery shell
178+
` / `init not found in new root`
152179
> "Stuff like this is slowly becoming a lost art" [src](https://www.linuxquestions.org/questions/linux-general-1/bin-bash-as-primary-init-4175543547/#post5367386) ooopse.
153180
154181

@@ -159,3 +186,4 @@ TODO READ: https://bbs.archlinux.org/viewtopic.php?pid=1378903#p1378903
159186

160187
> "busybox qemu /bin/sh: can't access tty; job control turned off"
161188
> https://github.com/brgl/busybox/blob/master/shell/cttyhack.c
189+

build-openssh-statically.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/bin/bash
22

3+
set -eux
4+
5+
echo $BUILD_ARTIFACTS_DIR
6+
37
# 1. clone openssh-portable
8+
rm -rf openssh-portable
49
git clone https://github.com/openssh/openssh-portable
510
cd openssh-portable
611
git checkout V_9_9_P1

create-scratch-space.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ for sshUtility in $(find "$BUILD_ARTIFACTS_FOLDER"/openssh -maxdepth 1 -type f -
3636
echo Copying over "$sshUtility"
3737
cp "$sshUtility" ./usr/bin
3838
done
39+
# No need to move sshd-session any more? already done?
3940
mv ./usr/bin/sshd-session ./usr/bin/libexec
4041

4142
# Bootstrap ssh users/config setup

0 commit comments

Comments
 (0)