Last active
May 24, 2024 16:59
-
-
Save martezr/9d4969106c06b6a527fa711d2cb229bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "http://mirrors.edge.kernel.org/alpine/v3.19/community" >> /etc/apk/repositories | |
apk update | |
# Install Open VM Tools | |
apk add open-vm-tools open-vm-tools-guestinfo open-vm-tools-deploypkg | |
rc-update add open-vm-tools boot | |
rc-service open-vm-tools start | |
# Install Open vSwitch | |
apk add openvswitch | |
service ovs-vswitchd start | |
rc-update add ovs-vswitchd | |
# Install virtualization packages | |
apk add libvirt-daemon qemu-img qemu-system-x86_64 qemu-modules openrc virt-install libvirt dbus polkit | |
rc-update add libvirtd | |
rc-update add libvirt-guests | |
rc-update add polkit | |
service libvirtd start | |
service polkit start | |
# Install storage | |
apk add zfs zfs-lts | |
modprobe zfs | |
sysctl net.ipv4.ip_forward | |
ovs-vsctl add-br external-net | |
ip link set dev eth1 up | |
apk add iproute2 | |
modprobe tun | |
echo tun >> /etc/modules | |
# DHCP Server | |
#### | |
ovs-vsctl add-port external-net dhcp0 -- set Interface dhcp0 type=internal external_ids:iface-id=dhcp0,attached-mac=32:6b:ce:89:41:42 | |
ip netns add dhcpport | |
ip link set dhcp0 netns dhcpport | |
ip netns exec dhcpport ip link set dhcp0 address 32:6b:ce:89:41:42 | |
ip netns exec dhcpport ip addr add 169.254.169.253/0 dev dhcp0 | |
ip netns exec dhcpport ip link set dhcp0 up | |
ip netns exec dhcpport ip route add default dev dhcp0 | |
# Configure DHCP Server | |
ip link add v-eth1 type veth peer name v-peer1 | |
## Add peer to dhcp | |
ip link set v-peer1 netns dhcpport | |
## Configure host virtual ethernet port | |
ip addr add 10.200.1.1/24 dev v-eth1 | |
ip link set v-eth1 up | |
## Configure DHCP server access to KVM Cloud backend | |
ip netns exec dhcpport ip addr add 10.200.1.2/24 dev v-peer1 | |
ip netns exec dhcpport ip link set v-peer1 up | |
ip netns exec dhcpport ip link set lo up | |
## Setup DHCP service | |
cat <<'EOF' > /etc/init.d/kcloud-dhcp | |
#!/sbin/openrc-run | |
#/etc/init.d/kcloud-dhcp | |
name="$SVCNAME" | |
command="/sbin/ip" | |
command_args="netns exec dhcpport /root/dhcp" | |
command_user="root" | |
pidfile="/run/$SVCNAME/$SVCNAME.pid" | |
command_background="yes" | |
EOF | |
mkdir /run/kcloud-dhcp | |
chmod +x /etc/init.d/kcloud-dhcp | |
service kcloud-dhcp start | |
# Metadata Server | |
ovs-vsctl add-port external-net meta0 -- set Interface meta0 type=internal external_ids:iface-id=meta0,attached-mac=32:6b:ce:89:41:43 | |
ip netns add metaport | |
ip link set meta0 netns metaport | |
ip netns exec metaport ip link set meta0 address 32:6b:ce:89:41:43 | |
ip netns exec metaport ip addr add 169.254.169.254/0 dev meta0 | |
ip netns exec metaport ip link set meta0 up | |
ip netns exec metaport ip route add default dev meta0 | |
## Setup Network | |
cat <<EOF > /root/external-network.xml | |
<network> | |
<name>external</name> | |
<uuid>f58cad29-0455-439a-b533-8362669cec92</uuid> | |
<forward mode='bridge'/> | |
<bridge name='external-net'/> | |
<virtualport type='openvswitch'/> | |
</network> | |
EOF | |
virsh net-define /root/external-network.xml | |
virsh net-start external | |
virsh net-autostart external | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
wget https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img | |
cp cirros-0.6.2-x86_64-disk.img /root/cirros1.img | |
virt-install --connect=qemu:///system --name=cirros1 --ram=512 --vcpus=1 --disk path=/root/cirros1.img,format=qcow2 --import --network network:ovs --osinfo=linux2022 --graphics vnc,listen=0.0.0.0 --noautoconsole |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment