You need to get telnet and/or ssh access to your Linkstation. My preference is ssh, and I felt most comfortable taking apart the Linkstation to achieve this; my guide to this is [http://free.acrconsulting.co.uk/docs/Buffalo%20Linkstation%20Backups%20via%20SSH.pdf here]; it mentions other possibilities there, or you may have success with guides like these: [[Open_Stock_Firmware_LS-WXL]] or [http://buffalo.nas-central.org/wiki/Category:LS-WXL#Gain_Root_Access this guide] to SSH as root to the LS (I've not checked if these work for the LS-CHLv2; there may be alternative versions of these instructions for the LS-CHLv2 elsewhere on this wiki; I've also provided some possible alternative links in [http://free.acrconsulting.co.uk/docs/Buffalo%20Linkstation%20Backups%20via%20SSH.pdf my guide].

+

You need to get telnet and/or ssh access to your Linkstation. My preference is ssh, and I felt most comfortable taking apart the Linkstation to achieve this; my guide to this is [http://free.acrconsulting.co.uk/docs/Buffalo%20Linkstation%20Backups%20via%20SSH.pdf here]; it mentions other possibilities there, or you may have success with guides like these: [[Open_Stock_Firmware_LS-WXL]], [[http://buffalo.nas-central.org/wiki/Open_Stock_Firmware_LS-XHL]] or [http://buffalo.nas-central.org/wiki/Category:LS-WXL#Gain_Root_Access this guide] to SSH as root to the LS (I've not checked if these work for the LS-CHLv2; there may be alternative versions of these instructions for the LS-CHLv2 elsewhere on this wiki; I've also provided some possible alternative links in [http://free.acrconsulting.co.uk/docs/Buffalo%20Linkstation%20Backups%20via%20SSH.pdf my guide].

==Backup the LS==

==Backup the LS==

Revision as of 15:48, 17 January 2012

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

After my success in getting Squeeze on the LS-CHLv2 I found Debian Squeeze on LS-WXL which looks to be based on the above Lenny document; I don't know which is more complete, nor whether Debian Squeeze on LS-WXL makes this document rather redundant - you may wish to use the forums to tell others which guide(s) you use and how successful they are.

boot into this new system which will have a Debian system but still using the Buffalo kernel+modules

build a new kernel+ modules

replace the Buffalo kernel & modules

Requirements, Background info, Warnings

Note that I dismantled my Linkstation so I could connect the hard drive to my [Linux] PC - this made it easier to deal with replacing filesystems etc. - in particular I didn't need to bother creating custom initrd files (tricky); re-reading the source documents mentioned above (esp. re. Lenny) it is possible to achieve a Squeeze installation without dismantling the device, but I wouldn't count on it: This guide is relatively complex and even if you try to avoid it, there's a fair chance you'll need to dismantle the Linkstation to access the drive like this anyway - perhaps to complete a step described here, perhaps to recover from a step that went wrong. Dismantling the device does of course void your warranty and could break your device, lose your data etc. If dismantling the device worries you, I recommend not following this guide.

I strongly suggest that you should be comfortable with Linux and working at its command-line before attempting to use this guide - including being able to create or edit a file with vi or nano. You should also be comfortable with taking apart your Linkstation to access the hard disk and connect it directly to your PC. If you're not comfortable with using Linux like this then there's a fair chance you'll brick (destroy) your Linkstation, and you'll also end up with a device that lacks most of the functionality you started with - so please only try this if you know why you'd want to install Debian in the first place, and if you know how to install packages etc to achieve your goals on it once you've finished.

This guide will ask you to reformat partitions, delete existing data, etc. All of these actions may void your warranty, destroy your data and risk other bad consequences 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.

At present, the resulting Debian Squeeze installation results in the fan running at full speed - I've not yet tried working with blstools etc to see if I can tweak this to make it less noisy (it makes a lot of noise at full speed).

I'm not a kernel hacker, so writing this guide took me out of my comfort zone. Some of the steps here may in fact be unnecessary incantations - but I don't want to go back and start it all from scratch to check. Hopefully others (you?) will update this wiki page to remove or cross out unnecessary steps. Given that this was a learning experience for me too I've added explanations of what's going on in a number of steps which may be helpful for some, annoyingly verbose for others.

Key Linkstation LS-CHLv2 features/quirks

uBoot

Unlike PC-based Linux, the Linkstation uses a system called uBoot for startup. This has its own way of doing things; on this wiki and in the forums people have discovered some of its Linkstation-specific features & quirks. A particularly useful quirk is that an empty initrd in /boot causes the device to boot from the root partition: This is much easier to manipulate than generating an initrd for the device and this is used as a handy trick in the instructions below. The other thing to be aware of is that files for uBoot require special headers for them to be usable: The instructions below include the steps to generate these.

GPT / GUID partitioning

The device uses the GUID / GID approach to disk partitioning. Therefore tools like Linux's fdisk won't be able to manipulate the disk. Other tools like parted can however make sense of it. You need to stick to using this partitioning method because that's what the firmware will expect. The major advantage of this approach is that it allows use of larger hard disks that wouldn't be usable with the old MBR approach. I'm reasonably happy with Buffalo's default partitioning scheme: Both ext3 (for boot and root filesystems) and xfs (for the data area) are tried and tested filesystem implementations, so I see no need to alter their types. You could potentially adjust partition sizes, but I think Buffalo's chosen good sizes already. The one thing I do change is to mount the data partition as /home, which is more intuitive from a Linux perspective than /mnt/disk1.

Hardware

Described elsewhere on the wiki in more detail, but key features are: ARM Kirkwood processor, 128 MByte RAM, 2 ethernet ports (only one installed), serial port (not enabled), indicator LED blue/red switchable; front function button, rear on/auto/off switch. Time is not stored between reboots, so ntpd is helpful to keep the time.

Memory

Although the device has 128MByte of memory, by the time Debian gets to see it, there's only 50 MByte. I think this is due to the firmware / uBoot setting aside half of the memory for a ramdisk, uBoot reserving a couple of MByte for itself that it doesn't give back, and presumably there's memory taken away for some other stuff too. It may be possible to adjust the uBoot setup to stop it taking away so much memory. Given that Debian recommends 64MByte as a minimum memory requirement, only having 50 MByte is annoying to say the least, esp. when physically there's 128MByte in the device.

I've found that using the ramdisk memory for /tmp by mounting it as tmpfs is unreliable (at least in debootstrap-derived Debian mode; poss. not once you've completed this guide and have pure Debian), leading to memory errors for big tasks (like the step to apt-get the kernel sources). I understand tmpfs to merge the ramdisk with any available swap space and to 'do the right thing'. Given the memory errors encountered, I feel it's safer just to use swap space as needed, not merged with the ramdisk, and to have /tmp as just an ordinary directory in the root filesystem (or you may prefer to alter /tmp to live on the larger data partition instead).

I think it should be possible to setup the ramdisk as swap space, and give it priority over the disk-based swap. This would be an improvement. I've not tried this.

micro_evtd

The Lenny-on-LS-WXL document said this which probably applies to the LS-CHLv2 too:

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

This refers to the "Event Timer Daemon" [1] but that seems to be specific to PowerPC-based
Linkstations, so it's not relevant to the LS-CHLv2 which is ARM-based.

blstools

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

Preliminary steps

Obtain root access to the linkstation

You need to get telnet and/or ssh access to your Linkstation. My preference is ssh, and I felt most comfortable taking apart the Linkstation to achieve this; my guide to this is here; it mentions other possibilities there, or you may have success with guides like these: Open_Stock_Firmware_LS-WXL, [[2]] or this guide to SSH as root to the LS (I've not checked if these work for the LS-CHLv2; there may be alternative versions of these instructions for the LS-CHLv2 elsewhere on this wiki; I've also provided some possible alternative links in my guide.

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. One approach is in [forum post]; alternatively if you have got ssh access to the Linkstation you can use Clonezilla to make a space-efficient backup of it; or for a further alternative, if you dismantle your Linkstation for ssh setup you can rsync etc. the partitions then (and separately backup data not in partitions like the MBR area) - that's covered in the ssh guide mentioned above. An rsync-style backup of the boot and root partitions is particularly handy to refer back to after converting your Linkstation to Debian, particularly if you find yourself tweaking the device further; it also makes it easier to revert the Linkstation to its stock setup which could be necessary - if only temporarily - if you wish to mess around with the firmware or uBoot stuff.

Prepare a Debian root filesystem

Debootstrap

This is derived from original debootstrap docs.

Login to the Linkstation with ssh or telnet as root.

Enable the 'ar' utility, assuming it doesn't already exist: This functionality can be provided by Busybox, already installed by Buffalo:

ln -si /bin/busybox /usr/bin/ar

We'll start by setting up a basic Debian system on the Linkstation. This will give you a half-way-house Debian installation: The kernel and associated modules will still be the original Buffalo kernel & modules. We'll come back to the kernel/modules issue later, to replace them with Squeeze. First though, let's setup our half-way-house Debian with debootstrap. Find your local debootstrap download link here and download and install accordingly. We'll work in a new directory for this purpose. E.g. for the UK,

Now to setup our half-way-house root filesystem we use debootstrap. You'll need to give debootstrap the address of your local Debian mirror site which you can find at http://www.debian.org/mirror/list. I've used the UK mirror in the example below,

Now go for a coffee / beer / siesta – this step takes about 20 minutes to complete and doesn't require user input. It finishes with,

I: Base system installed successfully.

We'll chroot into the debian-squeeze directory soon where we'll finish creating the new filesystem to replace the existing one. First though we'll need a copy of Buffalo's initrd image so we can extract needed files from it to keep the Buffalo kernel happy when it boots into the new half-way-house system. You may also like to take a look FYI at /etc/fstab & /etc/mtab which will form the basis of /etc/fstab on the new system,

Work in the new root filesystem by using chroot

We use chroot to work in the new filesystem as if it's the only thing that exists: The surrounding old Buffalo filesystem will be invisible to us whilst in the chroot; reference to "/" will in fact map to the debian-squeeze directory. Some of the steps during chroot could potentially be moved to later when we reboot the Linkstation to use the new root filesystem but I think it's better to do most of the steps now since some of them make the system easier to use later, and they need to be done at some point anyway.

chroot into the debian-squeeze directory,

LANG=C chroot debian-squeeze /bin/bash

We're now in the chroot (debian-squeeze) directory, but since we're in a chroot it will appear to be the root (/) directory.

In chroot: extract modules used by Buffalo kernel for use by the new system

Unpack initrd.buffalo. This is in uImage format, meaning that it has a 64-byte header that can be discarded. The remainder is an initrd in gzipped form,

Now extract the modules from Buffalo's initrd image to match the Buffalo kernel; we'll put these in /lib/modules, which is where the kernel will expect to find them. Note that on my system I found 2 different modules directories: 2.6.31.8 and an older 2.6.22.7-88f5182. I think the older one is redundant - I certainly didn't bother to copy it across and the Squeeze installation was successful - so it should be sufficient to just copy across the newer modules directory - which will be 2.6.31.8 if you're using the same firmware release as me, v1.56. Also FYI I omitted the MAKEDEV step mentioned in the predecessor LS-WXL document, since I believe it's no longer necessary with Debian Squeeze:

Esp. note /tmp commented out to avoid memory errors (esp. in hybrid setup, maybe okay once system fully converted), /boot mounted read-write - you can change it back to read-only later, and /dev/sda6 mounted as /home rather than /mnt/disk1. If however you prefer to stick to the Buffalo layout with the data area at /mnt/disk1 then adjust the fstab above (replace /home with /mnt/disk1) and create the mount point,

In chroot: Localisation

In chroot: NTP & timezone

Setup NTP & the timezone for the new system,

apt-get install ntp
dpkg-reconfigure tzdata

In chroot: Ethernet interface setup

Setup network interface (the board actually has 2 Ethernet interfaces as well
as the loopback interface - one of the Ethernet interfaces eth0 is not connected
/ soldered on the board but is still 'seen' by Linux as a device. No point in trying to set
it up though since it's not connected.
Assuming you want its IP address info from DHCP, create /etc/network/interfaces as follows,

# 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
# On the LS-CHLv2 only eth1 has an RJ45 socket
auto eth1
iface eth1 inet dhcp

or if you prefer having a static IP address (adjust IP values for your network),

In chroot: Perform an update

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

In chroot: Install sshd

You will need to be able to access your new system once you start it up. Do so using ssh. You'll need sshd, the SSH server for that:

apt-get install openssh-server

If you wish to use password authentication set a root password,

passwd

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

PermitRootLogin yes

If you wish to use keypair authentication make sure that the following 2 lines are present and uncommented in /etc/ssh/sshd_config:

RSAAuthentication yes
PubkeyAuthentication yes

and also setup .ssh for root (your keys file will be copied in after we've left the chroot):

mkdir /root/.ssh
chmod go-rwx /root/.ssh

In chroot: Cleanup

Clean up the installation

aptitude clean

Leave chroot

We've now done most of the setup of the new filesystem, although a couple of tasks still remain. We need to exit chroot to do those,

exit

Completing the new root filesystem

ssh keypair authentication

If you're using SSH keypair authentication you need to copy root's ssh public keys into the new filesystem,

cp -p /root/.ssh/authorized_keys debian-squeeze/root/.ssh

Necessary Buffalo Incantations

You're making significant changes to the device. It may not like that and decide to sulk (= not reboot successfully). I've found having the following files in /etc (poss. also in /boot, we'll do that later) are helpful to keep things sweet,

Zip it up

which will leave squeeze-armel-rootfs.tgz in /root/workarea. It'll take a long time (about 15 minutes), so this is a good opportunity to get a cup of tea etc., and/or do the next stop on your PC

Create an empty (dummy) initrd image

This is a useful cheat from Debian_Lenny_on_LS-CHLv2#Installing_an_empty_initrd to avoid a complex process of building custom initrd images, although you will need to open up the Linkstation to access the disk (later). The stock initrd needs to be replaced with something, otherwise the Linkstation will sulk (not [re]boot etc), but the kernel (stock or the Debian kernel we'll install later) doesn't actually need an full initrd image to boot successfully (with the possible proviso of needing an fsck).

"empty initrd" means an initrd with no filesystem. It is not an empty file.

For this you need the mkimage command. I completed this step on my Linux PC; it will probably work on the Linkstation too within the chroot.

Install the uboot-mkimage package: On a Debian/Ubuntu PC or in chroot on Linkstation,

we'll use the file initrd.buffalo.empty later; remember where it is for now.

Installing the new root filesystem & initrd image

Before proceeding, please double-check that you have a reliable backups of the Linkstation's boot and root partitions, and know how you would use these to restore the Linkstation to its original state if something goes wrong.

You could go to the trouble of building 2 separate (but very similar) custom initrd images to shoehorn into
the new system without opening the case. You'd do this by adapting the instructions on this in Debian Lenny on LS-WXL,
but it would be very tricky.

Much simpler I feel is to use the null initrd image just created to force use of /dev/sda2 as the root partition.
To install the new root partition however you will need to take out the disk from the Linkstation and connect it to your PC

Take out the hard disk from the Linkstation

You need to take apart the Linkstation to remove the hard disk. Instructions for this are given here [4] (it's in Japanese, but just looking at the photos you can probably work out what to do - basically remove the 2 labels on the bottom of the device to reveal plastic tabs. Depress these and you should be able to pull the 2 sides apart). There's also a YouTube video of the process if you prefer. Remember to avoid static electricity to prevent damaging the device (esp. be careful not to work on synthetic carpets like nylon, that would be asking for trouble).

Connect the hard disk to your PC

I am assuming you have a PC to connect to...! At the risk of stating the obvious, make sure your PC is fully switched off before you start connecting or disconnecting the hard disk and take suitable precautations against damage to the Linkstation or your PC by static electricity. Start it up with Linux (if you don't run Linux on your desktop you could boot Ubuntu, Knoppix etc from a CDROM or DVD instead). Once the PC has started up, take a look to see what device the Buffalo disk is. Type

parted

to list currently attached disks. Hopefully the Buffalo disk should be amongst them. The output will give you the disk device, for example /dev/sdb. I'll assume /dev/sdb for my example commands below, but proceed very carefully if yours is different since some of the commands coming up could overwrite your PCs disk partitions, destroy your PC's data and make you have a really bad day. You have been warned.

Mount points

Create 2 directories to mount the boot partition and root partition of the Linkstation:

mkdir /ls1
mkdir /ls2

Mount the Linkstation partitions (adjust /dev/sdb if your parted output showed the Linkstation disk to have a different identifier),

that you set above. If either of these results differs then you may well have mounted the wrong disk and are at risk of destroying data if you proceed, in which case shutdown your PC and start this section again.

Replace initrd.buffalo image on Linkstation boot partition

Backup the existing initrd.buffalo file,

mv /ls1/initrd.buffalo /ls1/initrd.original

then put the initrd.buffalo.empty file we created earlier in its place. If you created initrd.buffalo.empty while you were in the chroot,

Replace the Linkstation root filesystem

Destroy the existing root filesystem (adjust /sdb2 if the Linkstation disk is not /dev/sdb - use whatever you had mounted as /ls2 above). Take care to choose the correct partition to avoid destroying your PC's data,

Rebuild your Linkstation & reboot

Now rebuild your Linkstation & try starting it. It should start up with the new system, although it will still be using the old Buffalo kernel. We'll fix that next. If it you can't connect to it I suggest you try these troubleshooting tips to get the Linkstation to boot.

You'll probably find that the indicator light constantly flashes blue. I recommend moving the On/Auto/Off switch to Off. This won't turn off the device, but it will stop it restarting when you issue a shutdown command. Until we've replaced the kernel (below), such a restart without a power off is likely to panic the Linkstation.

You have the option to stop at this point with this hybrid setup. You can install blstools to deal with the LED indicator lights & fan. Take care however when switching off the device: Keep the switch at Off (just briefly move it to Auto or On when switching it on); you should shutdown the device by using the shutdown command (shutdown -h now), and then take care to fully power off the device: Leaving it in standby will result in it being unable to reboot until after a full power off. Avoid those troubles by replacing the kernel (below).

Caution: Make sure that you have physical access to the drives and a linux box just in case you mess 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.

This guide describes how to compile the kernel on the Linkstation itself (slow, but more straightforward). If you prefer to cross-compile on a separate Debian PC you can find details in the [[5]] guide.

Currently the Linkstation is still running the Buffalo kernel, which may cause some instability including when using NFS, as well as preventing you from having a purely Debian system.

Connect to the new system

Having started it, login to the new hybrid system with ssh,

ssh root@linkstation_IP_address

You can see that the system is still a hybrid of a Debian system with the original Buffalo kernel:

uname -a

will show kernel version 2.6.31 (root@ubuntu) which is the Buffalo kernel.