Why
My QNAP NAS hardware failed, but the disks remained intact. First attempts to retrieve data with a standard Linux distributionwas unsuccessful due to QNAP’s proprietary LVM extensions. So I need system with QNAP-flaivored kernel to attempt recover my data.
Step 1: Getting the QNAP Kernel Source
The QNAP Kernel is on SourceForge(yes it is still alive): QNAP Kernel Source. So go grab a couple of files:
QTS_Kernel_5.2.3.20250218.0.tar.gzQTS_Kernel_5.2.3.20250218.1.tar.gz
Step 2: Installing Debian “Jessie”
You will need Debian Jessie for that as it seems what QNAP folks are using.
- Install Debian Jessie,but do not enable network mirrors. (They will not work anyway)
- Run
apt-get install debian-archive-keyring. -
All packages for Jessie is in archive now. So edit
/etc/apt/sources.list– comment out the cdrom entry and add these:deb http://archive.debian.org/debian/ jessie main contrib deb-src http://archive.debian.org/debian/ jessie main contrib -
#apt-get update. You’ll hit some expired keys, but just ignore the errors. -
Install some build essentials:
apt-get install build-essential bc kmod cpio flex libncurses5-dev libelf-dev libssl-dev dwarves bison linux-source man-db less lvm2
Step 3: Extracting the Kernel
Move all those QNAP Kernel files to /usr/src/ and extract them:
cd /usr/src/
cat QTS_Kernel_5.2.3.20250218.0.tar.gz QTS_Kernel_5.2.3.20250218.1.tar.gz | tar xzv
Step 4: Kernel Configuration Tricks
While there are some kernel configs under GPL_QTS/kernel_cfg, I wasn’t sure what to do with them. Instead, I found and used this config: GPL_QTS/src/linux-5.10/QNAP/x86_64.cfg.
cd GPL_QTS/src/linux-5.10/
cat QNAP/x86_64.cfg >> .config
cat QNAP/X86_KABYLAKE.cfg >> .config
I used Kabbylake because my PC is running a Kaby Lake CPU. YMMV
Step 5: Building the Kernel
With everything in place, let’s try to build it
#make all
-
The build initially failed due to undefined symbols in
drivers/scsi/sd.c. Quick fix: add these definitions to the top of the file past includes:#define SD_NOOP 0 #define SD_VJBOD 0 #include "qnap/qnap_sg.h" - Now it is failing to compile iSCSI. I do not need it, so I commented it out in
.config.# CONFIG_ISCSI_TCP=m # CONFIG_ISCSI_TARGET=m # CONFIG_SCSI_ISCSI_ATTRS=m - Now it is failing in drivers/target which is part of configfs driver
commenting out same way as iSCSI
# CONFIG_TARGET_CORE=m - now failing in
net/ipv4/ip_input.c:148:72: fatal error: qnap/pic.h: No such file or directory #include <qnap/pic.h> /* for deliver message to picd */pic.h can not be found anywhere. So very dirty fix to stop it including that files by adding ‘&& 0’ at the end of #if line ``` /* Patch by QNAP: Add IP filter */
#if defined(CONFIG_MACH_QNAPTS) && !defined(QNAP_HAL) && 0 #include <qnap/pic.h> /* for deliver message to picd */ #endif
- it is not yet over.
"int is_filtered_by_ipsec_rules()" can't be compiled as send_message_to_app() not defined anywhere. More missing headers
I just comment out whole body of function leaving only return 0; Who knows what that function do, but it can return 0, so be let it always return 0 .
int is_filtered_by_ipsec_rules(struct sk_buff skb) { / if (filter_by_ipsec_rules(skb)) { add_to_violated_list(skb); #if !defined(QNAP_HAL) send_message_to_app(QNAP_BLOCK_IP_EVENT); #else send_hal_ip_block_event(skb); #endif return 1; } */ return 0; }
- one more attempt
linker is not happy now
drivers/scsi/sd.o: In function sd_probe':
sd.c:(.text+0x5941): undefined reference to qanp_scsi_add_sg’
Makefile:1179: recipe for target ‘vmlinux’ failed
```
that funtction is from ./drivers/scsi/qnap/qnap_sg.c
to make it compiled. Just edit .config and set
CONFIG_VIRTUAL_JBOD=y
Finally, kernel and modules compiled. But it is not all folks.
Step 6: Making It Work on My Hardware
The challenge now was getting the kernel to run my hardware, as it missing drivers to run on PC instead of QNAP box. NO generic recommendation possible here, as it depend on what is it going to run. make menuconfig to add device drivers for video, storage, and NIC.
I also added drivers for USB subsystem, as QNAP one did not work for me.
compile kernel again and install it
make all, make modules_install, make install.
make install - will also buld initramfs and update grub for you.
After rebooting, I found a new Grub entry for QNAP kernel 5.10.60.
My first attempt ended in initramfs because /dev/disk failed to populate, so root drive wasn’t found based on UUID, but it was still there as /dev/sda1
Fixing the Boot Problem
The quick fix: intercept the boot process by pressing “e” on the Grub entry. Edit the config to change root=UUID=xxxxx to root=/dev/sda1 (or whatever disk holds your root partition). Systemd will compline for a bit but boot up eventually.
Victory!
In the end I got franken-debian with QNAP kernel and rest of stuff from debian Jessy. Next step is try to access QNAP disks.
UPD(7/10/2025): I have failed in using this kernel to do the trick. I have to resort to extracting linux kernal and utilities from working QNAP system. As moral, do not use propritery systems. They alway find a way to bite you. Need NAS - build yourself. Do not whant to much hassle use freeNAS.