Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
338 lines (239 sloc) 9.17 KB
***************************************************
USE THE "vars.txt" commands to prepare the environment variables we will use.
***************************************************
##################################################
# Introduction
##################################################
The new kernel will need a rootfs to bootstrap.
For the HDD and USB version, I chose a standard Debian 7 installation, with minimal packages.
For the NAND version, the packages selection is smaller and I used EMDEBIAN to reduce to the bone the size.
I used multistrap (as opposed to debootstrap) because it's the preferred way for EMDEBIAN.
While doing tests, I used a local caching proxy (squid), to avoid downloading again and again.
For 2-nd stage part, I used QEMU emulation (On Debian, the needed package is qemu-user-static).
##################################################
# MULTISTRAP config file
##################################################
mkdir -p $RFSnandPATH
cd $RFSnandPATH
# multistrap-nand.conf
####################################################################################
cat <<END > $RFSnandCFG
[General]
arch=armel
noauth=true
unpack=true
debootstrap=grip3-updates grip3 wheezy
aptsources=grip3-updates grip3 wheezy
cleanup=true
[grip3]
packages=udev kmod mtd-utils evtest
packages=apt
packages=netbase net-tools ifupdown pump iputils-ping
packages=dropbear
packages=vim-tiny mc htop less usbutils bash-completion screen ntpdate parted
source=http://www.emdebian.org/grip
keyring=emdebian-archive-keyring
components=main
suite=wheezy-grip
omitdebsrc=true
[grip3-updates]
source=http://www.emdebian.org/grip
suite=wheezy-proposed-updates-grip
keyring=emdebian-archive-keyring
components=main
omitdebsrc=true
[wheezy]
packages=u-boot-tools esekeyd gdisk
source=http://ftp.it.debian.org/debian
suite=wheezy
omitdebsrc=true
END
####################################################################################
# prepare multistrap-nand
multistrap -d $RFSnand -f $RFSnandCFG
# Get DNS-NAS-utils package from Jamie Lentin
wget -O $RFSnandPATH/dns-nas-utils.deb https://github.com/lentinj/dns-nas-utils/blob/master/dns-nas-utils.deb?raw=true
cp $RFSnandPATH/dns-nas-utils.deb $RFSnand/tmp/dns-nas-utils.deb
##################################################
# MULTISTRAP 2-nd STAGE
##################################################
This will fake-mount some volumes before entering chroot and umount at exit.
if [ -d $RFSnand ]; then
cp /usr/bin/qemu-arm-static $RFSnand/usr/bin/
mount -t proc proc $RFSnand/proc && mkdir ${RFSnand}/dev/pts ; mount -t devpts devpts $RFSnand/dev/pts && chroot $RFSnand ; umount $RFSnand/proc ; umount $RFSnand/dev/pts ; rmdir $RFSnand/dev/pts
rm -f $RFSnand/usr/bin/qemu-arm-static
fi
########################################################
!!! NOW IN QEMU-emulated ARM CHROOT ENVIRONMENT !!!
If you need to preconfigure a package: echo "packagename name/question type value" | debconf-set-selections
########################################################
# See the magic:
uname -m
# Preconfigures locale/lang for setup
export LC_ALL=C LANGUAGE=C LANG=C
echo LANG=C > /etc/default/locale
# Fixup Preinstall DASH
/var/lib/dpkg/info/dash.preinst install
# Fake presence of OpenSSH so Dropbear will not start in chroot
touch /usr/sbin/sshd
chmod +x /usr/sbin/sshd
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg --configure -a
## Enable Dropbear at startup and make it default ssh client
sed --in-place -e 's/^NO_START=1/NO_START=0/' /etc/default/dropbear
update-alternatives --install /usr/bin/ssh ssh /usr/bin/dbclient 1
update-alternatives --set ssh /usr/bin/dbclient
# remove the fake sshd binary
rm -f /usr/sbin/sshd
## Choose your TimeZone
dpkg-reconfigure -plow tzdata
## Choose your locale
dpkg-reconfigure locales
## Set a root password
passwd
## Get rid of some unused packages
apt-get -y purge initramfs-tools mountall plymouth
## Install dns-nas-utils.deb from Jamie Lentin
dpkg -i /tmp/dns-nas-utils.deb
service fan-daemon stop
rm /tmp/dns-nas-utils.deb
## Ensure a serial console device
mknod /dev/ttyS0 c 4 64
## Optionally configure Midnight commander (I like Internal Editor as default)
mc
exit
#################################
## -> EXIT CHROOT - post-config:
#################################
rm -f > $RFSnand/root/.bash_history
NASHOSTNAMESHORT=$(echo $NASHOSTNAME | cut -d. -f1)
NASDOMAIN=$(echo $NASHOSTNAME | cut -d. -f2-)
cat <<END > $RFSnand/etc/hostname
$NASHOSTNAMESHORT
END
cat <<END > $RFSnand/etc/hosts
127.0.0.1 localhost
127.0.1.1 $NASHOSTNAME $NASHOSTNAMESHORT
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
END
cat <<END > $RFSnand/etc/resolv.conf
domain $NASDOMAIN
search $NASDOMAIN
nameserver 8.8.8.8
nameserver 8.8.4.4
END
cat <<END > $RFSnand/etc/network/interfaces
# Loopback
auto lo
iface lo inet loopback
# Ethernet
auto eth0
iface eth0 inet static
address $NASIP
netmask 255.255.255.0
gateway $NASGW
dns-nameservers 8.8.8.8 8.8.4.4
hwaddress ether $NASMAC
END
# Set up APT preferences to limit package install
cat <<END > $RFSnand/etc/apt/apt.conf.d/99-norecommends-nosuggests
APT::Install-Recommends "0";
APT::Install-Suggests "0";
END
# Disable standard ttys
sed -i -r -e 's/^(.:23.*:respawn:\/sbin\/getty 38400 tty.*)/#\1/' $RFSnand/etc/inittab
# Enable Serial Console
cat <<END >> $RFSnand/etc/inittab
T0:2345:respawn:/sbin/getty -L ttyS0 115200 linux
END
cat <<END > $RFSnand/etc/fstab
/dev/root / auto defaults,noatime,errors=remount-ro 0 0
tmpfs /tmp tmpfs defaults 0 0
#LABEL=uboot-boot /boot auto ro,nodev,nosuid,noexec,noatime,errors=remount-ro 0 0
#UUID=ece46cea-fafe-478e-a995-6e57ef7a1738 none swap sw 0 0
END
cat <<END > $RFSnand/etc/profile.d/z-custom-aliases.sh
if [ "\$BASH" ]; then
export LS_OPTIONS='--color=auto'
eval "\`dircolors\`"
alias ls='ls \$LS_OPTIONS'
alias ll='ls \$LS_OPTIONS -l'
alias l='ls \$LS_OPTIONS -la'
fi
END
cat <<END > $RFSnand/etc/profile.d/z-vim.sh
alias vi=vim.tiny
END
# Configuration for fw_printenv / fw_setenv
cat <<END > $RFSnand/etc/fw_env.config
#/dev/mtd0 0x00000000-0x00100000 : "u-boot"
#/dev/mtd1 0x00100000-0x00600000 : "uImage"
#/dev/mtd2 0x00600000-0x00b00000 : "ramdisk"
#/dev/mtd3 0x00b00000-0x07100000 : "image"
#/dev/mtd4 0x07100000-0x07b00000 : "mini firmware"
#/dev/mtd5 0x07b00000-0x08000000 : "config"
# MTD device name Device offset Env. size Flash sector size Number of sectors
/dev/mtd0 0xE0000 0x20000 0x20000
END
# Use a tmpfs for /tmp
sed -i 's/^#*\(RAMTMP\)=.*$/\1=yes/' $RFSnand/etc/default/tmpfs
[ ! -e $RFSnand/etc/mtab ] || rm $RFSnand/etc/mtab
ln -s /proc/mounts $RFSnand/etc/mtab
[ ! -e $RFSnand/etc/blkid.tab ] || rm $RFSnand/etc/blkid.tab
ln -s /dev/null $RFSnand/etc/blkid.tab
# Overwrite dns_temp with updated version (for DNS325 only)
cp dns_temp $RFSnand/usr/bin/dns_temp
# Overwrite fan-daemon with updated version (fan device changed path in recent kernels)
# fan_device=$(find /sys/devices -name fan1_target)
#
cp fan-daemon $RFSnand/usr/sbin/fan-daemon
## Set up EseKeyD to control NAS buttons
sed --in-place -e 's/^START_ESEKEYD=false/START_ESEKEYD=true/' $RFSnand/etc/default/esekeyd
cat <<END > $RFSnand/etc/esekeyd.conf
POWER:/sbin/shutdown -h now
RESTART:/sbin/halt -f -p
EJECTCD:/usr/local/sbin/button-usbcopy
END
cat <<END > $RFSnand/usr/local/sbin/button-usbcopy
#!/bin/sh
# Sample script to show buttons customization and LED functionality
# Substitute with what you want, for ex.: WiFi on/off
curr_bright=\$(cat /sys/class/leds/dns325:white:power/brightness)
if [ \$curr_bright = 255 ]; then
new_bright="0"
else
new_bright="255"
fi
echo \$new_bright > /sys/class/leds/dns325:white:power/brightness
END
chmod +x $RFSnand/usr/local/sbin/button-usbcopy
## free up some more space
find $RFSnand/usr/share/doc/ -type f -name "*" -delete
find $RFSnand/etc/ -name "*~" -delete
find $RFSnand/var/cache/debconf/ -name "*-old" -delete
find $RFSnand/var/lib/dpkg/ -name "*-old" -delete
:> $RFSnand/var/log/dpkg.log
:> $RFSnand/var/log/alternatives.log
# Fix a strange error in hwclock (seems http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=699554)
cat <<END > $RFSnand/etc/adjtime
0.0 0 0.0
0
UTC
END
## Fix a strange error with overlayfs:
cp rc.local $RFSnand/etc/
##################################################
# INITRAMS
##################################################
See initramfs.txt for uInitramfs creation, then:
cp $NASINITRAMFS/uInitramfs $RFSnand/boot/uInitramfs
If you want to exclude OverlayFS, you can just create empty file:
touch $RFSnand/disable-root-ro
#######################################################################################################################
## Credits:
## http://free-electrons.com/blog/embdebian-with-multistrap/
## http://jamie.lentin.co.uk/devices/dlink-dns325/userland-configuration/
#######################################################################################################################
You can’t perform that action at this time.