最後更新: 2023-09-05
目錄
- Compile RedPill-LKM - redpill.ko (Kernel Module)
- 建立 Bootable Image
介紹
redpill 項目有3個子項目, 分別係
- redpill.ko # 負責扮 Synology 的硬件
- redpill-load # patch script, 並建立 bootable 的 raw image
- dsm-research # 技術文件
原理
redpill-load 包含 build-loader.sh 在做什麼
- 下載 DSM 的 pat 到 Cache Folder (ds3615xs_25556.pat)
-
Verified checksum of a known zlinux& ramdisk files
(config/DS3615xs/6.2.4-25556/config.json) - Unpack pat 到 build 目錄
-
Patches the kernel zlinux using included patches [direct mode]
(zImage-001-3615xs-25556-ramdisk-and-header.bsp) -
Unpacks ramdisk
- Applies common patches (disable root pw, add RP LKM loading etc)
- Generates synoinfo replacements based on the platform requirements AND user configuration
- Patches synoinfo in etc & etc.defaults in the ramdisk image
- Adds dynamic patching routines to post-init script (so that synoinfo is patched in the booted OS too)
- Copies missing VirtIO modules (original DSM script supports them but they're not included in non-VDSM builds) - Reassembles ramdisk(rd.gz)
- 在當前目錄建立 raw image 檔
Patching the kernel mothod:
- direct (Default)
- repack (BRP_LINUX_PATCH_METHOD=repack)
* In the repack mode the kernel is NOT patched using direct binary patches between original and final.
* Each version requires a static kernel patch.
Info.
- DSM 6.2.4 = Kernel v3 <= 要用 GCC v4.8/v4.9 去 compile, 否認會失敗 !
Compile RedPill-LKM - redpill.ko
下載 DSM 6.2.4 的 Linux Kernel Source
- HW: ds3515xs => bromolow
- DSM Version 6.2.4 => 25426
- Linux Kernel => 3.10.x
# linux kernel source
https://archive.synology.com/download/ToolChain/Synology%20NAS%20GPL%20Source
Complie redpill on Centos 7
# 準備
yum groupinstall "Development Tools" # gcc version 4.8.5
# 準備 package source
tar -Jxf linux-3.10.x.txz
cd linux-3.10.x
cp synoconfigs/bromolow .config
make oldconfig ; make modules_prepare
# redpill-lkm
cd /usr/src
git clone https://github.com/RedPill-TTG/redpill-lkm
cd redpill-lkm; git pull
Already up-to-date.
# 查看支援
grep ^prod-v Makefile
prod-v6: # kernel running in v6.2+ OS, fully stripped with no debug messages prod-v7: # kernel running in v6.2+ OS, fully stripped with no debug messages
make LINUX_SRC=../linux-3.10.x prod-v6 # 另有 dev-v6, test-v6
# Checking
ls -lh redpill.ko
-rw-r--r-- 1 root root 108K Sep 23 04:35 redpill.ko
建立 Bootable Image
準備
yum install jq # v1.6 epel
在 Centos 7 compile 它們
- Compile bash 5.X # 系統上的 bash 太舊, 行 build-loader.sh 會出 error
- compile bsdiff # 系統沒有它, 亦要人手 compile
# Get Source Code
# pocopico 版本才支援 DSM 7.1
git clone https://github.com/pocopico/redpill-load
cd redpill-load; git pull
# Config
建立 user_config.json
{ "extra_cmdline": { "sn": "<fill me>", "mac1": "005056888801", "mac2": "005056888802" } }
# ESXi 的 MAC Address "00:50:56:x:x:x" 是不可以人手指定
其他 Setting
ie.
ls -1 config/DS3615xs/*/config.json
config/DS3615xs/6.2.4-25556/config.json config/DS3615xs/7.0.1-42218/config.json config/DS3615xs/7.0-41222/config.json config/DS3615xs/7.1.0-42621/config.json config/DS3615xs/7.1.0-42661/config.json
# Copy Kernel module(redpill.ko) 到 rp-lkm
# Path: ext/rp-lkm/redpill-linux-<VERSION>.ko
grep -A 3 ramdisk_copy config/DS3615xs/7.0.1-42218/config.json
"ramdisk_copy": { "@@@EXT@@@/rp-lkm/redpill-linux-v3.10.108.ko": "usr/lib/modules/rp.ko", "@@@COMMON@@@/iosched-trampoline.sh": "usr/sbin/modprobe" },
cp ../redpill-lkm/redpill.ko ext/rp-lkm/redpill-linux-v3.10.108.ko
# 下載 pat 到 cache folder
# 注意要改名 !!
cd cache
下載 DSM_DS3615xs_42218.pat
mv DSM_DS3615xs_42218.pat ds3615xs_42218.pat
# Build
Run ./build-loader.sh <hw_version> <os_version> [output-file]
e.g.
export PATH=/opt/bash/bin:$PATH # 設定要 bash 5.0
./build-loader.sh DS3615xs 7.0.1-42218 redpill.img
ls -lh ./redpill.img
-rw-r--r-- 1 root root 128M Dec 15 17:59 ./redpill.img
# 修改 loader
losetup -f
losetup /dev/loop0 redpill.img
partprobe /dev/loop0
ls -1 /dev/loop0*
/dev/loop0 /dev/loop0p1 # vfat /dev/loop0p2 # ext2 /dev/loop0p3 # Empty
mkdir /mnt/p1 /mnt/p2
mount /dev/loop0p1 /mnt/p1
vim /mnt/p1/boot/grub/grub.cfg
...
# 直接用 SATA boot
#set default="0"
set default="1"
#set timeout="1"
set timeout="1"
...
menuentry 'RedPill DS3615xs v6.2.4-25556 (SATA, Verbose)' {
savedefault
set root=(hd0,msdos1)
echo Loading Linux...
linux /zImage ... SataPortMap=16 DiskIdxMap=1000
cd -; umount /mnt/p1; losetup -d loop0
loop0p1 Partition
- grub(grub-0.97),
- rd.gz(patched ramdisk),
- zImage(patched zImage),
- GRUB_VER(orig pat),
- custom.gz (rp.ko, boot-wait.sh, virtio)
loop0p2 Partition
rd.gz(orig pat), zImage(orig pat), grub_cksum.syno
cat grub_cksum.syno
/zImage Encrypted: 34299503 /rd.gz Encrypted: df5b31a3
Run it on ESXi 7
yum install qemu-img # On Centos 7
qemu-img convert -O vmdk redpill.img boot.tmp
file boot.tmp
boot.tmp: VMware4 disk image
# boot.vmdk boot-flat.vmdk
vmkfstools -i boot.tmp -d thin boot.vmdk # Run vmkfstools on ESXi
在 DiskStation mount synoboot1 fail
mkdir /mnt/p1 /mnt/p2
mount -t vfat /dev/synoboot1 /mnt/p1
mount: mounting /dev/synoboot1 on /mnt/p1 failed: Invalid argument
[Fix]
cd /dev
mount -t vfat synoboot1 /mnt/p1
mount -t ext2 synoboot2 /mnt/p2
boot-wait.sh
boot msg
Running "boot-wait.sh" for thethorgroup.boot-wait->on_boot [ 3.958069] usb 1-1: new full-speed USB device number 2 using uhci_hcd Still waiting for boot device (waited 1 of 30 seconds) Still waiting for boot device (waited 2 of 30 seconds) Still waiting for boot device (waited 3 of 30 seconds) ...
Troubleshoot
找到 HDD 但 Install fail
# 6.2.4 HDD 要有 5G 先安裝成功,
tail -f /var/log/messages
... raidtool: partition_create.c:178 Failed to [/sbin/sfdisk -N2 -uS -q -f -j0 -z4194304 -tfd -F /dev/sdg], err=255 ... raidtool: raidtool.c:665 Failed to create system partition of /dev/sdg, newlayout=8, errno=0x2000 ... raidtool: raidtool.c:709 No disk to create system and swap partition, initsys fail!
* 用 virtio 安裝會找不到 HDD, 因為 sda -> vda
安 DSM 時出 Error
Failed to install the file. The file is probably corrupted. (13)
在 bootloader 選 'RedPill DS3615xs v6.2.4-25556 (SATA, Verbose)'
Solution to fix update fail from 6.2.4 to 6.2.4-2
cat /var/log/junior_reason
Exit on error [7] root not matched with junior...
cat /var/log/messages
... findhostd: ninstaller.c:224 Mount partion /dev/md0 /tmpRoot ... findhostd: ninstaller.c:967 Executing /tmpRoot//.syno/patch/updater -a /tmpRoot [255] ... findhostd: ninstaller.c:969 Recover patch is not available.
1. login the console with root (without password)
2. mount /dev/md0 /mnt
3. rm -rf /mnt/.syno
Select "Migration: Keep my data and most of the settings"
Install original pat (DSM_DS3615xs_25556.pat) # 271 MB