mirror of
https://github.com/AlbrechtL/openwrt-docker.git
synced 2026-10-14 16:01:29 +00:00
Merge pull request #9 from AlbrechtL/squashfs
Replace ext4 image and kernel image by squashfs-combined image
This commit is contained in:
+58
-48
@@ -57,61 +57,47 @@ RUN echo "Building for platform '$TARGETPLATFORM'" \
|
||||
multirun \
|
||||
bash \
|
||||
wget \
|
||||
grep \
|
||||
qemu-system-"$CPU_ARCH" \
|
||||
qemu-hw-usb-host \
|
||||
qemu-hw-usb-redirect \
|
||||
nginx \
|
||||
nginx-mod-stream \
|
||||
netcat-openbsd \
|
||||
tcpdump \
|
||||
uuidgen \
|
||||
curl \
|
||||
usbutils \
|
||||
openssh-client \
|
||||
util-linux-misc \
|
||||
&& mkdir -p /usr/share/novnc \
|
||||
&& wget https://github.com/novnc/noVNC/archive/refs/tags/v${NOVNC_VERSION}.tar.gz -O /tmp/novnc.tar.gz -q \
|
||||
&& tar -xf /tmp/novnc.tar.gz -C /tmp/ \
|
||||
&& cd /tmp/noVNC-${NOVNC_VERSION}\
|
||||
&& mv app core vendor package.json *.html /usr/share/novnc \
|
||||
&& sed -i 's/^worker_processes.*/worker_processes 1;daemon off;/' /etc/nginx/nginx.conf
|
||||
|
||||
|
||||
COPY ./openwrt_additional /var/vm/openwrt_additional
|
||||
|
||||
# Handle different CPUs architectures and choose the correct OpenWrt images
|
||||
RUN echo "Building for platform '$TARGETPLATFORM'" \
|
||||
OPKG_EXTRA_ARGS="" \
|
||||
&& if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
|
||||
if [ "$OPENWRT_VERSION" = "master" ]; then \
|
||||
OPENWRT_ROOTFS_IMG="https://downloads.openwrt.org/snapshots/targets/x86/64/openwrt-x86-64-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://downloads.openwrt.org/snapshots/targets/x86/64/openwrt-x86-64-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://downloads.openwrt.org/snapshots/targets/x86/64/openwrt-x86-64-rootfs.tar.gz"; \
|
||||
OPKG_EXTRA_ARGS="--no-check-certificate"; \
|
||||
OPENWRT_IMAGE="https://downloads.openwrt.org/snapshots/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz"; \
|
||||
elif [ "$OPENWRT_VERSION" = "24.10-SNAPSHOT" ]; then \
|
||||
wget https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/x86/64/version.buildinfo; \
|
||||
VERSION_BUILDINFO=`cat version.buildinfo`; \
|
||||
OPENWRT_ROOTFS_IMG="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/x86/64/openwrt-24.10-snapshot-${VERSION_BUILDINFO}-x86-64-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/x86/64/openwrt-24.10-snapshot-${VERSION_BUILDINFO}-x86-64-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/x86/64/openwrt-24.10-snapshot-${VERSION_BUILDINFO}-x86-64-rootfs.tar.gz"; \
|
||||
OPKG_EXTRA_ARGS="--no-check-certificate"; \
|
||||
OPENWRT_IMAGE="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/x86/64/openwrt-24.10-snapshot-${VERSION_BUILDINFO}-x86-64-generic-squashfs-combined.img.gz"; \
|
||||
else \
|
||||
OPENWRT_ROOTFS_IMG="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/x86/64/openwrt-${OPENWRT_VERSION}-x86-64-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/x86/64/openwrt-${OPENWRT_VERSION}-x86-64-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/x86/64/openwrt-${OPENWRT_VERSION}-x86-64-rootfs.tar.gz"; \
|
||||
OPENWRT_IMAGE="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/x86/64/openwrt-${OPENWRT_VERSION}-x86-64-generic-squashfs-combined.img.gz"; \
|
||||
fi; \
|
||||
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
|
||||
if [ "$OPENWRT_VERSION" = "master" ]; then \
|
||||
OPENWRT_ROOTFS_IMG="https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-rootfs.tar.gz"; \
|
||||
OPKG_EXTRA_ARGS="--no-check-certificate"; \
|
||||
OPENWRT_IMAGE="https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-generic-squashfs-combined.img.gz"; \
|
||||
elif [ "$OPENWRT_VERSION" = "24.10-SNAPSHOT" ]; then \
|
||||
wget https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/armsr/armv8/version.buildinfo; \
|
||||
VERSION_BUILDINFO=`cat version.buildinfo`; \
|
||||
OPENWRT_ROOTFS_IMG="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/armsr/armv8/openwrt-24.10-snapshot-${VERSION_BUILDINFO}-armsr-armv8-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/armsr/armv8/openwrt-24.10-snapshot-${VERSION_BUILDINFO}-armsr-armv8-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/armsr/armv8/openwrt-24.10-snapshot-${VERSION_BUILDINFO}-armsr-armv8-rootfs.tar.gz"; \
|
||||
OPKG_EXTRA_ARGS="--no-check-certificate"; \
|
||||
OPENWRT_IMAGE="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/armsr/armv8/openwrt-24.10-snapshot-${VERSION_BUILDINFO}-armsr-armv8-generic-squashfs-combined.img.gz"; \
|
||||
else \
|
||||
OPENWRT_ROOTFS_IMG="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-rootfs.tar.gz"; \
|
||||
OPENWRT_IMAGE="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-generic-squashfs-combined.img.gz"; \
|
||||
fi; \
|
||||
else \
|
||||
echo "Error: CPU architecture $TARGETPLATFORM is not supported"; \
|
||||
@@ -119,33 +105,58 @@ RUN echo "Building for platform '$TARGETPLATFORM'" \
|
||||
fi \
|
||||
\
|
||||
# Get OpenWrt images \
|
||||
&& mkdir /var/vm \
|
||||
&& mkdir /var/vm/packages \
|
||||
&& echo $OPENWRT_ROOTFS_IMG \
|
||||
&& wget $OPENWRT_ROOTFS_IMG -O /var/vm/rootfs-${OPENWRT_VERSION}.img.gz \
|
||||
&& wget "${OPENWRT_KERNEL}" -O /var/vm/kernel.bin \
|
||||
&& wget "${OPENWRT_ROOTFS_TAR}" -O /tmp/rootfs-${OPENWRT_VERSION}.tar.gz \
|
||||
&& wget $OPENWRT_IMAGE -O /var/vm/squashfs-combined-${OPENWRT_VERSION}.img.gz \
|
||||
&& gzip -d /var/vm/squashfs-combined-${OPENWRT_VERSION}.img.gz \
|
||||
\
|
||||
# Use OpenWrt rootfs to download additional IPKs and put them into the Docker image \
|
||||
&& mkdir /tmp/openwrt-rootfs \
|
||||
&& tar -xzf /tmp/rootfs-${OPENWRT_VERSION}.tar.gz -C /tmp/openwrt-rootfs \
|
||||
&& cp /etc/resolv.conf /tmp/openwrt-rootfs/etc/resolv.conf \
|
||||
&& chroot /tmp/openwrt-rootfs mkdir -p /var/lock \
|
||||
&& chroot /tmp/openwrt-rootfs opkg ${OPKG_EXTRA_ARGS} update \
|
||||
# Boot OpenWrt in order to install additional packages and settings
|
||||
&& if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
|
||||
qemu-system-x86_64 -M pc -smp 2 -nographic -nodefaults -m 256 \
|
||||
-blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=/var/vm/squashfs-combined-${OPENWRT_VERSION}.img \
|
||||
-device virtio-blk-pci,drive=hd0 \
|
||||
-device virtio-net,netdev=qlan0 -netdev user,id=qlan0,net=192.168.1.0/24,hostfwd=tcp::8022-192.168.1.1:22 \
|
||||
-device virtio-net,netdev=qwan0 -netdev user,id=qwan0 \
|
||||
-daemonize; \
|
||||
else \
|
||||
qemu-system-aarch64 -M virt -cpu cortex-a53 -smp 2 -nographic -nodefaults -m 256 \
|
||||
-bios /usr/share/qemu/edk2-aarch64-code.fd \
|
||||
-blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=/var/vm/squashfs-combined-${OPENWRT_VERSION}.img \
|
||||
-device virtio-blk-pci,drive=hd0 \
|
||||
-device virtio-net,netdev=qlan0 -netdev user,id=qlan0,net=192.168.1.0/24,hostfwd=tcp::8022-192.168.1.1:22 \
|
||||
-device virtio-net,netdev=qwan0 -netdev user,id=qwan0 \
|
||||
-daemonize; \
|
||||
fi \
|
||||
\
|
||||
&& until ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new root@localhost -p 8022 'opkg update'; do echo "Retrying ssh ..."; sleep 1; done \
|
||||
# Download Luci, qemu guest agent and mDNS support \
|
||||
&& chroot /tmp/openwrt-rootfs opkg ${OPKG_EXTRA_ARGS} install qemu-ga luci luci-ssl umdns --download-only \
|
||||
&& ssh root@localhost -p 8022 'opkg install qemu-ga luci luci-ssl umdns' \
|
||||
# Download Wi-Fi access point support and Wi-Fi USB devices support \
|
||||
&& chroot /tmp/openwrt-rootfs opkg ${OPKG_EXTRA_ARGS} install hostapd wpa-supplicant kmod-mt7921u --download-only \
|
||||
&& ssh root@localhost -p 8022 'opkg install hostapd wpa-supplicant kmod-mt7921u' \
|
||||
# Download celluar network support \
|
||||
&& chroot /tmp/openwrt-rootfs opkg ${OPKG_EXTRA_ARGS} install modemmanager kmod-usb-net-qmi-wwan luci-proto-modemmanager qmi-utils --download-only \
|
||||
&& ssh root@localhost -p 8022 'opkg install modemmanager kmod-usb-net-qmi-wwan luci-proto-modemmanager qmi-utils' \
|
||||
# Download basic GPS support \
|
||||
&& chroot /tmp/openwrt-rootfs opkg ${OPKG_EXTRA_ARGS} install kmod-usb-serial usbutils minicom gpsd --download-only \
|
||||
&& ssh root@localhost -p 8022 'opkg install kmod-usb-serial usbutils minicom gpsd' \
|
||||
# Add Wireguard support \
|
||||
&& chroot /tmp/openwrt-rootfs opkg ${OPKG_EXTRA_ARGS} install wireguard-tools luci-proto-wireguard --download-only \
|
||||
# Copy downloaded IPKs into the Docker image \
|
||||
&& cp /tmp/openwrt-rootfs/*.ipk /var/vm/packages \
|
||||
&& rm -rf /tmp/openwrt-rootfs \
|
||||
&& rm /tmp/rootfs-${OPENWRT_VERSION}.tar.gz \
|
||||
&& ssh root@localhost -p 8022 'opkg install wireguard-tools luci-proto-wireguard' \
|
||||
\
|
||||
# Add default network config \
|
||||
&& ssh root@localhost -p 8022 "uci set network.lan.ipaddr='172.31.1.1'; uci commit network" \
|
||||
\
|
||||
# Add some files \
|
||||
&& ssh root@localhost -p 8022 'opkg install openssh-sftp-server' \
|
||||
&& chmod +x /var/vm/openwrt_additional/usr/bin/* \
|
||||
&& scp -P 8022 /var/vm/openwrt_additional/usr/bin/* root@localhost:/usr/bin \
|
||||
&& ssh root@localhost -p 8022 'opkg remove openssh-sftp-server' \
|
||||
\
|
||||
# Sync changes into image and kill qemu
|
||||
&& ssh root@localhost -p 8022 'sync; halt' \
|
||||
&& if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
|
||||
while pgrep -x "qemu-system-x86_64" >/dev/null; do echo "Wait for exit of qemu ..."; sleep 1; done; \
|
||||
else \
|
||||
while pgrep -x "qemu-system-aarch64" >/dev/null; do echo "Wait for exit of qemu ..."; sleep 1; done \
|
||||
fi \
|
||||
\
|
||||
&& gzip /var/vm/squashfs-combined-${OPENWRT_VERSION}.img \
|
||||
\
|
||||
&& echo "OPENWRT_VERSION=\"${OPENWRT_VERSION}\"" > /var/vm/openwrt_metadata.conf \
|
||||
&& echo "OPENWRT_IMAGE_CREATE_DATETIME=\"`date`\"" >> /var/vm/openwrt_metadata.conf \
|
||||
&& echo "OPENWRT_IMAGE_ID=\"`uuidgen`\"" >> /var/vm/openwrt_metadata.conf \
|
||||
@@ -154,7 +165,6 @@ RUN echo "Building for platform '$TARGETPLATFORM'" \
|
||||
COPY --from=builder /usr/local/bin/qemu-openwrt-web-backend /usr/local/bin/qemu-openwrt-web-backend
|
||||
COPY ./src /run/
|
||||
COPY ./web-frontend /var/www/
|
||||
COPY ./openwrt_additional /var/vm/openwrt_additional
|
||||
|
||||
RUN chmod +x /run/*.sh
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
# Remount rootfs to enable sync
|
||||
mount -o remount,rw,sync /
|
||||
|
||||
exit 0
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci set network.lan.ipaddr='172.31.1.1'
|
||||
uci commit network
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#/bin/sh
|
||||
|
||||
echo "Get packages list from repo"
|
||||
opkg update
|
||||
|
||||
echo "Restore packages"
|
||||
grep '\tunknown' /etc/backup/installed_packages.txt | cut -f1 | xargs opkg install
|
||||
@@ -6,46 +6,19 @@ trap - ERR
|
||||
. /var/vm/openwrt_metadata.conf
|
||||
. /run/helpers.sh
|
||||
|
||||
# Check if rootfs is in volume
|
||||
FILE=/storage/rootfs-${OPENWRT_IMAGE_ID}.img
|
||||
# Check if squashfs-combined is in volume
|
||||
FILE=/storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img
|
||||
if [ -f "$FILE" ]; then
|
||||
info "$FILE exists. Nothing to do."
|
||||
else
|
||||
info "$FILE does not exist. Copying rootfs-${OPENWRT_VERSION}.img to storage ..."
|
||||
cp /var/vm/rootfs-${OPENWRT_VERSION}.img.gz /storage/rootfs-${OPENWRT_IMAGE_ID}.img.gz
|
||||
gzip -d /storage/rootfs-${OPENWRT_IMAGE_ID}.img.gz
|
||||
info "$FILE does not exist. Copying squashfs-combined-${OPENWRT_VERSION}.img to storage ..."
|
||||
cp /var/vm/squashfs-combined-${OPENWRT_VERSION}.img.gz /storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img.gz
|
||||
gzip -d /storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img.gz
|
||||
|
||||
info "Inject some additional files into the image"
|
||||
mount /storage/rootfs-${OPENWRT_IMAGE_ID}.img /mnt
|
||||
# mount -o offset=$((512*262656)) /storage/disk.img /mnt # combined image ext4 partition starts at offset 262656
|
||||
|
||||
chmod +x /var/vm/openwrt_additional/usr/bin/*
|
||||
cp /var/vm/openwrt_additional/usr/bin/* /mnt/usr/bin/
|
||||
|
||||
mv /mnt/etc/rc.local /mnt/etc/rc.local.orig
|
||||
cp /var/vm/openwrt_additional/etc/rc.local /mnt/etc/rc.local
|
||||
chmod +x /mnt/etc/rc.local
|
||||
|
||||
# Add some additional default configurations. Only if we have a fresh container because /storage/current_version is not existing then
|
||||
if [ ! -f /storage/current_version ]; then
|
||||
chmod +x /var/vm/openwrt_additional/etc/uci-defaults/*
|
||||
cp /var/vm/openwrt_additional/etc/uci-defaults/* /mnt/etc/uci-defaults/
|
||||
fi
|
||||
|
||||
info "Install additional IPKs into the image"
|
||||
mkdir /mnt/var/offline_packages
|
||||
cp /var/vm/packages/*.ipk /mnt/var/offline_packages/
|
||||
chroot /mnt/ mkdir -p /var/lock
|
||||
chroot /mnt/ sh -c 'cd /var/offline_packages/ && opkg install *.ipk'
|
||||
rm -rf /mnt/var/offline_packages/
|
||||
rm -rf /mnt/var/lock
|
||||
|
||||
umount /mnt
|
||||
|
||||
if [ -f "/storage/current_version" ]; then
|
||||
mv /storage/current_version /storage/old_version
|
||||
fi
|
||||
|
||||
touch /storage/current_version
|
||||
echo "rootfs-${OPENWRT_IMAGE_ID}.img" > /storage/current_version
|
||||
echo "squashfs-combined-${OPENWRT_IMAGE_ID}.img" > /storage/current_version
|
||||
fi
|
||||
|
||||
+143
-18
@@ -6,32 +6,157 @@ trap - ERR
|
||||
. /var/vm/openwrt_metadata.conf
|
||||
. /run/helpers.sh
|
||||
|
||||
FILE=/storage/rootfs-${OPENWRT_IMAGE_ID}.img
|
||||
# Function to find the squashfs file system start offset from a OpenWrt given file
|
||||
find_squashfs_offset() {
|
||||
local IMAGE_FILE="$1"
|
||||
echo >&2 "Start finding start of squashfs file system in file '"$IMAGE_FILE"' ..."
|
||||
|
||||
# Use fdisk to find the squashfs partition
|
||||
local squashfs_start_sectors=`fdisk -l "$IMAGE_FILE" | awk '/^.*squashfs-combined.*.img2/ {print $2}'` # use the 4th ouput as sectors
|
||||
|
||||
if [ -z "$squashfs_start_sectors" ]; then
|
||||
echo >&2 "No squashfs-combined*.img2 found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local squashfs_offset=$(( squashfs_start_sectors * 512 )) # Each sector has 512 bytes
|
||||
|
||||
echo >&2 "squashfs file system start at offset 0x$(printf '%x' "$squashfs_offset")"
|
||||
|
||||
echo $squashfs_offset
|
||||
}
|
||||
|
||||
# Function to find the ext4 file system start offset from a OpenWrt given file
|
||||
find_ext4_offset() {
|
||||
local IMAGE_FILE="$1"
|
||||
echo >&2 "Start finding start of ext4 file system in file '$IMAGE_FILE' ..."
|
||||
|
||||
# Define the search boundary (in bytes)
|
||||
local SEARCH_BOUNDARY=200 # This is the search boundary for extracting data before and after 'rootfs_data'
|
||||
local EXT4_MAGIC_KEY="\x53\xef" # This is the magic key identifying the ext4 file system (as hex string)
|
||||
local ROOTFS_PATTERN="rootfs_data" # This is the pattern we are searching for in the file
|
||||
|
||||
# Step 1: Find the OFFSET of the first occurrence of 'rootfs_data'
|
||||
local OFFSET=`grep -obam 1 "$ROOTFS_PATTERN" "$IMAGE_FILE" | awk -F':' '{print $1}'`
|
||||
|
||||
if [ -z "$OFFSET" ]; then
|
||||
echo >&2 "'$ROOTFS_PATTERN' not found in the file."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Output OFFSET in hexadecimal format
|
||||
echo >&2 "Found volume name '$ROOTFS_PATTERN' at offset: 0x$(printf '%x' "$OFFSET")"
|
||||
|
||||
# Step 2: Use dd to extract the bytes and search for the EXT4_MAGIC_KEY
|
||||
# Extract the byte offset from the grep result (this is relative to the start of the dd block)
|
||||
local offset_in_block=`dd if="$IMAGE_FILE" bs=1 skip=$((OFFSET - SEARCH_BOUNDARY)) count=$SEARCH_BOUNDARY 2>/dev/null |
|
||||
LANG=C grep -obUaPm 1 $EXT4_MAGIC_KEY | cut -d: -f1`
|
||||
|
||||
if [ -z "$offset_in_block" ]; then
|
||||
echo >&2 "ext4 magic key not found in the file."
|
||||
return 1
|
||||
fi
|
||||
|
||||
local actual_offset=$((offset_in_block + OFFSET - SEARCH_BOUNDARY)) # Adjust the offset to the actual position in the original file
|
||||
local ext4_start_offset=$((actual_offset - 1080)) # Subtract 1080 bytes from the found offset. ext4 is starting 1080 before 0x53ef
|
||||
|
||||
# Show the adjusted actual_offset
|
||||
#echo >&2 "Offset in dd block: 0x$(printf '%x' "$offset_in_block")"
|
||||
echo >&2 "Found ext4 magic key '$EXT4_MAGIC_KEY' at offset: 0x$(printf '%x' "$actual_offset")"
|
||||
echo >&2 "ext4 file system start at offset: 0x$(printf '%x' "$ext4_start_offset")"
|
||||
|
||||
echo $ext4_start_offset
|
||||
}
|
||||
|
||||
# Function to find the ext4 file system start offset from a OpenWrt given file
|
||||
find_f2fs_offset() {
|
||||
local IMAGE_FILE="$1"
|
||||
local SQUASHFS_OFFSET="$2"
|
||||
echo >&2 "Start finding start of j2fs file system in file '$IMAGE_FILE' ..."
|
||||
|
||||
# Define the search boundary (in bytes)
|
||||
local SQUASHFS_SIZE_APPROX=4000000 # This is the size assumtion of squashfs file system that is located before the j2fs
|
||||
local J2FS_MAGIC_KEY="\x10\x20\xf5\xf2" # This is the magic key identifying the ext4 file system (as hex string)
|
||||
|
||||
local offset_in_block=`dd if="$IMAGE_FILE" bs=1 skip=$((SQUASHFS_OFFSET + SQUASHFS_SIZE_APPROX)) 2>/dev/null | \
|
||||
LANG=C grep -obUaPm 1 "$J2FS_MAGIC_KEY" | cut -d: -f1`
|
||||
|
||||
if [ -z "$offset_in_block" ]; then
|
||||
echo >&2 "j2fs magic key not found in the file."
|
||||
return 1
|
||||
fi
|
||||
|
||||
local actual_offset=$((offset_in_block + SQUASHFS_OFFSET + SQUASHFS_SIZE_APPROX)) # Adjust the offset to the actual position in the original file
|
||||
local j2fs_start_offset=$((actual_offset - 1024)) # Subtract 1024 bytes from the found offset. j2fs is starting 1024 before 0x1020f5f2
|
||||
|
||||
echo >&2 "Found j2fs magic key '$J2FS_MAGIC_KEY' at offset: 0x$(printf '%x' "$actual_offset")"
|
||||
echo >&2 "j2fs file system start at offset: 0x$(printf '%x' "$j2fs_start_offset")"
|
||||
|
||||
echo $j2fs_start_offset
|
||||
}
|
||||
|
||||
mount_squashfs_combined_image() {
|
||||
local IMAGE_FILE="$1"
|
||||
|
||||
squashfs_start_offset=$(find_squashfs_offset "$IMAGE_FILE")
|
||||
|
||||
CPU_ARCH=$(arch)
|
||||
if [ $CPU_ARCH = "aarch64" ]; then
|
||||
start_offset=$(find_f2fs_offset "$IMAGE_FILE" "$squashfs_start_offset")
|
||||
else
|
||||
start_offset=$(find_ext4_offset "$IMAGE_FILE")
|
||||
fi
|
||||
|
||||
mkdir -p /tmp/squashfs_dir
|
||||
mkdir -p /tmp/userdata_dir
|
||||
|
||||
mount -o offset="$squashfs_start_offset",sizelimit=$((start_offset-squashfs_start_offset)) "$IMAGE_FILE" /tmp/squashfs_dir
|
||||
mount -o offset="$start_offset" "$IMAGE_FILE" /tmp/userdata_dir
|
||||
mount -t overlay -o lowerdir=/tmp/squashfs_dir,upperdir=/tmp/userdata_dir/upper,workdir=/tmp/userdata_dir/work overlay /mnt
|
||||
}
|
||||
|
||||
umount_squashfs_combined_image() {
|
||||
umount /mnt
|
||||
umount /tmp/userdata_dir
|
||||
umount /tmp/squashfs_dir
|
||||
}
|
||||
|
||||
SQUASHFS_COMBINED=/storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img
|
||||
|
||||
# Migrate settings from old OpenWrt version to new one
|
||||
if [ -f /storage/old_version ]; then
|
||||
OLD_VERSION_ROOTFS=`cat /storage/old_version`
|
||||
OLD_SQUASHFS_COMBINED=`cat /storage/old_version`
|
||||
|
||||
info "Migrate settings from $OLD_VERSION_ROOTFS to rootfs-${OPENWRT_IMAGE_ID}.img."
|
||||
|
||||
mount /storage/$OLD_VERSION_ROOTFS /mnt
|
||||
chroot /mnt/ mkdir -p /var/lock
|
||||
chroot /mnt /sbin/sysupgrade -k -b /tmp/openwrt_config.tar.gz
|
||||
mv /mnt/tmp/openwrt_config.tar.gz /storage/config-`basename $OLD_VERSION_ROOTFS .img`.tar.gz
|
||||
umount /mnt
|
||||
info "Migrate settings from $OLD_SQUASHFS_COMBINED to squashfs-combined-${OPENWRT_IMAGE_ID}.img."
|
||||
|
||||
# Put config backup to new rootfs
|
||||
mount $FILE /mnt
|
||||
# Create config backup in previos image
|
||||
if [[ $OLD_SQUASHFS_COMBINED == *"rootfs"* ]]; then
|
||||
warn "Using rootfs-<UUID>.img images is deprecated!"
|
||||
mount /storage/$OLD_SQUASHFS_COMBINED /mnt
|
||||
chroot /mnt/ mkdir -p /var/lock
|
||||
chroot /mnt /sbin/sysupgrade -k -b /tmp/openwrt_config.tar.gz
|
||||
mv /mnt/tmp/openwrt_config.tar.gz /storage/config-`basename $OLD_SQUASHFS_COMBINED.img`.tar.gz
|
||||
umount /mnt
|
||||
else
|
||||
mount_squashfs_combined_image /storage/$OLD_SQUASHFS_COMBINED
|
||||
chroot /mnt/ mkdir -p /var/lock
|
||||
chroot /mnt /sbin/sysupgrade -k -b /tmp/openwrt_config.tar.gz
|
||||
mv /mnt/tmp/openwrt_config.tar.gz /storage/config-`basename $OLD_SQUASHFS_COMBINED.img`.tar.gz
|
||||
umount_squashfs_combined_image
|
||||
fi
|
||||
|
||||
# Put config backup to new squashfs-combined
|
||||
mount_squashfs_combined_image $SQUASHFS_COMBINED
|
||||
mkdir -p /mnt/root/backup
|
||||
cp /storage/config-`basename $OLD_VERSION_ROOTFS .img`.tar.gz /mnt/root/backup/config.tar.gz
|
||||
cp /storage/config-`basename $OLD_SQUASHFS_COMBINED.img`.tar.gz /mnt/root/backup/config.tar.gz
|
||||
chroot /mnt/ mkdir -p /var/lock
|
||||
chroot /mnt /sbin/sysupgrade -r /root/backup/config.tar.gz
|
||||
umount /mnt
|
||||
umount_squashfs_combined_image
|
||||
|
||||
# Finally remove old rootfs and old files
|
||||
rm /storage/$OLD_VERSION_ROOTFS
|
||||
# Finally remove old squashfs-combined and old files
|
||||
rm /storage/$OLD_SQUASHFS_COMBINED
|
||||
rm /storage/old_version
|
||||
rm /storage/config-`basename $OLD_VERSION_ROOTFS .img`.tar.gz
|
||||
rm /storage/config-`basename $OLD_SQUASHFS_COMBINED.img`.tar.gz
|
||||
else
|
||||
info "rootfs-${OPENWRT_IMAGE_ID}.img is up to date. Nothing to do."
|
||||
fi
|
||||
info "squashfs-combined-${OPENWRT_IMAGE_ID}.img is up to date. Nothing to do."
|
||||
fi
|
||||
+3
-6
@@ -13,7 +13,7 @@ trap - ERR
|
||||
CPU_ARCH=$(arch)
|
||||
|
||||
VERS=$(qemu-system-"$CPU_ARCH" --version | head -n 1 | cut -d '(' -f 1)
|
||||
FILE=/storage/rootfs-${OPENWRT_IMAGE_ID}.img
|
||||
FILE=/storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img
|
||||
|
||||
# Attach physical interfaces to Docker container
|
||||
attach_eth_if () {
|
||||
@@ -212,11 +212,10 @@ info "Booting image using $VERS..."
|
||||
|
||||
#************************ FINAL BOOTING ************************
|
||||
exec qemu-system-"$CPU_ARCH" \
|
||||
-m 128 \
|
||||
-m 256 \
|
||||
-nodefaults \
|
||||
$CPU_ARGS -smp $CPU_COUNT \
|
||||
-display vnc=:0,websocket=5700 \
|
||||
-kernel /var/vm/kernel.bin -append "root=fe00 console=tty0" \
|
||||
-blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=${FILE} \
|
||||
-device virtio-blk-pci,drive=hd0 \
|
||||
-device qemu-xhci -device usb-kbd \
|
||||
@@ -228,6 +227,4 @@ exec qemu-system-"$CPU_ARCH" \
|
||||
-device virtio-serial \
|
||||
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
|
||||
|
||||
|
||||
# -device virtio-net,netdev=qlan1 -netdev user,id=qlan1,net=192.168.1.0/24,hostfwd=tcp::8000-192.168.1.1:80 \
|
||||
# -blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=/var/vm/openwrt-armsr-armv8-generic-ext4-combined.img \
|
||||
# -kernel /var/vm/kernel.bin -append "root=fe00 console=tty0" \
|
||||
|
||||
@@ -369,34 +369,6 @@ def test_cpu_num(docker_services, parameter):
|
||||
assert parameter[1] == cpu_num
|
||||
|
||||
|
||||
def test_additional_installed_packages(docker_services):
|
||||
# Get list of packages to be installed in OpenWrt
|
||||
process = subprocess.run(['docker','exec','openwrt','ls','/var/vm/packages'],
|
||||
stdout=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
assert process.returncode == 0
|
||||
|
||||
package_list_docker_full = process.stdout.splitlines()
|
||||
package_list_docker = []
|
||||
for package in package_list_docker_full:
|
||||
package = package.split('_')[0] # Use only the name before the '_'
|
||||
package_list_docker.append(package)
|
||||
|
||||
# Get list of installed packages in OpenWrt
|
||||
wait_for_openwrt_startup(docker_services)
|
||||
response = run_openwrt_shell_command("opkg", "list-installed")
|
||||
|
||||
assert response['exitcode'] == 0
|
||||
|
||||
package_list_openwrt_full = response['out-data'].splitlines()
|
||||
print(f"'{len(package_list_docker)}' additional installed packages", end=' ')
|
||||
|
||||
# Check if all additional OpenWrt packages in Docker image are installed in OpenWrt
|
||||
for package in package_list_docker:
|
||||
assert any(package in s for s in package_list_openwrt_full) == True
|
||||
|
||||
|
||||
@pytest.mark.parametrize("parameter",
|
||||
[('','','20240922_test_volume_openwrt_23.05.4.tar.gz')], indirect=True,
|
||||
ids=['20240922_test_volume_openwrt_23.05.4'])
|
||||
|
||||
Reference in New Issue
Block a user