InstallingDebianOn/Synology

Documentation for Debian on ARM based Synology devices:

Manual installation on Synology DS218j (you need a TTL UART for serial console access) Some LEDs do not work as expected but over all functional. Debian arm kernel has LED power off issue after shutdown. You may use custom kernel with patch to resolve this.

Prepare HDD (SSD might not work and hangup during openssh-server startup due to low entropy).

Zero out the first 50MiB of the HDD.

Warning: it will remove all partitions information.

# dd if=/dev/zero of=/dev/sdx bs=1MiB count=50

create partition (with space infront; we need it for raw booting. First sector:102400)

# fdisk /dev/sdx
Command (m for help): g
Created a new GPT disklabel (GUID: ...).
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-62533262, default 2048): 102400
Last sector, +/-sectors or +/-size{K,M,G,T,P} (102400-62533262, default 62533262):
Created a new partition 1 of type 'Linux filesystem' and of size 29.8 GiB.
Command (m for help): w
The partition table has been altered.

create file system

# mkfs.ext3 -L rootfs /dev/sdx1

note: please set level "rootfs" which will be used later to boot.

Check doozan forum if you want to use ext4 here. I did not test ext4.

Install base system.

# debootstrap --foreign --arch=armhf testing ~/armhf-chroot/ http://deb.debian.org/debian/
# chroot ~/armhf-chroot/ /debootstrap/debootstrap --second-stage

mount the partition example: /mnt/armhf and copy base system /mnt/armhf

# mount -o bind /dev /mnt/armhf/dev/
# mount -o bind /proc /mnt/armhf/proc/
# mount -o bind /sys /mnt/armhf/sys

chroot

# chroot /mnt/armhf/

edit /etc/fstab

LABEL=rootfs    /               ext3    noatime,errors=remount-ro 0 1
tmpfs          /tmp            tmpfs   defaults          0       0

/etc/network/interface

auto lo eth0
iface lo inet loopback
iface eth0 inet dhcp

set account and password

# passwd
...
# adduser YOUR_USERNAME

install opnessh

# apt-get update
# apt-get install openssh-server

Install kernel

# apt-get install linux-image-armmp

important to get device tree you can get pre-build dtb from kernel 5.2 from the tarbal linux-5.12.6-mvebu-tld-1-bodhi.tar.bz2 at doozan forum or compile yourself.

cd /boot
cp vmlinuz-5.10.0-7-armmp zImage.fdt 
cat dts/armada-385-synology-rs816.dtb  >> zImage.fdt

generate uImage and uInitrd for booting

# apt-get install u-boot-tools
# mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n linux-image-5.10.7-armmp-1 -d zImage.fdt uImage
# mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initramfs-5.10.7-armmp-1 -d initrd.img-5.10.0-7-armmp uInitrd

write uImage and uInitrd in raw HDD sectors

# dd if=uImage of=/dev/sdx bs=1MiB seek=10
# dd if=uInitrd of=/dev/sdx bs=1MiB seek=20
# sync

umount all bind partions /dev /proc /dev after exit from chroot attach HDD to Synology

connect TTL UART Pin configuration on board:

2-GND, 4-TX, 6-RX

connect these pins from your usb TTL UART:

2-GND, 4-RXD, 6-TXD

connect

# screen /dev/ttyUSB1 115200

test boot by interrupting u-boot via ctrl+c

setenv load_image_addr 0x02000000
setenv load_initrd_addr 0x3000000
setenv load_image 'echo loading uImage from raw HDD ...; scsi device 0; scsi read $load_image_addr 0x5000 0x2F00'
setenv load_initrd 'echo loading uInitrd from raw HDD ...; scsi device 0; scsi read $load_initrd_addr 0xA000 0xAF00'
setenv set_bootargs 'setenv bootargs "console=ttyS0,115200 root=LABEL=rootfs rootdelay=10 $mtdparts earlyprintk=serial"'
setenv bootcmd_exec 'echo Booting Debian ...; run set_bootargs; setenv fdt_skip_update yes; setenv initrd_high 0xffffffff; run load_image; run load_initrd; bootm $load_image_addr $load_initrd_addr'
setenv bootcmd 'scsi init; run bootcmd_exec; echo Booting Stock OS ...; run bootspi'

in original document 0x4F00 replaced with 0xAF00 because uInitrd size is bigger.

For Synology DS218j replace bootcmd environment variable and use the following instead

setenv bootcmd 'mw.l f1018100 00008000; scsi init; run bootcmd_exec; echo Booting Stock OS ...; run bootspi'

boot

boot

if everything is working fine you may make this boot permanent. first print and backup your old bootcmd

printenv bootcmd
setenv bootcmd2 'YOUR PRINTED bootcmd STRING GOES HERE'

set all the previous setenv and save

saveenv
reset

Now your system should boot.

Install kernel from source. (tested linux-5.13.4) get kernel patch from linux-5.12.6-mvebu-tld-1.patch

$ cd linux-5.13.4
$ patch -p1 < ../linux-5.12.6-mvebu-tld-1.patch

configure kernel

$ cp ../config-5.12.6-mvebu-tld-1 .config
$ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- menuconfig

The config file config-5.12.6-mvebu-tld-1 has local version as

CONFIG_LOCALVERSION="-mvebu-tld-1"

Please change it accordingly to custom kernel naming conversion or your choice.

build kernel

$ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- bindeb-pkg

You will have the following packages

linux-headers-5.13.4_*.deb
linux-image-5.13.4_*.deb
linux-libc-dev_5.13.4-*.deb