Difference between revisions of "Debian Lenny on LS-WXL"

From NAS-Central Buffalo - The Linkstation Wiki
Jump to: navigation, search
(Native compilation: added warning for patch)
(Cross compilation)
Line 551: Line 551:
  cd linux-2.6-2.6.32
  cd linux-2.6-2.6.32
  make -f debian/rules.gen source_armel_none
  make -f debian/rules.gen source_armel_none
apply the necesary patches, but review them before you apply them, as the kernel patches changes every week
patch -Np1 -i ~/patch.lswxl
  cd debian/build/source_armel_none/
  cd debian/build/source_armel_none/
  patch -Np1 -i ../../../../patch.lswxl
  patch -Np1 -i ../../../../patch.lswxl

Revision as of 21:57, 8 March 2011

This guide will explain how to install Debian GNU/Linux "Lenny" on the LinkStation™ Duo LS-WXL using the Debian "debootstrap" procedure. The original kernel will be preserved, as well as the original bootloader (U-Boot).

Basic idea:

  • create a Debian system with debootstrap
  • use the data partition as a temporary root
  • replace the old filesystem with the new one

This guide will ask you to reformat partitions, delete existing data, etc. All of these actions may void your warranty, destroy your data, etc. In general you can receive help from the community or from the Buffalo forums but bear in mind that every problem you may encounter is ultimately up to you to solve. You do it at your own risk.

This guide is based on the procedure for installing Debian on LS-CHLv2 and was developed using the LS-WXL/E version. This guide should also work for the LS-WXL/R1 variants.

This guide suggests to install blstools, a small set of utilities developed for this hardware to enable some operations which would not be possible from a plain Debian install:

  • turn the unit off from the on-off-auto switch
  • turn unit blinking LEDs to still blue when boot is complete
  • resume blinking when the unit is shutting down
  • use the USB port

Please note that the Armel Debian "micro_evtd" package will NOT work on LS-WXL because of different hardware.


Preliminary steps

Obtain root access to the linkstation

You are supposed to start from an "open" Stock Firmware, that is stock software that you can telnet to,

Follow this guide to get telnet root console access to the LS.

Follow this guide to SSH as root to the LS.

Backup the LS

If you have any important data on the LS you definitely need to make a backup.

Even if you don't, you'd better take a snapshot of the vital disk partitions (first and second partition). So you will be able to easily revert to the original stock distribution. [forum post] explains how to do it.

Prepare a Debian Lenny root filesystem


This is derived from original debootstrap docs.

From the linkstation console download the Debian debootstrap utility and install it with dpkg:

wget http://ftp.us.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.10lenny1_all.deb
dpkg -i debootstrap_1.0.10lenny1_all.deb

dpkg will complain of missing dependencies. Ignore it.

Note that for firmware 1.22 (and possibly others) Busybox isn't linked to ar so the debootstrap step below will fail.

which ar >/dev/null || ln -s /bin/busybox /usr/bin/ar  # fix ar link

mkdir debian-armel-rootfs
debootstrap --verbose --arch armel lenny debian-armel-rootfs http://ftp.us.debian.org/debian

This step WILL take time. At the end you should get the following message:

I: Base system installed successfully.

Completing the debootstrap and preparing the rootfs

Most commands will be run in the chrooted environment of the newly created Debian Lenny install. In order to enter the chroot type

LANG=C chroot debian-armel-rootfs/ /bin/bash

to leave type exit.

Copy kernel modules from stock kernel

Kernel modules reside in /lib/modules/<kernel version>. Here we are using the stock kernel so we must copy them from the stock initrd to the new rootfs. This must be done from within a chrooted environment in the new system - won't work with stock software.

