Debian Lenny on LS-WXL

From NAS-Central Buffalo - The Linkstation Wiki
Revision as of 01:34, 4 August 2010 by Jugagagah (Talk | contribs)

Jump to: navigation, search

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.


Contents

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

Debootstrap

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
EOF

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.

Network

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 192.168.0.42
#     network 192.168.0.0
#     netmask 255.255.255.0
#     broadcast 192.168.0.255
#     gateway 192.168.0.1

Create /etc/hosts

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

Create /etc/hostname:

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

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
exit
tar zcvf lenny-armel-rootfs.tgz -C debian-armel-rootfs .

Now you have a complete rootfs for Debian Lenny armel.

Installation

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.

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
EOF
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:

exit
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. :)

reboot

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

Reboot and pray that it works. :)

reboot

Post-installation setup

Configuring timezone

dpkg-reconfigure tzdata

Useful packages

Anyone would need these:

apt-get install sudo less usbutils bzip2 mc linuxlogo psmisc

NTP

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

apt-get install ntp

blstools

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
./install.sh
/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

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/2.6.22.18kenatonline /lib/modules/
reboot

Install nfs

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

Check if server is running:

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

References