aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile17
-rwxr-xr-xscripts/qemu-ifup43
-rw-r--r--skeleton/root/.placeholder0
3 files changed, 53 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index c087f39..f88f458 100644
--- a/Makefile
+++ b/Makefile
@@ -109,8 +109,8 @@ $(MUSL_TARGET):
cd '$(MUSL_BUILD_DIR)' && (test -r ./config.mak || ./configure --prefix='$(ROOTFS_DIR)/usr')
make -C '$(MUSL_BUILD_DIR)' -j$(BUILDJOBS) ARCH='$(ARCH)' V=1 all
make -C '$(MUSL_BUILD_DIR)' -j$(BUILDJOBS) ARCH='$(ARCH)' install
- ln -sr '$(ROOTFS_DIR)/usr/lib' '$(ROOTFS_DIR)/lib' || true
- ln -sr '$(ROOTFS_DIR)/lib/libc.so' '$(ROOTFS_DIR)/lib/ld-musl-$(ARCH).so.1' || true
+ test -e '$(ROOTFS_DIR)/lib' || ln -sr '$(ROOTFS_DIR)/usr/lib' '$(ROOTFS_DIR)/lib'
+ test -e '$(ROOTFS_DIR)/lib/ld-musl-$(ARCH).so.1' || ln -sr '$(ROOTFS_DIR)/lib/libc.so' '$(ROOTFS_DIR)/lib/ld-musl-$(ARCH).so.1'
$(BUSYBOX_TARGET):
cp -v '$(CFG_DIR)/busybox.config' '$(BUSYBOX_BUILD_DIR)/.config'
@@ -128,9 +128,9 @@ build: extract $(LINUX_TARGET) $(MUSL_TARGET) $(BUSYBOX_TARGET)
$(INITRD_TARGET):
cp -v '$(SCRIPT_DIR)/init.rootfs' '$(ROOTFS_DIR)/init'
- cp -rfvTp '$(SKEL_DIR)' '$(ROOTFS_DIR)'
- chmod 0755 '$(ROOTFS_DIR)/init'
- cd '$(ROOTFS_DIR)' && find . -print0 | cpio --null -ov --format=newc | gzip -9 > '$(INITRD_TARGET)'
+ chmod 0755 '$(ROOTFS_DIR)/init'
+ cp -rfvTp '$(SKEL_DIR)' '$(ROOTFS_DIR)'
+ cd '$(ROOTFS_DIR)' && find . -print0 | cpio --owner 0:0 --null -ov --format=newc | gzip -9 > '$(INITRD_TARGET)'
image: build $(INITRD_TARGET)
@@ -146,7 +146,8 @@ image-rebuild: force-remove
rm -rf '$(ROOTFS_DIR)'
$(DO_BUILD)
-image-reinstall: force-remove
+image-reinstall:
+ rm -f '$(INITRD_TARGET)'
$(DO_BUILD)
image-repack:
@@ -155,7 +156,8 @@ image-repack:
net:
sudo ip tuntap add linux-qemu-test mode tap
- sudo /etc/qemu-ifup linux-qemu-test
+ test -x /etc/qemu-ifup && sudo /etc/qemu-ifup linux-qemu-test
+ test -x /etc/qemu-ifup || sudo scripts/qemu-ifup linux-qemu-test
qemu: image
qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -vga qxl -display sdl
@@ -174,6 +176,7 @@ qemu-net: image
qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -vga qxl -display sdl \
-net nic,macaddr=$(NET_HWADDR) -net tap,ifname=linux-qemu-test,br=$(NET_BRIDGE),script=no,downscript=no -append 'net $(if $(NET_IP4),ip4)'
+# printf '%*s%-10s - %s\n' '20' 'COMMAND' '' 'HELP'
define HELP_PREFIX
@echo "\t make $1\t- $2"
endef
diff --git a/scripts/qemu-ifup b/scripts/qemu-ifup
new file mode 100755
index 0000000..20c10de
--- /dev/null
+++ b/scripts/qemu-ifup
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Script to bring a network (tap) device for qemu up.
+# The idea is to add the tap device to the same bridge
+# as we have default routing to.
+
+
+# in order to be able to find brctl
+PATH=$PATH:/sbin:/usr/sbin
+ip=$(which ip)
+
+if [ -n "$ip" ]; then
+ ip link set "$1" up
+else
+ brctl=$(which brctl)
+ if [ ! "$ip" -o ! "$brctl" ]; then
+ echo "W: $0: not doing any bridge processing: neither ip nor brctl utility not found" >&2
+ exit 0
+ fi
+ ifconfig "$1" 0.0.0.0 up
+fi
+
+switch=$(ip route ls | \
+ awk '/^default / {
+ for(i=0;i<NF;i++) { if ($i == "dev") { print $(i+1); next; } }
+ }'
+ )
+
+# only add the interface to default-route bridge if we
+# have such interface (with default route) and if that
+# interface is actually a bridge.
+# It is possible to have several default routes too
+for br in $switch; do
+ if [ -d /sys/class/net/$br/bridge/. ]; then
+ if [ -n "$ip" ]; then
+ ip link set "$1" master "$br"
+ else
+ brctl addif $br "$1"
+ fi
+ exit # exit with status of the previous command
+ fi
+done
+
+echo "W: $0: no bridge for guest interface found" >&2
diff --git a/skeleton/root/.placeholder b/skeleton/root/.placeholder
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/skeleton/root/.placeholder