mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 13:30:02 +08:00
Minor fixes
Network/serial reworked
This commit is contained in:
commit
9adbaf1981
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -22,5 +22,5 @@ jobs:
|
||||
- name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
env:
|
||||
SHELLCHECK_OPTS: -e SC2001 -e SC2002 -e SC2116 -e SC2034 -e SC1091 -e SC2143 -e SC2223 -e SC2086 -e SC2145 -e SC2015 -e SC2268 -e SC2207 -e SC2064
|
||||
SHELLCHECK_OPTS: -e SC2001 -e SC2002 -e SC2116 -e SC2034 -e SC1091 -e SC2143 -e SC2223 -e SC2086 -e SC2145 -e SC2015 -e SC2268 -e SC2207 -e SC2064 -e SC2166
|
||||
|
||||
|
@ -57,12 +57,9 @@ EXPOSE 445
|
||||
EXPOSE 5000
|
||||
EXPOSE 5001
|
||||
|
||||
ENV URL ""
|
||||
ENV CPU_CORES 1
|
||||
ENV DISK_SIZE 16G
|
||||
ENV RAM_SIZE 512M
|
||||
|
||||
#ENV URL https://global.synologydownload.com/download/DSM/beta/7.2/64216/DSM_VirtualDSM_64216.pat
|
||||
#ENV URL https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat
|
||||
ENV URL https://global.synologydownload.com/download/DSM/release/7.1.1/42962-1/DSM_VirtualDSM_42962.pat
|
||||
|
||||
ENTRYPOINT ["/run/run.sh"]
|
||||
|
30
disk.sh
30
disk.sh
@ -16,28 +16,32 @@ NEW_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
|
||||
FILE="$IMG/data$DISK_SIZE.img"
|
||||
|
||||
if [ ! -f "$FILE" ]; then
|
||||
# Create an empty file
|
||||
truncate -s "${NEW_SIZE}" "${FILE}"
|
||||
# Format as BTRFS filesystem
|
||||
mkfs.btrfs -q -L data -d single -m dup "${FILE}" > /dev/null
|
||||
#qemu-img convert -f raw -O qcow2 -o extended_l2=on,cluster_size=128k,compression_type=zstd,preallocation=metadata "$TMP" "$FILE"
|
||||
fi
|
||||
|
||||
[ ! -f "$FILE" ] && echo "ERROR: Virtual DSM data-image does not exist ($FILE)" && exit 83
|
||||
|
||||
#OLD_SIZE=$(stat -c%s "${FILE}")
|
||||
# Resizing requires mounting a loop device which in turn requires
|
||||
# the container to be privileged, so we must disable it for now.
|
||||
#
|
||||
#if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then
|
||||
# echo "Resizing data disk from $OLD_SIZE to $NEW_SIZE bytes"
|
||||
# OLD_SIZE=$(stat -c%s "${FILE}")
|
||||
#
|
||||
# if [ "$NEW_SIZE" -gt "$OLD_SIZE" ]; then
|
||||
# truncate -s "${NEW_SIZE}" "${FILE}"
|
||||
# btrfs filesystem resize "${NEW_SIZE}" "${FILE}"
|
||||
# fi
|
||||
# if [ "$NEW_SIZE" -ne "$OLD_SIZE" ]; then
|
||||
# echo "Resizing data disk from $OLD_SIZE to $NEW_SIZE bytes"
|
||||
#
|
||||
# if [ "$NEW_SIZE" -lt "$OLD_SIZE" ]; then
|
||||
# btrfs filesystem resize "${NEW_SIZE}" "${FILE}"
|
||||
# truncate -s "${NEW_SIZE}" "${FILE}"
|
||||
# fi
|
||||
#fi
|
||||
# if [ "$NEW_SIZE" -gt "$OLD_SIZE" ]; then
|
||||
# truncate -s "${NEW_SIZE}" "${FILE}"
|
||||
# btrfs filesystem resize "${NEW_SIZE}" "${FILE}"
|
||||
# fi
|
||||
#
|
||||
# if [ "$NEW_SIZE" -lt "$OLD_SIZE" ]; then
|
||||
# btrfs filesystem resize "${NEW_SIZE}" "${FILE}"
|
||||
# truncate -s "${NEW_SIZE}" "${FILE}"
|
||||
# fi
|
||||
# fi
|
||||
|
||||
KVM_DISK_OPTS="\
|
||||
-device virtio-scsi-pci,id=hw-synoboot,bus=pcie.0,addr=0xa \
|
||||
|
10
install.sh
10
install.sh
@ -1,6 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
|
||||
if [ -z $URL ]; then
|
||||
#URL="https://global.synologydownload.com/download/DSM/beta/7.2/64216/DSM_VirtualDSM_64216.pat"
|
||||
#URL="https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
||||
URL="https://global.synologydownload.com/download/DSM/release/7.1.1/42962-1/DSM_VirtualDSM_42962.pat"
|
||||
fi
|
||||
|
||||
IMG="/storage"
|
||||
BASE=$(basename "$URL" .pat)
|
||||
|
||||
@ -8,7 +14,7 @@ BASE=$(basename "$URL" .pat)
|
||||
[ ! -f "/run/server.sh" ] && echo "Script must run inside Docker container!" && exit 60
|
||||
|
||||
[ ! -f "$IMG/$BASE.boot.img" ] && rm -f "$IMG"/"$BASE".system.img
|
||||
[ -f "$IMG/$BASE.system.img" ] && exit 0
|
||||
[ -f "$IMG/$BASE.system.img" ] && return
|
||||
|
||||
# Display wait message on port 5000
|
||||
/run/server.sh 5000 > /dev/null &
|
||||
@ -150,5 +156,3 @@ mv -f "$BOOT" "$IMG"/"$BASE".boot.img
|
||||
mv -f "$SYSTEM" "$IMG"/"$BASE".system.img
|
||||
|
||||
rm -rf $TMP
|
||||
|
||||
exit 0
|
||||
|
57
network.sh
57
network.sh
@ -2,8 +2,8 @@
|
||||
set -eu
|
||||
|
||||
: ${VM_NET_TAP:=''}
|
||||
: ${VM_NET_MAC:=''}
|
||||
: ${VM_NET_IP:='20.20.20.21'}
|
||||
: ${VM_NET_MAC:='02:11:32:AA:BB:CC'}
|
||||
|
||||
: ${DNS_SERVERS:=''}
|
||||
: ${DNSMASQ:='/usr/sbin/dnsmasq'}
|
||||
@ -14,18 +14,6 @@ set -eu
|
||||
# Functions
|
||||
# ######################################
|
||||
|
||||
setupLocalDhcp () {
|
||||
IP="$2"
|
||||
MAC="$1"
|
||||
CIDR="24"
|
||||
HOSTNAME="VirtualDSM"
|
||||
# dnsmasq configuration:
|
||||
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$IP,$IP --dhcp-host=$MAC,,$IP,$HOSTNAME,infinite --dhcp-option=option:netmask,255.255.255.0"
|
||||
# Create lease file for faster resolve
|
||||
echo "0 $MAC $IP $HOSTNAME 01:${MAC}" > /var/lib/misc/dnsmasq.leases
|
||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||
}
|
||||
|
||||
# Setup macvtap device to connect later the VM and setup a new macvlan device to connect the host machine to the network
|
||||
configureNatNetworks () {
|
||||
|
||||
@ -46,7 +34,15 @@ configureNatNetworks () {
|
||||
#Enable port forwarding flag
|
||||
[[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]] && sysctl -w net.ipv4.ip_forward=1
|
||||
|
||||
setupLocalDhcp $VM_NET_MAC $VM_NET_IP
|
||||
CIDR="24"
|
||||
HOSTNAME="VirtualDSM"
|
||||
|
||||
# dnsmasq configuration:
|
||||
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$VM_NET_IP,$VM_NET_IP --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$HOSTNAME,infinite --dhcp-option=option:netmask,255.255.255.0"
|
||||
|
||||
# Create lease file for faster resolve
|
||||
echo "0 $VM_NET_MAC $VM_NET_IP $HOSTNAME 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
|
||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||
}
|
||||
|
||||
# ######################################
|
||||
@ -61,14 +57,6 @@ if [ ! -c /dev/net/tun ]; then
|
||||
fi
|
||||
|
||||
[ ! -c /dev/net/tun ] && echo "Error: TUN network interface not available..." && exit 85
|
||||
[ ! -d "$IMG" ] && echo "Storage folder (${IMG}) not found!" && exit 86
|
||||
|
||||
#If environment variabele not set fall back to file
|
||||
if [ -z "$VM_NET_MAC" ]; then
|
||||
FILE="${IMG}/guest.mac"
|
||||
[ ! -f "$FILE" ] && echo "00:11:32:2C:A7:85" > "$FILE"
|
||||
VM_NET_MAC=$(cat "${FILE}")
|
||||
fi
|
||||
|
||||
update-alternatives --set iptables /usr/sbin/iptables-legacy > /dev/null
|
||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||
@ -88,17 +76,28 @@ for nameserver in "${nameservers[@]}"; do
|
||||
fi
|
||||
done
|
||||
|
||||
DNSMASQ_OPTS="$DNSMASQ_OPTS \
|
||||
--dhcp-option=option:dns-server,$DNS_SERVERS \
|
||||
--dhcp-option=option:router,${VM_NET_IP%.*}.1 \
|
||||
--dhcp-option=option:domain-search,$searchdomains \
|
||||
--dhcp-option=option:domain-name,$domainname"
|
||||
if [ -z $DNS_SERVERS ]; then
|
||||
DNS_SERVERS="1.1.1.1"
|
||||
else
|
||||
COMMAS=${DNS_SERVERS//[^,]/}
|
||||
COMMAS=${#COMMAS}
|
||||
((COMMAS < 1)) && DNS_SERVERS="$DNS_SERVERS,1.1.1.1"
|
||||
fi
|
||||
|
||||
[[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)"
|
||||
DNSMASQ_OPTS="$DNSMASQ_OPTS \
|
||||
--dhcp-option=option:dns-server,$DNS_SERVERS \
|
||||
--dhcp-option=option:router,${VM_NET_IP%.*}.1"
|
||||
|
||||
if [ -n "$searchdomains" -a "$searchdomains" != "." ]; then
|
||||
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-search,$searchdomains"
|
||||
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$domainname"
|
||||
else
|
||||
[[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)"
|
||||
fi
|
||||
|
||||
$DNSMASQ $DNSMASQ_OPTS
|
||||
|
||||
KVM_NET_OPTS="${KVM_NET_OPTS} -device virtio-net-pci,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
|
||||
KVM_NET_OPTS="${KVM_NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
|
||||
|
||||
# Hack for guest VMs complaining about "bad udp checksums in 5 packets"
|
||||
iptables -A POSTROUTING -t mangle -p udp --dport bootpc -j CHECKSUM --checksum-fill
|
||||
|
19
run.sh
19
run.sh
@ -1,25 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
|
||||
if /run/install.sh; then
|
||||
echo "Starting Virtual DSM..."
|
||||
else
|
||||
echo "Installation failed (code $?)" && exit 81
|
||||
fi
|
||||
echo "Starting Virtual DSM..."
|
||||
|
||||
source /run/disk.sh
|
||||
. /run/install.sh
|
||||
. /run/disk.sh
|
||||
|
||||
[ -z "${KVM_DISK_OPTS}" ] && echo "Error: Failed to setup disks..." && exit 83
|
||||
|
||||
source /run/network.sh
|
||||
. /run/network.sh
|
||||
|
||||
[ -z "${KVM_NET_OPTS}" ] && echo "Error: Failed to setup network..." && exit 84
|
||||
|
||||
source /run/serial.sh
|
||||
. /run/serial.sh
|
||||
|
||||
[ -z "${KVM_SERIAL_OPTS}" ] && echo "Error: Failed to setup serial..." && exit 85
|
||||
|
||||
source /run/power.sh
|
||||
. /run/power.sh
|
||||
|
||||
[ -z "${KVM_MON_OPTS}" ] && echo "Error: Failed to setup monitor..." && exit 87
|
||||
|
||||
@ -39,7 +36,9 @@ ARGS="-m ${RAM_SIZE} -smp ${CPU_CORES} ${KVM_ACC_OPTS} ${EXTRA_OPTS} ${KVM_MON_O
|
||||
|
||||
set -m
|
||||
(
|
||||
for _SIGNAL in {1..64}; do trap "echo Caught trap ${_SIGNAL} for the QEMU process" "${_SIGNAL}"; done
|
||||
for _SIGNAL in {1..64}; do
|
||||
trap "echo Caught trap ${_SIGNAL} for the QEMU process" "${_SIGNAL}";
|
||||
done
|
||||
qemu-system-x86_64 ${ARGS} & echo $! > ${_QEMU_PID}
|
||||
)
|
||||
set +m
|
||||
|
59
serial.sh
59
serial.sh
@ -1,33 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
# Docker environment variabeles
|
||||
: ${HOST_SERIAL:=''}
|
||||
: ${GUEST_SERIAL:=''}
|
||||
|
||||
permanent="DSM"
|
||||
serialstart="2000"
|
||||
|
||||
[ ! -d "$IMG" ] && echo "Storage folder (${IMG}) not found!" && exit 69
|
||||
|
||||
#If environment variabele not set fall back to file
|
||||
if [ -z "$HOST_SERIAL" ]; then
|
||||
FILE="${IMG}/host.serial"
|
||||
if [ ! -f "$FILE" ]; then
|
||||
SERIAL="$(echo "$serialstart" | tr ' ' '\n' | sort -R | tail -1)$permanent"$(printf "%06d" $((RANDOM % 30000 + 1)))
|
||||
echo $SERIAL > "$FILE"
|
||||
fi
|
||||
HOST_SERIAL=$(cat "${FILE}")
|
||||
fi
|
||||
|
||||
#If environment variabele not set fall back to file
|
||||
if [ -z "$GUEST_SERIAL" ]; then
|
||||
FILE="${IMG}/guest.serial"
|
||||
if [ ! -f "$FILE" ]; then
|
||||
SERIAL="$(echo "$serialstart" | tr ' ' '\n' | sort -R | tail -1)$permanent"$(printf "%06d" $((RANDOM % 30000 + 1)))
|
||||
echo $SERIAL > "$FILE"
|
||||
fi
|
||||
GUEST_SERIAL=$(cat "${FILE}")
|
||||
fi
|
||||
: ${HOST_BUILD:='42962'}
|
||||
: ${HOST_VERSION:='2.6.1-12139'}
|
||||
: ${HOST_TIMESTAMP:='1679863686'}
|
||||
: ${HOST_SERIAL:='0000000000000'}
|
||||
: ${GUEST_SERIAL:='0000000000000'}
|
||||
: ${GUEST_UUID:='ba13a19a-c0c1-4fef-9346-915ed3b98341'}
|
||||
|
||||
CPU=$(lscpu | sed -nr '/Model name/ s/.*:\s*(.*) @ .*/\1/p' | sed ':a;s/ / /;ta' | sed s/"(R)"//g | sed s/"-"//g | sed 's/[^[:alnum:] ]\+//g')
|
||||
|
||||
@ -38,18 +19,18 @@ else
|
||||
fi
|
||||
|
||||
./run/serial.bin -cpu="${CPU_CORES}" \
|
||||
-cpu_arch="${CPU}" \
|
||||
-buildnumber=42962 \
|
||||
-vmmts=1679863686 \
|
||||
-hostsn="${HOST_SERIAL}" \
|
||||
-guestsn="${GUEST_SERIAL}" \
|
||||
-vmmversion="2.6.1-12139" \
|
||||
-guestuuid="ba13a19a-c0c1-4fef-9346-915ed3b98341" > /dev/null 2>&1 &
|
||||
-cpu_arch="${CPU}" \
|
||||
-hostsn="${HOST_SERIAL}" \
|
||||
-guestsn="${GUEST_SERIAL}" \
|
||||
-vmmts="${HOST_TIMESTAMP}" \
|
||||
-vmmversion="${HOST_VERSION}" \
|
||||
-buildnumber="${HOST_BUILD}" \
|
||||
-guestuuid="${GUEST_UUID}" > /dev/null 2>&1 &
|
||||
|
||||
KVM_SERIAL_OPTS="\
|
||||
-serial mon:stdio \
|
||||
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \
|
||||
-chardev pty,id=charserial0 \
|
||||
-device isa-serial,chardev=charserial0,id=serial0 \
|
||||
-chardev socket,id=charchannel0,host=127.0.0.1,port=12345,reconnect=10 \
|
||||
-device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel"
|
||||
-serial mon:stdio \
|
||||
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \
|
||||
-chardev pty,id=charserial0 \
|
||||
-device isa-serial,chardev=charserial0,id=serial0 \
|
||||
-chardev socket,id=charchannel0,host=127.0.0.1,port=12345,reconnect=10 \
|
||||
-device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel"
|
||||
|
@ -55,7 +55,7 @@ func main() {
|
||||
listener, err := net.Listen("tcp", *ListenAddr)
|
||||
|
||||
if err != nil {
|
||||
log.Println("Error listening", err.Error())
|
||||
log.Fatalln("Error listening", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ func main() {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Println("Error on accept", err.Error())
|
||||
log.Fatalln("Error on accept", err.Error())
|
||||
return
|
||||
}
|
||||
log.Printf("New connection from %s\n", conn.RemoteAddr().String())
|
||||
|
Loading…
x
Reference in New Issue
Block a user