Unverified Commit 5589e512 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

New partition generation method

Create them dynamicly using sfdisk instead of using a disk template
parents d97d45aa dba6e3c0
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ RUN apt-get update && apt-get -y upgrade && \
	curl \
	cpio \
	wget \
	fdisk \
	unzip \
	procps \
	dnsmasq \
@@ -44,8 +45,6 @@ RUN ["chmod", "+x", "/run/run.sh"]
RUN ["chmod", "+x", "/run/server.sh"]
RUN ["chmod", "+x", "/run/serial.bin"]

COPY disks/template.img.xz /data/

VOLUME /storage

EXPOSE 22

disks/template.img.xz

deleted100644 → 0
−709 KiB

File deleted.

+30 −32
Original line number Diff line number Diff line
@@ -42,18 +42,19 @@ chmod +x /run/extract/syno_extract_system_patch

rm -rf $TMP && mkdir -p $TMP

echo "Install: Downloading $URL..."

PAT="$TMP/dsm.pat"
echo "Install: Downloading $(basename $URL)..."

# Check if running with interactive TTY or redirected to docker log
if [ -t 1 ]; then
  wget "$URL" -O "$PAT" -q --no-check-certificate --show-progress
  wget "$URL" -O /$BASE.pat -q --no-check-certificate --show-progress
else
  wget "$URL" -O "$PAT" -q --no-check-certificate --show-progress --progress=dot:giga
  wget "$URL" -O /$BASE.pat -q --no-check-certificate --show-progress --progress=dot:giga
fi

[ ! -f "$PAT" ] && echo "Download failed" && exit 61
[ ! -f "/$BASE.pat" ] && echo "Download failed" && exit 61

PAT="$TMP/dsm.pat"
mv /$BASE.pat $PAT

SIZE=$(stat -c%s "$PAT")

@@ -90,28 +91,30 @@ BOOT=$(find $TMP -name "*.bin.zip")
BOOT=$(echo "$BOOT" | head -c -5)
unzip -q -o "$BOOT".zip -d $TMP

echo "Install: Extracting prepared disk image..."
echo "Install: Creating partition table..."

SYSTEM="$TMP/temp.img"
PLATE="/data/template.img"
SYSTEM="$TMP/sys.img"
truncate -s 4954537983 "${SYSTEM}"

rm -f $PLATE
unxz $PLATE.xz
mv -f $PLATE $SYSTEM
PART="$TMP/partition.fdisk"

echo "Install: Extracting system partition..."
{	echo "label: dos"
	echo "label-id: 0x6f9ee2e9"
	echo "device: ${SYSTEM}"
	echo "unit: sectors"
	echo "sector-size: 512"
	echo ""
	echo "${SYSTEM}1 : start=        2048, size=     4980480, type=83"
	echo "${SYSTEM}2 : start=     4982528, size=     4194304, type=82"
} > $PART

PRIVILEGED=false
LABEL="1.44.1-42218"
OFFSET="1048576" # 2048 * 512
NUMBLOCKS="622560" # 2550005760 / 4096
sfdisk -q $SYSTEM < $PART

MOUNT="/mnt/tmp"
rm -rf $MOUNT && mkdir -p $MOUNT
echo "Install: Extracting system partition..."

mount -t ext4 -o loop,offset=$OFFSET $SYSTEM $MOUNT 2>/dev/null && PRIVILEGED=true
MOUNT="$TMP/system"

rm -rf ${MOUNT:?}/{,.[!.],..?}*
rm -rf $MOUNT && mkdir -p $MOUNT

mv -f $HDA.tgz $HDA.txz

@@ -138,18 +141,13 @@ chmod +x $LOC/agent.sh
# Store agent version
echo "2" > "$IMG"/"$BASE".agent

if [ "$PRIVILEGED" = false ]; then

echo "Install: Installing system partition..."

  # Workaround for containers that are not privileged to mount loop devices
  mke2fs -q -t ext4 -b 4096 -d $MOUNT/ -L $LABEL -F -E offset=$OFFSET $SYSTEM $NUMBLOCKS

else

  umount $MOUNT
LABEL="1.44.1-42218"
OFFSET="1048576" # 2048 * 512
NUMBLOCKS="622560" # (4980480 * 512) / 4096

fi
mke2fs -q -t ext4 -b 4096 -d $MOUNT/ -L $LABEL -F -E offset=$OFFSET $SYSTEM $NUMBLOCKS

rm -rf $MOUNT

+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ _graceful_shutdown(){
  [ -f "${_QEMU_SHUTDOWN_COUNTER}" ] && return

  set +e
  echo
  echo "Received $1 signal, shutting down..."
  echo 0 > "${_QEMU_SHUTDOWN_COUNTER}"

@@ -39,6 +40,7 @@ _graceful_shutdown(){

  if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then

    echo
    echo "Could not send shutdown command to guest, error: $RESPONSE"

    FILE="${IMG}/${BASE}.agent"
@@ -46,6 +48,7 @@ _graceful_shutdown(){
    AGENT_VERSION=$(cat "${FILE}")

    if ((AGENT_VERSION < 2)); then
      echo
      echo "Please update the agent to allow gracefull shutdowns..."
      pkill -f qemu-system-x86_64
    else
@@ -69,6 +72,7 @@ _graceful_shutdown(){
    fi
  done

  echo
  echo "Quitting..."
  echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT:-7100}">/dev/null || true