mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-07 02:23:42 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
354bd2429b | ||
|
|
c1d3d15d4e | ||
|
|
95b2b83ac6 | ||
|
|
c3c4d966b4 |
@@ -14,7 +14,8 @@ ARG DEBIAN_FRONTEND noninteractive
|
|||||||
|
|
||||||
RUN apt-get update && apt-get -y upgrade && \
|
RUN apt-get update && apt-get -y upgrade && \
|
||||||
apt-get --no-install-recommends -y install \
|
apt-get --no-install-recommends -y install \
|
||||||
tini \
|
jq \
|
||||||
|
tini \
|
||||||
curl \
|
curl \
|
||||||
cpio \
|
cpio \
|
||||||
wget \
|
wget \
|
||||||
|
|||||||
23
src/disk.sh
23
src/disk.sh
@@ -24,6 +24,7 @@ DISK_OPTS="\
|
|||||||
|
|
||||||
addDisk () {
|
addDisk () {
|
||||||
|
|
||||||
|
local FS
|
||||||
local GB
|
local GB
|
||||||
local DIR
|
local DIR
|
||||||
local REQ
|
local REQ
|
||||||
@@ -39,6 +40,12 @@ addDisk () {
|
|||||||
|
|
||||||
DIR=$(dirname "${DISK_FILE}")
|
DIR=$(dirname "${DISK_FILE}")
|
||||||
[ ! -d "${DIR}" ] && return 0
|
[ ! -d "${DIR}" ] && return 0
|
||||||
|
|
||||||
|
FS=$(stat -f -c %T "$DIR")
|
||||||
|
|
||||||
|
if [[ "$FS" == "overlay"* ]]; then
|
||||||
|
info "Warning: the filesystem of ${DIR} is OverlayFS, this usually means it was binded to an invalid path!"
|
||||||
|
fi
|
||||||
|
|
||||||
[ -z "$DISK_SPACE" ] && DISK_SPACE="16G"
|
[ -z "$DISK_SPACE" ] && DISK_SPACE="16G"
|
||||||
DISK_SPACE=$(echo "${DISK_SPACE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
DISK_SPACE=$(echo "${DISK_SPACE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||||
@@ -70,16 +77,17 @@ addDisk () {
|
|||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
||||||
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
|
||||||
if (( REQ > SPACE )); then
|
if (( REQ > SPACE )); then
|
||||||
error "Not enough free space to resize ${DISK_DESC} to ${DISK_SPACE} .."
|
error "Not enough free space to resize ${DISK_DESC} to ${DISK_SPACE} in ${DIR}, it has only ${SPACE_GB} GB available.."
|
||||||
error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 84
|
error "Specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation with ALLOCATE=N." && exit 84
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Resize file by allocating more space
|
# Resize file by allocating more space
|
||||||
if ! fallocate -l "${DISK_SPACE}" "${DISK_FILE}"; then
|
if ! fallocate -l "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||||
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||||
error "Could not resize ${DISK_DESC} file (${DISK_FILE}) to ${DISK_SPACE} .." && exit 85
|
error "Could not resize ${DISK_DESC} file (${DISK_FILE}) to ${DISK_SPACE}" && exit 85
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -94,24 +102,25 @@ addDisk () {
|
|||||||
# Create an empty file
|
# Create an empty file
|
||||||
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||||
rm -f "${DISK_FILE}"
|
rm -f "${DISK_FILE}"
|
||||||
error "Could not create a file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
error "Could not create a ${DISK_SPACE} file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
||||||
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
|
||||||
if (( DATA_SIZE > SPACE )); then
|
if (( DATA_SIZE > SPACE )); then
|
||||||
error "Not enough free space to create ${DISK_DESC} of ${DISK_SPACE} .."
|
error "Not enough free space to create ${DISK_DESC} of ${DISK_SPACE} in ${DIR}, it has only ${SPACE_GB} GB available.."
|
||||||
error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 86
|
error "Specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation with ALLOCATE=N." && exit 86
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create an empty file
|
# Create an empty file
|
||||||
if ! fallocate -l "${DISK_SPACE}" "${DISK_FILE}"; then
|
if ! fallocate -l "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||||
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||||
rm -f "${DISK_FILE}"
|
rm -f "${DISK_FILE}"
|
||||||
error "Could not create a file for ${DISK_DESC} (${DISK_FILE}) of ${DISK_SPACE} .." && exit 87
|
error "Could not create a ${DISK_SPACE} file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -21,17 +21,37 @@ fi
|
|||||||
# Display wait message
|
# Display wait message
|
||||||
/run/server.sh 5000 install &
|
/run/server.sh 5000 install &
|
||||||
|
|
||||||
# Download the required files from the Synology website
|
# Detect country
|
||||||
DL="https://global.synologydownload.com/download/DSM"
|
COUNTRY=""
|
||||||
|
{ JSON=$(curl -sfk https://ipinfo.io); rc=$?; } || :
|
||||||
|
|
||||||
|
if (( rc == 0 )); then
|
||||||
|
{ COUNTRY=$(echo "$JSON" | jq -r '.country' 2> /dev/null); rc=$?; } || :
|
||||||
|
(( rc != 0 )) || [[ "$COUNTRY" == "null" ]] && COUNTRY=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$COUNTRY" ]]; then
|
||||||
|
{ JSON=$(curl -sfk https://api.ipapi.is); rc=$?; } || :
|
||||||
|
if (( rc == 0 )); then
|
||||||
|
{ COUNTRY=$(echo "$JSON" | jq -r '.location.country_code' 2> /dev/null); rc=$?; } || :
|
||||||
|
(( rc != 0 )) || [[ "$COUNTRY" == "null" ]] && COUNTRY=""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Select download mirror based on country
|
||||||
|
if [ "$COUNTRY" == "CN" ]; then
|
||||||
|
DL="https://cndl.synology.cn/download/DSM"
|
||||||
|
else
|
||||||
|
DL="https://global.synologydownload.com/download/DSM"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Select default version based on architecture
|
||||||
if [ -z "$URL" ]; then
|
if [ -z "$URL" ]; then
|
||||||
|
|
||||||
if [ "$ARCH" == "amd64" ]; then
|
if [ "$ARCH" == "amd64" ]; then
|
||||||
URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat"
|
URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat"
|
||||||
else
|
else
|
||||||
URL="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
URL="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if output is to interactive TTY
|
# Check if output is to interactive TTY
|
||||||
@@ -48,27 +68,42 @@ rm -f "$STORAGE"/"$BASE".agent
|
|||||||
rm -f "$STORAGE"/"$BASE".boot.img
|
rm -f "$STORAGE"/"$BASE".boot.img
|
||||||
rm -f "$STORAGE"/"$BASE".system.img
|
rm -f "$STORAGE"/"$BASE".system.img
|
||||||
|
|
||||||
|
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||||
|
|
||||||
|
# Check filesystem
|
||||||
MIN_SPACE=6442450944
|
MIN_SPACE=6442450944
|
||||||
FS=$(stat -f -c %T "$STORAGE")
|
FS=$(stat -f -c %T "$STORAGE")
|
||||||
|
|
||||||
|
if [[ "$FS" == "overlay"* ]]; then
|
||||||
|
info "Warning: the filesystem of ${STORAGE} is OverlayFS, this usually means it was binded to an invalid path!"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$FS" != "fat"* && "$FS" != "vfat"* && "$FS" != "exfat"* && \
|
if [[ "$FS" != "fat"* && "$FS" != "vfat"* && "$FS" != "exfat"* && \
|
||||||
"$FS" != "ntfs"* && "$FS" != "fuse"* && "$FS" != "msdos"* ]]; then
|
"$FS" != "ntfs"* && "$FS" != "fuse"* && "$FS" != "msdos"* ]]; then
|
||||||
TMP="$STORAGE/tmp"
|
TMP="$STORAGE/tmp"
|
||||||
else
|
else
|
||||||
TMP="/tmp/dsm"
|
TMP="/tmp/dsm"
|
||||||
SPACE=$(df --output=avail -B 1 /tmp | tail -n 1)
|
SPACE=$(df --output=avail -B 1 /tmp | tail -n 1)
|
||||||
(( MIN_SPACE > SPACE )) && TMP="$STORAGE/tmp"
|
if (( MIN_SPACE > SPACE )); then
|
||||||
|
TMP="$STORAGE/tmp"
|
||||||
|
info "Warning: the ${FS} filesystem of ${STORAGE} does not support UNIX permissions.."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf /tmp/dsm
|
|
||||||
rm -rf "$STORAGE/tmp"
|
|
||||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
||||||
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation, need at least 6 GB." && exit 95
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation in ${STORAGE}, have ${SPACE_GB} GB available but need at least 6 GB." && exit 95
|
||||||
|
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
if [[ "$TMP" != "$STORAGE/tmp" ]]; then
|
||||||
|
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||||
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation in ${STORAGE}, have ${SPACE_GB} GB available but need at least 6 GB." && exit 94
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Download the required files from the Synology website
|
||||||
|
|
||||||
RDC="$STORAGE/dsm.rd"
|
RDC="$STORAGE/dsm.rd"
|
||||||
|
|
||||||
@@ -213,7 +248,8 @@ SYSTEM_SIZE=4954537983
|
|||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
||||||
(( SYSTEM_SIZE > SPACE )) && error "Not enough free space to create a 4 GB system disk." && exit 87
|
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||||
|
(( SYSTEM_SIZE > SPACE )) && error "Not enough free space to create a 4 GB system disk, have only ${SPACE_GB} GB available." && exit 87
|
||||||
|
|
||||||
if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
||||||
if ! truncate -s "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
if ! truncate -s "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
||||||
@@ -274,12 +310,6 @@ rm -rf "$MOUNT"
|
|||||||
|
|
||||||
echo "$BASE" > "$STORAGE"/dsm.ver
|
echo "$BASE" > "$STORAGE"/dsm.ver
|
||||||
|
|
||||||
if [[ "$TMP" != "$STORAGE/tmp" ]]; then
|
|
||||||
# Check free diskspace
|
|
||||||
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
|
||||||
(( MIN_SPACE > SPACE )) && error "Not enough free space in storage folder, need at least 6 GB." && exit 94
|
|
||||||
fi
|
|
||||||
|
|
||||||
mv -f "$PAT" "$STORAGE"/"$BASE".pat
|
mv -f "$PAT" "$STORAGE"/"$BASE".pat
|
||||||
mv -f "$BOOT" "$STORAGE"/"$BASE".boot.img
|
mv -f "$BOOT" "$STORAGE"/"$BASE".boot.img
|
||||||
mv -f "$SYSTEM" "$STORAGE"/"$BASE".system.img
|
mv -f "$SYSTEM" "$STORAGE"/"$BASE".system.img
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ set -Eeuo pipefail
|
|||||||
: ${VM_NET_MAC:="$MAC"}
|
: ${VM_NET_MAC:="$MAC"}
|
||||||
: ${VM_NET_HOST:='VirtualDSM'}
|
: ${VM_NET_HOST:='VirtualDSM'}
|
||||||
|
|
||||||
: ${DNS_SERVERS:=''}
|
|
||||||
: ${DNSMASQ_OPTS:=''}
|
: ${DNSMASQ_OPTS:=''}
|
||||||
: ${DNSMASQ:='/usr/sbin/dnsmasq'}
|
: ${DNSMASQ:='/usr/sbin/dnsmasq'}
|
||||||
: ${DNSMASQ_CONF_DIR:='/etc/dnsmasq.d'}
|
: ${DNSMASQ_CONF_DIR:='/etc/dnsmasq.d'}
|
||||||
@@ -78,33 +77,8 @@ configureDNS () {
|
|||||||
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
|
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
|
||||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||||
|
|
||||||
# Build DNS options from container /etc/resolv.conf
|
# Set DNS server and gateway
|
||||||
|
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,${VM_NET_IP%.*}.1 --dhcp-option=option:router,${VM_NET_IP%.*}.1"
|
||||||
if [[ "${DEBUG}" == [Yy1]* ]]; then
|
|
||||||
echo "/etc/resolv.conf:" && echo && cat /etc/resolv.conf && echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
mapfile -t nameservers < <( { grep '^nameserver' /etc/resolv.conf || true; } | sed 's/\t/ /g' | sed 's/nameserver //' | sed 's/ //g')
|
|
||||||
searchdomains=$( { grep '^search' /etc/resolv.conf || true; } | sed 's/\t/ /g' | sed 's/search //' | sed 's/#.*//' | sed 's/\s*$//g' | sed 's/ /,/g')
|
|
||||||
domainname=$(echo "$searchdomains" | awk -F"," '{print $1}')
|
|
||||||
|
|
||||||
for nameserver in "${nameservers[@]}"; do
|
|
||||||
nameserver=$(echo "$nameserver" | sed 's/#.*//' )
|
|
||||||
if ! [[ "$nameserver" =~ .*:.* ]]; then
|
|
||||||
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="$nameserver" || DNS_SERVERS="$DNS_SERVERS,$nameserver"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="1.1.1.1"
|
|
||||||
|
|
||||||
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,$DNS_SERVERS --dhcp-option=option:router,${VM_NET_IP%.*}.1"
|
|
||||||
|
|
||||||
if [ -n "$searchdomains" ] && [ "$searchdomains" != "." ]; then
|
|
||||||
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-search,$searchdomains --dhcp-option=option:domain-name,$domainname"
|
|
||||||
else
|
|
||||||
[[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||||
|
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||||
@@ -147,8 +121,6 @@ configureNAT () {
|
|||||||
ip link set dev "${VM_NET_TAP}" master dockerbridge
|
ip link set dev "${VM_NET_TAP}" master dockerbridge
|
||||||
|
|
||||||
# Add internet connection to the VM
|
# Add internet connection to the VM
|
||||||
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
|
||||||
|
|
||||||
iptables -t nat -A POSTROUTING -o "${VM_NET_DEV}" -j MASQUERADE
|
iptables -t nat -A POSTROUTING -o "${VM_NET_DEV}" -j MASQUERADE
|
||||||
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p tcp -j DNAT --to $VM_NET_IP
|
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p tcp -j DNAT --to $VM_NET_IP
|
||||||
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p udp -j DNAT --to $VM_NET_IP
|
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p udp -j DNAT --to $VM_NET_IP
|
||||||
@@ -223,12 +195,10 @@ update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
|||||||
|
|
||||||
VM_NET_MAC="${VM_NET_MAC//-/:}"
|
VM_NET_MAC="${VM_NET_MAC//-/:}"
|
||||||
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
||||||
|
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||||
|
|
||||||
if [[ "${DEBUG}" == [Yy1]* ]]; then
|
if [[ "${DEBUG}" == [Yy1]* ]]; then
|
||||||
|
|
||||||
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
|
||||||
info "Container IP is ${IP} with gateway ${GATEWAY}" && echo
|
info "Container IP is ${IP} with gateway ${GATEWAY}" && echo
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${DHCP}" == [Yy1]* ]]; then
|
if [[ "${DHCP}" == [Yy1]* ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user