cp /boot/initrd.buffalo debian-armel-rootfs/tmp/
LANG=C chroot debian-armel-rootfs/ /bin/bash
cd /tmp
dd if=initrd.buffalo of=initrd.gz ibs=64 skip=1
gunzip initrd.gz
mkdir INITRD
mount -t ext2 -o loop initrd INITRD 
cp -R INITRD/lib/modules/* /lib/modules/
umount INITRD
rmdir INITRD
rm initrd*

Adding missing devices

Still in the chrooted environment.

Mount the proc filesystem - it can be mounted a number of times - and run the command to create device nodes in /dev (TODO: investigate dynamic devices with udev?):

mount -t proc proc /proc
cd /dev
MAKEDEV generic
umount /proc

This will also take some time while all device nodes are created.

Apt setup

Apt will complain about packages without verification if this step is not performed.

Edit /etc/apt/sources.list, use the appropriate debian mirror

# Debian packages for lenny
deb http://ftp.us.debian.org/debian lenny main
# Uncomment the deb-src line if you want 'apt-get source'
# to work with most packages.
# deb-src http://ftp.us.debian.org/debian lenny main

deb http://security.debian.org/ lenny/updates main contrib
# deb-src http://security.debian.org/ lenny/updates main contrib

deb http://volatile.debian.org/debian-volatile lenny/volatile main contrib
# deb-src http://volatile.debian.org/debian-volatile lenny/volatile main contrib

Perform an update

apt-get update

The final upgrade step can be performed later once the installation is finished.

Install mdadm

ln -s /sbin/MAKEDEV /dev     # mdadm install expects to see this
apt-get --no-install-recommends install mdadm

Ignore the "(failed to load MD subsystem)" error.

Update mdadm.conf:

exit                                                # exit from chroot
cp /etc/mdadm.conf debian-armel-rootfs/etc/mdadm/
LANG=C chroot debian-armel-rootfs/ /bin/bash        # back again

Configuring locale

Install and configure the locales. Suggestion is to install at least the en_US.UTF-8 and your native language locale (e.g. it_IT.UTF-8, de_DE.UTF-8, etc).

apt-get install locales
dpkg-reconfigure locales

Editing /etc/fstab

Create /etc/fstab:

cat >/etc/fstab <<EOF
# /etc/fstab: static file system information.
# file system	mount point	type	options			dump pass
/dev/md2	/		xfs	defaults,noatime	0    1
/dev/md0	/boot		ext3	rw,nosuid,nodev		0    2
/dev/md10	none		swap	sw			0    0
proc		/proc		proc	defaults		0    0

Partition /dev/md2 contains the shared directory which will be used as a temporary root before the final installation. Make sure that a backup of this partition is made if it contains important data.

If the LS has only a single drive attached, change /dev/md2 to either /dev/sda6 or /dev/sdb6 depending on which slot the drive is inserted.


Edit /etc/network/interfaces to match your LAN configuration. My LS gets all information from DHCP:

# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.

# We always want the loopback interface.
auto lo
iface lo inet loopback
# DHCP for Ethernet connection 
auto eth1
iface eth1 inet dhcp
# Example static IP setup: (broadcast and gateway are optional)
# auto eth1
# iface eth1 inet static
#     address
#     network
#     netmask
#     broadcast
#     gateway

Create /etc/hosts

cat >/etc/hosts <<EOF  localhost.localdomain localhost

Create /etc/hostname:

cat >/etc/hostname <<EOF
<your hostname>

Replace <your hostname> with a sensible name.

Install SSHD

apt-get install openssh-server
passwd root

Edit /etc/ssh/sshd_config and make sure that the following line is present and uncommented:

PermitRootLogin yes

Prepare the rootfs archive

Clean up the installation, leave the chrooted environment and tar it up:

aptitude clean
tar zcvf lenny-armel-rootfs.tgz -C debian-armel-rootfs .

Now you have a complete rootfs for Debian Lenny armel.


We will reuse the existing root partition to store the debian rootfs. The data partition will be used as a temporary root so that this installation will be performed right on the LS itself. It is necessary to have a backup of the data partition if it contains important stuff.

If you want to change the RAID type for the data partition, it is better to use the web interface before switching to the full Debian setup.

Create an initrd

An initrd is necessary to boot debian using a raid partition.

We need busybox to create a minimal initrd. Note that we need to go back to the chrooted environment.

chroot debian-armel-rootfs/ /bin/bash
apt-get install busybox

Install uboot files:

apt-get install uboot-mkimage

Create and mount an ext2 image file:

cd /tmp
dd if=/dev/zero of=initrd bs=1k count=0 seek=3K
mke2fs -F -m 0 -b 1024 initrd
tune2fs -c0 -i0 initrd
mkdir INITRD
mount -o loop initrd INITRD

Create directory structure and the device nodes:

mkdir -p INITRD/{bin,lib,dev,etc/mdadm,proc,sbin}
cp -a /dev/{null,console,tty,sd{a,b,c,d}?,md*} INITRD/dev/

Copy busybox, mdadm and their dependencies:

cp /bin/busybox INITRD/bin/
cp /sbin/mdadm INITRD/sbin
cp /lib/{libm.so.6,libc.so.6,libgcc_s.so.1,ld-linux.so.3} INITRD/lib

The dependencies can be determined using the commands:

ldd /bin/busybox
ldd /sbin/mdadm

Create a linuxrc:

cat > INITRD/linuxrc <<EOF
#!/bin/busybox sh

# Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys

echo 'DEVICE /dev/sd??*' > /etc/mdadm/mdadm.conf
mdadm -Eb /dev/sd??* >> /etc/mdadm/mdadm.conf
mdadm -As --force

# use /dev/md1 as root
# echo "0x901" > /proc/sys/kernel/real-root-dev
# use /dev/md2 as root
echo "0x902" > /proc/sys/kernel/real-root-dev
# use /dev/sda6 as root
# echo "0x806" > /proc/sys/kernel/real-root-dev
# use /dev/sdb6 as root
# echo "0x822" > /proc/sys/kernel/real-root-dev

# Clean up.
umount /proc
umount /sys
chmod +x INITRD/linuxrc

Uncomment the relevant line if you use a different temporary root partition.

Generate an initrd for temporary root partition:

umount INITRD
gzip initrd
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n initrd -d initrd.gz initrd.buffalo

Next we need to create another initrd for the final installation:

gunzip initrd.gz
mount -o loop initrd INITRD

Edit linuxrc to use /dev/MD1 as root:

# use /dev/md1 as root
echo "0x901" > /proc/sys/kernel/real-root-dev

Or change it to whatever partition you may want later.

umount INITRD
gzip initrd
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n initrd -d initrd.gz initrd.buffalo.final
rmdir INITRD

Copy initrd:

mv /boot/initrd.buffalo /boot/initrd.buffalo.old
cp debian-armel-rootfs/tmp/initrd.buffalo* /boot/

Installing the Debian rootfs

This will be a two step process. We first boot debian using a temporary rootfs and then transfer it to it final partition.

If you are using two hard disks, /dev/md2 will be the temporary partition and /dev/md1 will be the final destination. If you are using a single drive, then /dev/sda6 or /dev/sdb6 will be the temporary partition.

Install rootfs in temporary partition

Untar the rootfs and copy the backup:

tar xvzf lenny-armel-rootfs.tgz -C /mnt/array1/
cp lenny-armel-rootfs.tgz /mnt/array1/

Use /mnt/disk1 or /mnt/disk2 instead of /mnt/array1 if you are using a single drive.

Reboot and pray that it works. :)


After rebooting, login to the new system.

Install rootfs in /dev/md1

Format /dev/md1, use whatever filesystem that you prefer:

mkfs.ext3 /dev/md1
tune2fs -c0 -i0 /dev/md1

Mount it under /mnt and extract the rootfs:

mount /dev/md1 /mnt
tar xvzf /lenny-armel-rootfs.tgz -C /mnt
cp /lenny-armel-rootfs.tgz /mnt/root           # make a copy

Edit /mnt/etc/fstab to reflect the changes:

# /etc/fstab: static file system information.
# file system	mount point	type	options			dump pass
/dev/md1	/		ext3	defaults,noatime	0    1
/dev/md0	/boot		ext3	ro,nosuid,nodev		0    2
/dev/md10	none		swap	sw			0    0
proc		/proc		proc	defaults		0    0

Use the correct initrd:

cd /boot
mv initrd.buffalo initrd.buffalo.initial
cp initrd.buffalo.final initrd.buffalo

Note: make sure the /boot is mounted! You may have to manually mount it to complete the above step.

Reboot and pray that it works. :)


Post-installation setup

Setup data partition

The existing data partition can be mounted on the home directory as-is without formatting but the rootfs files must be manually deleted.

The other approach is to start clean and format it. Note that the EXT3 was chosen as the filesystem for the data partition.

Replace /dev/md2 with either /dev/sda6 or /dev/sdb6 if you are using a single drive.


mkfs.ext3 -m0 /dev/md2
tune2fs -c0 -i0 /dev/md2

Update /etc/fstab:

# /etc/fstab: static file system information.
# file system	mount point	type	options			dump pass
/dev/md1	/		ext3	defaults,noatime	0    1
/dev/md2	/home		ext3	defaults,noatime	0    2
/dev/md0	/boot		ext3	ro,nosuid,nodev		0    2
/dev/md10	none		swap	sw			0    0
proc		/proc		proc	defaults		0    0

Mount /home

mount /home

Add user

Issue the following command

 adduser <username>

Configuring timezone

dpkg-reconfigure tzdata

Useful packages

Anyone would need these:

apt-get install sudo less usbutils bzip2 mc linuxlogo psmisc


Ntpd ensures that your Linkstation clock stays in sync with global time servers.

apt-get install ntp


As told above, blstools are a set of utilities which enable LS-CHL/XHL/WXL hardware-specific features otherwise unavailable from a plain Debian Lenny installation.

In order to install the latest blstools, smartmontools is required:

apt-get install smartmontools

Download the package from the blstools project page

wget http://downloads.sourceforge.net/project/blstools/releases/blstools-0.2.0.tar.gz
tar zxf blstools-0.2.0.tar.gz
cd blstools-0.2.0
/etc/init.d/lsmonitor start

The following features are installed:

lsmonitor (/etc/init.d/lsmonitor)

This is a daemon that is automatically started when the system boots. You don't need to call it directly.

lsmonitor stops the blue led from flashing and provides a reassuring, still blue light. Also, when you move the switch in "off" position lsmonitor initiates system shutdown (which is nice isn't it?)

usb (/etc/init.d/usb)

Powers on and off the USB interface.

When you want to connect a USB disk to the Linkstation you should first call:

sudo /etc/init.d/usb start

and then you will be able to mount the USB drive to the desired location (generally, the device will be /dev/sdb1). Once done, in order to save power you can unmount the mounted volume and issue:

sudo /etc/init.d/usb stop

to disable the USB device.

NFS kernel

Note: Some export problems were encountered using this kernel. Compiling a Debian kernel is the preferred approach.

The kernel provided on this page can also be used for LS-WXL.

Download and extract kernel and modules:

wget http://downloads.buffalo.nas-central.org/Users/kenatonline/NFSKernel/nfs-kernel-feroceon-kw.tgz
tar xzf nfs-kernel-feroceon-kw.tgz boot lib

Install and reboot:

mount -o remount,rw /boot
mv /boot/uImage.buffalo /boot/uImage.buffalo.old
cp boot/uImage.buffalo /boot/
cp -a lib/modules/ /lib/modules/

Install nfs

apt-get install nfs-kernel-server nfs-common portmap

Check if server is running:

/etc/init.d/nfs-kernel-server status


wget http://prdownloads.sourceforge.net/webadmin/webmin_1.510-2_all.deb
apt-get install libnet-ssleay-perl openssl libauthen-pam-perl libio-pty-perl apt-show-versions libapt-pkg-perl
dpkg -i webmin_1.510-2_all.deb

For more information, please refers to Webmin to remotely administer your LinkStation

Building the Debian kernel

Caution: Make sure that you have physical access to the drives and a linux box just in case you messed up with the the kernel configuration. At the moment, there is no known way of gaining root access when the device is in EM mode.

The kernel can be natively compiled or cross compiled using an external Debian PC.


Install the following packages under root:

apt-get install build-essential fakeroot uboot-mkimage debhelper python libncurses5-dev

Update /etc/apt/sources.list to be able to download the Squeeze kernel sources:

echo deb-src http://ftp.us.debian.org/debian squeeze main >> /etc/apt/sources.list
apt-get update

Install the kernel sources (this command can be run as a normal user)

apt-get -t squeeze source linux-2.6

Download the patch and sample config file (for linux-2.6-2.6.32-30):

wget http://pastebin.com/download.php?i=vFRr3zAX -O patch.lswxl
wget http://pastebin.com/download.php?i=2R6sJ0ZX -O config.lswxl

Native compilation

cd linux-2.6-2.6.32
make -f debian/rules source
cd debian/build/source_armel_none/

apply the necesary patches, but review them before you apply them, as the kernel patches changes every week

patch -Np1 -i ~/patch.lswxl
cp ~/config.lswxl .config
make uImage modules
cp arch/arm/boot/uImage uImage.buffalo.debian
make modules_install INSTALL_MOD_PATH=./modules

On my LS, the compilation took around 1.5 hrs.

Cross compilation

cd linux-2.6-2.6.32
make -f debian/rules.gen source_armel_none

apply the necesary patches, but review them before you apply them, as the kernel patches changes every week

patch -Np1 -i ~/patch.lswxl
cd debian/build/source_armel_none/
patch -Np1 -i ../../../../patch.lswxl
cp ../../../../config.lswxl .config
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage modules
mv arch/arm/boot/uImage uImage.buffalo.debian
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules_install INSTALL_MOD_PATH=./modules


Get yourself root access, and get write access to the boot fs

mount -o remount,rw /boot

If blstools is installed, this program must first be disabled or removed. Otherwise, the system will just automatically reboot.

chmod a-x /etc/init.d/lsmonitor

Copy the kernel to the boot directory, create a backup of the old version:

mv /boot/uImage.buffalo /boot/uImage.buffalo.old
cp uImage.buffalo.debian /boot/uImage.buffalo

Copy the modules:

cp -a modules/lib/modules/2.6.32 /lib/modules

make the correct realtime clock device, with this kernel settings it is:

mknod /dev/rtc c 254 0

Reboot and enjoy your new kernel.

blstools Replacement

This is the replacement lsmonitor script. This uses the sysfs GPIO interface instead of the buffalo specific proc interface. Also this script monitors the temperature of both drives.