Add tftp for qemu; Include qemu in Makefile
This commit is contained in:
parent
bc4d1af428
commit
a4789e6902
3 changed files with 104 additions and 39 deletions
98
Makefile
98
Makefile
|
|
@ -7,20 +7,36 @@ MKTORRENT_DOCKER_IMAGE ?= labsync-mktorrent
|
|||
|
||||
CWD=$(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
|
||||
|
||||
qemu_ifname_br = brlabsync
|
||||
qemu_ifname_tap = taplabsync
|
||||
qemu_hostname = qemumachine
|
||||
qemu_host_ip = 10.2.2.1
|
||||
qemu_netmask = 24
|
||||
qemu_vm_ip = 10.2.2.10
|
||||
qemu_disk = tmp/qemu-disk.img
|
||||
qemu_target ?= debian-stretch
|
||||
qemu_kernel = $(qemu_target).linux
|
||||
qemu_initramfs = $(qemu_target).initramfs.dev
|
||||
qemu_torrent = $(qemu_target).torrent
|
||||
|
||||
.PHONY: default
|
||||
default: clean dockerimg images/debian-stretch.squashfs images/debian-stretch.torrent
|
||||
default: dockerimg images/debian-stretch.squashfs images/debian-stretch.torrent
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f images/*
|
||||
rm -f tmp/*
|
||||
rm -rf tmp
|
||||
|
||||
.PHONY: dockerimg
|
||||
dockerimg:
|
||||
docker build -t "$(PACKER_DOCKER_IMAGE)" --build-arg "PACKER_VERSION=$(PACKER_VERSION)" packer/docker
|
||||
docker build -t "$(MKTORRENT_DOCKER_IMAGE)" mktorrent
|
||||
|
||||
images/debian-stretch.squashfs:
|
||||
images:
|
||||
[ ! -d "$@" ] && mkdir "$@"
|
||||
touch "$@"
|
||||
|
||||
images/debian-stretch.squashfs: images
|
||||
docker run \
|
||||
--rm \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
|
|
@ -31,7 +47,7 @@ images/debian-stretch.squashfs:
|
|||
"$(PACKER_DOCKER_IMAGE)" \
|
||||
debian-stretch
|
||||
|
||||
images/debian-stretch.torrent:
|
||||
images/debian-stretch.torrent: images
|
||||
docker run \
|
||||
--rm \
|
||||
-v "${PWD}/images:/workdir" \
|
||||
|
|
@ -41,3 +57,77 @@ images/debian-stretch.torrent:
|
|||
-e "WEBSEED=$(WEBSEED)" \
|
||||
"$(MKTORRENT_DOCKER_IMAGE)" \
|
||||
debian-stretch.squashfs
|
||||
|
||||
# updates the initramfs
|
||||
# only used for development
|
||||
images/debian-stretch.initramfs.dev: tmp/initramfs-extracted/debian-stretch packer/initramfs/labsync
|
||||
cp packer/initramfs/labsync tmp/initramfs-extracted/debian-stretch/scripts/labsync
|
||||
(cd tmp/initramfs-extracted/debian-stretch && find . | cpio -H newc -o | gzip > $(CWD)/images/debian-stretch.initramfs.dev)
|
||||
|
||||
tmp:
|
||||
[ ! -d "$@" ] && mkdir "$@" || true
|
||||
|
||||
tmp/initramfs-extracted/debian-stretch: images/debian-stretch.initramfs
|
||||
rm -rf tmp/initramfs-extracted/debian-stretch
|
||||
mkdir -p tmp/initramfs-extracted/debian-stretch
|
||||
(cd tmp/initramfs-extracted/debian-stretch && zcat "$(CWD)/images/debian-stretch.initramfs" | cpio -i)
|
||||
touch tmp/initramfs-extracted/debian-stretch
|
||||
|
||||
$(qemu_disk): tmp
|
||||
qemu-img create "$@" 4G
|
||||
|
||||
tmp/netboot.tar.gz: tmp
|
||||
wget -O "$@" https://cdn-aws.deb.debian.org/debian/dists/stretch/main/installer-amd64/current/images/netboot/netboot.tar.gz
|
||||
touch "$@"
|
||||
|
||||
tmp/tftproot: tmp/netboot.tar.gz
|
||||
[ ! -d tmp/tftproot ] && mkdir tmp/tftproot || true
|
||||
tar -xzf "$<" -C "$@"
|
||||
rm tmp/tftproot/debian-installer/amd64/boot-screens/txt.cfg
|
||||
|
||||
tmp/tftproot/images: tmp/tftproot
|
||||
ln -s ../../images tmp/tftproot/images
|
||||
|
||||
tmp/tftproot/debian-installer/amd64/boot-screens/txt.cfg: txt.cfg
|
||||
ln -s ../../../../../txt.cfg "$@"
|
||||
|
||||
|
||||
/sys/devices/virtual/net/$(qemu_ifname_tap):
|
||||
sudo ip tuntap add dev $(qemu_ifname_tap) mode tap user $(USER)
|
||||
|
||||
/sys/devices/virtual/net/$(qemu_ifname_br):
|
||||
sudo brctl addbr $(qemu_ifname_br)
|
||||
|
||||
/sys/devices/virtual/net/$(qemu_ifname_br)/brif/$(qemu_ifname_tap): /sys/devices/virtual/net/$(qemu_ifname_tap) /sys/devices/virtual/net/$(qemu_ifname_br)
|
||||
sudo brctl addif $(qemu_ifname_br) $(qemu_ifname_tap)
|
||||
|
||||
.PHONY: qemu-network
|
||||
qemu-network: /sys/devices/virtual/net/$(qemu_ifname_br)/brif/$(qemu_ifname_tap)
|
||||
if ! ip addr show dev $(qemu_ifname_br) | grep -F "$(qemu_host_ip)/$(qemu_netmask)"; then \
|
||||
sudo ip addr add $(qemu_host_ip)/$(qemu_netmask) dev $(qemu_ifname_br); \
|
||||
fi
|
||||
sudo ip link set $(qemu_ifname_tap) up
|
||||
sudo ip link set $(qemu_ifname_br) up
|
||||
|
||||
.PHONY: qemu
|
||||
qemu: qemu-network $(qemu_disk)
|
||||
qemu-system-x86_64 \
|
||||
-kernel "images/$(qemu_kernel)" \
|
||||
-initrd "images/$(qemu_initramfs)" \
|
||||
-drive format=raw,file="$(qemu_disk)" \
|
||||
-append "boot=labsync labsync_disk=/dev/sda labsync_partsize_boot=512 labsync_torrent=http://10.2.2.1/$(qemu_torrent) quiet vga=792 ip=$(qemu_vm_ip):::255.255.255.0:$(qemu_hostname):ens3:off labsync_wait=pause" \
|
||||
-enable-kvm \
|
||||
-m 1G \
|
||||
-net nic \
|
||||
-net tap,ifname=$(qemu_ifname_tap),script=no,downscript=no
|
||||
|
||||
.PHONY: qemu-tftp
|
||||
qemu-tftp: tmp/tftproot tmp/tftproot/images tmp/tftproot/debian-installer/amd64/boot-screens/txt.cfg qemu-network $(qemu_disk)
|
||||
qemu-system-x86_64 \
|
||||
-net nic -net tap,ifname=$(qemu_ifname_tap),script=no,downscript=no \
|
||||
-net nic -net user,tftp=.,bootfile=/tmp/tftproot/pxelinux.0 \
|
||||
-enable-kvm \
|
||||
-m 1G \
|
||||
-drive format=raw,file="$(qemu_disk)" \
|
||||
-boot n
|
||||
|
||||
|
|
|
|||
35
qemu.sh
35
qemu.sh
|
|
@ -1,35 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
ifname_tap=taplabsync
|
||||
ifname_br=brlabsync
|
||||
|
||||
TORRENT="$1.torrent"
|
||||
KERNEL="$1.linux"
|
||||
INITRAMFS="$1.initramfs"
|
||||
SQUASHFS="$1"
|
||||
|
||||
if [ "$1" = "" ]; then
|
||||
echo "you must supply an image name!" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p ./tmp
|
||||
[ -e tmp/qemu-disk.img ] || qemu-img create tmp/qemu-disk.img 4G
|
||||
|
||||
sudo ip tuntap add dev $ifname_tap mode tap user $USER
|
||||
sudo brctl addbr $ifname_br
|
||||
sudo brctl addif $ifname_br $ifname_tap
|
||||
sudo ip addr add 10.2.2.1/24 dev $ifname_br
|
||||
sudo ip link set taplabsync up
|
||||
sudo ip link set brlabsync up
|
||||
|
||||
qemu-system-x86_64 \
|
||||
-kernel "images/$KERNEL" \
|
||||
-initrd "images/$INITRAMFS" \
|
||||
-drive format=raw,file=tmp/qemu-disk.img \
|
||||
-drive format=raw,file=tmp/qemu-disk2.img \
|
||||
-append "boot=labsync disk=/dev/sda partsize=3072 torrent=http://10.2.2.1/$TORRENT torrent_file=$SQUASHFS quiet vga=792 ip=10.2.2.2:::255.255.255.0:qemumachine:ens3:off" \
|
||||
-enable-kvm \
|
||||
-m 1G \
|
||||
-net nic \
|
||||
-net tap,ifname=$ifname_tap,script=no,downscript=no
|
||||
10
txt.cfg
Normal file
10
txt.cfg
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
label labsync
|
||||
menu label ^labsync
|
||||
kernel images/debian-stretch.linux
|
||||
append initrd=images/debian-stretch.initramfs.dev boot=labsync labsync_disk=/dev/sda labsync_partsize_boot=512 labsync_torrent=http://10.2.2.1/debian-stretch.torrent quiet vga=792 ip=10.2.2.10:::255.255.255.0:qemu-host:ens3:off labsync_wait=pause
|
||||
|
||||
label install
|
||||
menu label ^Install
|
||||
kernel debian-installer/amd64/linux
|
||||
append vga=788 initrd=debian-installer/amd64/initrd.gz --- quiet
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue