HanG321 Blog

Debian chroot on DSM 5.2

similar to previous blog: https://www.hang321.net/2014/08/16/debian-chroot-on-dsm/

Prerequisite:

add custom source:  Package Centre > Settings > Package Sources > add

Name: SynoCommunity
Location:  https://packages.synocommunity.com/

Installation:

– select Debian Chroot and click install

– select yes to install python (SynoCommunity version) as well.

– after installation completed, ssh to DSM as root

root@diskstation> /var/packages/debian-chroot/scripts/start-stop-status chroot
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.utf8)
root@diskstation:/#

– now under chroot

##backup and update source list. e.g. from France to Australia
##see https://www.debian.org/mirror/list
sed -i.`date +%Y%m%d` 's/fr.debian.org/au.debian.org/g' /etc/apt/sources.list
aptitude update
aptitude upgrade
aptitude install locales
dpkg-reconfigure locales
dpkg-reconfigure tzdata
# optional: packages to install
aptitude install less vim curl rsync screen openssh-server bash-completion

– enable home for users: Control Panel > User > Advance, “Enable user home services”, Apply.
ls -al /var/services/homes  symbolic link updated and pointed correctly

– some additional directories want to be mount by startup script

diff -u /var/packages/debian-chroot/scripts/start-stop-status.org /var/packages/debian-chroot/scripts/start-stop-status
--- /var/packages/debian-chroot/scripts/start-stop-status.org
+++ /var/packages/debian-chroot/scripts/start-stop-status
@@ -19,6 +19,7 @@
grep -q "${CHROOTTARGET}/sys " /proc/mounts || mount -t sysfs sys ${CHROOTTARGET}/sys
grep -q "${CHROOTTARGET}/dev " /proc/mounts || mount -o bind /dev ${CHROOTTARGET}/dev
grep -q "${CHROOTTARGET}/dev/pts " /proc/mounts || mount -o bind /dev/pts ${CHROOTTARGET}/dev/pts
+ grep -q "${CHROOTTARGET}/home " `realpath /var/services/homes` || mount -o bind `realpath /var/services/homes` ${CHROOTTARGET}/home

# Start all services
${INSTALL_DIR}/app/start.py
@@ -35,6 +36,7 @@
umount ${CHROOTTARGET}/dev
umount ${CHROOTTARGET}/sys
umount ${CHROOTTARGET}/proc
+ umount ${CHROOTTARGET}/home
}

daemon_status ()

– setup users on debian domain

## find user id
id -u username
id -g username

## Debian domain. XXXX YYYY is the id value
adduser username -uid XXXX --gid YYYY --home /home/username

– change Port form 22 to 2222, so Synology still using default port 22, Debian domain will use 2222 port

cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +%Y%m%d`
vim /etc/ssh/sshd_config

 

– config profile

#on Debian domain
# enable color for ls and PS1
vim /etc/profile.d/S01_allusers.sh
  export LS_OPTIONS='--color=auto'
  eval "`dircolors`"
  alias ls='ls $LS_OPTIONS'
  alias ll='ls $LS_OPTIONS -la'
  alias l='ls $LS_OPTIONS -lA'

  if [ "$BASH" ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
    if [ -f ~/.bashrc ]; then
      . ~/.bashrc
    fi
  fi
  #EOF

source /etc/profile && source /root/.profile

– ~/.profile  , different PS1 for both Synology and Debian ssh login

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

if [ ! -r /etc/debian_chroot ]; then
  PS1='\u@\h \W \$ '
fi

– (optional) on Synology domain, edit /etc/profile as well: PS1=’\u@\h \W \$ ‘

Final

– ssh username@diskstation   for original synology ash shell. Or
– ssh -p 2222 username@diskstation  for debian bash shell

 

Exit mobile version