This howto presents a step by step guide to convert the Terastation into a real NAS like server. The principal idea behind this conversion is that in order to maximize data reliability, the disks containing that data should be turned off for as long periods of time as possible. To archive this goal we will add another hard disk to hold the operating system and possibly some other frequently changing or frequently accessed data. Also, this conversion gives us a safe way to install another Operating System to unlock the usefulness of our Terastation to its full potential.

+

This howto presents a step by step guide to convert the TeraStation into a real NAS like server. The principal motivation behind this conversion is that to maximize data reliability, the disks containing that data should be off as much as possible. To achieve this goal we will add another hard disk to hold the operating system and possibly some other frequently changing or frequently accessed data. Also, this conversion gives us a safe way to install another Operating System to unlock the usefulness of our TeraStation to its full potential.

== Ingredients ==

== Ingredients ==

−

* 1 Terastation

+

* 1 TeraStation

−

* 1 2.5in HD

+

* 1 2.5" HD

−

* 1 40 to 44 pins HD adapter

+

* 1 EIDE cable with 3 40 pins connectors

* 1 EIDE cable with 3 40 pins connectors

+

* 1 40 to 44 pins HD adapter

* 1 Y power cable

* 1 Y power cable

+

+

The 2.5" hard disk will be put into the TeraStation as a fifth drive. To do this we also need the EIDE cable with three connectors which will be connected to the motherboard of the TeraStation, the 2,5" hard disk and one of the 3.5" hard disks. It replaces one of the two-connector cables the TeraStation is equipped with. The Y power cable is needed to provide an additional power source for the 2.5" hard disk.

== Steps outline ==

== Steps outline ==

−

# Prepare the OS hard disk

+

# [[#Prepare the soon to be installed OS Hard Disk|Prepare the soon to be installed OS Hard Disk]]

−

# Install the OS hd into the Terastation

+

# [[#Put the OS hard disk into the TeraStation|Put the OS hard disk into the TeraStation]]

In this section we will setup the 2.5in laptop hard disk to have the shape/form the Terastation expects form a disk that can be booted.

+

In this section we will setup the 2.5in laptop hard disk to have the shape/form the TeraStation expects form a disk that can be booted.

−

This can be done with the aid of a free EIDE port on a separate computer or directly on the Terastation.

+

This can be done with the aid of a free EIDE port on a separate computer or directly on the TeraStation.

=== Using a Separate Computer ===

=== Using a Separate Computer ===

−

If we don't have any big-endian computer on hand and as the mdadm tool isn't endian agnostic, there no nice way to create a raid partition and transfer files into it that will work on the Terastation. But that does not present a real problem as we can copy the raid partition as is (in RAW mode).

+

If we don't have any big-endian computer on hand and as the mdadm tool isn't endian agnostic, there no nice way to create a RAID partition and transfer files into it that will work on the TeraStation. But that does not present a real problem as we can copy the RAID partition as is (in RAW mode).

+

+

First we connect one of the TeraStation's 250GB data disks to our computer and run:

−

First we connect one of the Terastation's 250GB data disks to our computer and run:

This gives us an image with the original partition table, raid1 partition the Terastation boots from and the swap partition, an image that we will transfer to the os disk, as well as, should keep in case we need to recover the Terastation to it's original state.

−

Then we disconnect the data disk, connect the soon to be os disk and run:

+

This gives us an image with the original partition table, the RAID1 partition the Terastation boots from and the swap partition. This image we will transfer to the new OS disk, as well as keep in case we need to recover the TeraStation to it's original state.

+

+

Then we disconnect the data disk, connect the soon to be OS disk and run:

+

# dd if=original-sectors-0-65.raw of=/dev/os_disk bs=8225280 count=66

# dd if=original-sectors-0-65.raw of=/dev/os_disk bs=8225280 count=66

+

And we are done!

And we are done!

−

Also, in case we have not jet setup [[Hacking#Dropbear|ssh]] nor gained [[QandA#I_want_to_avoid_soldering._Is_is_possible_to_become_root_without_serial_console.3F|root access]] on the Terastation, this is a good time to do it, as we have the disk we will boot the Terastation form connected to our computer.

+

Also, in case we have not yet setup [[Hacking#Dropbear|SSH]] nor gained [[QandA#I_want_to_avoid_soldering._Is_is_possible_to_become_root_without_serial_console.3F|root access]] on the TeraStation, this is a good time to do it, as we have the disk we will boot the TeraStation from connected to our computer.

+

+

The RAID1 partition can be mounted to be modified with:

−

The raid1 partition can be mounted to be modified with:

# mount -t xfs /dev/os_disk1 /mnt/teraroot

# mount -t xfs /dev/os_disk1 /mnt/teraroot

−

And in that case, to force the Terastation to boot from our OS disk we need to connect all four 250GB data disks one by one to our computer and execute:

+

And in that case, to force the TeraStation to boot from our OS disk we need to connect all four 250GB data disks one by one to our computer and execute:

+

# dd if=/dev/zero of=/dev/250gb_disk count=64

# dd if=/dev/zero of=/dev/250gb_disk count=64

−

This is to make them look to the Terastation as if they were factory new disks.

−

=== Using the Terastation ===

+

This is to make them look to the TeraStation as if they were factory new disks.

+

+

=== Using the TeraStation ===

−

''Note 1: This subsection assumes that we have root access to the Terastation via ssh.''<br />

+

''Note 1: This subsection assumes that we have root access to the TeraStation via SSH.''<br />

In theory the partition scheme should not matter to the Terastation nor it should interfere with the boot process unless the OS disk has a raid partition whose super block suggests it to be /dev/md0 ("Preferred Minor : 0"). But as all data contained in the os disk will be lost anyway, it may be reasonable to delete the partition table using a computer or an USB enclosure connected to the Terastation before connecting to the Terastation via EIDE port.

+

In theory the partition scheme should not matter to the TeraStation nor it should interfere with the boot process unless the OS disk has a RAID partition whose super block suggests it to be /dev/md0 ("Preferred Minor : 0"). But as all data contained in the OS disk will be lost anyway, it may be reasonable to delete the partition table using a computer or an USB enclosure connected to the TeraStation before connecting to the TeraStation via EIDE port.

+

+

So if the OS disk gets recognized as /dev/sda we can clean it's partition table running:

−

So if the os disk gets recognized as /dev/sda we can clean it's partition table running:

# dd if=/dev/zero of=/dev/sda count=64

# dd if=/dev/zero of=/dev/sda count=64

−

At this point we can connect all the disks to the Terastation (this is detailed in the next section), boot it and continue setting up the os disk.

+

At this point we can connect all the disks to the TeraStation (this is detailed in the next section), boot it and continue setting up the OS disk.

−

First we enable dma on hda and hdb to speed up things a little bit:

+

First we enable DMA on hda and hdb to speed up things a little bit:

# hdparm -d1 /dev/hd{a,b}

# hdparm -d1 /dev/hd{a,b}

−

Then remove /dev/hdb1 form /dev/md0 (the raid1 array the Terastation boots form):

+

+

Then remove /dev/hdb1 from /dev/md0 (the raid1 array the TeraStation boots form):

+

# mdadm --manage /dev/md0 --fail /dev/hdb1

# mdadm --manage /dev/md0 --fail /dev/hdb1

# mdadm --manage /dev/md0 --remove /dev/hdb1

# mdadm --manage /dev/md0 --remove /dev/hdb1

−

At this point it may be good to make a backup of a working raid1 array used to boot the Terastation to another computer (just in case we make some mistake and have to recover). So we run the following command on the computer we want to back up to:

+

At this point it may be good to make a backup of a working RAID1 array used to boot the Terastation to another computer (just in case we make some mistake and have to recover). So we run the following command on the computer we want to back up to:

Then we swap the data disks we just removed with the os hard disk in the raid1 array and reboot the Terastation:

+

Then we swap the data disks we just removed with the OS hard disk in the RAID1 array and reboot the TeraStation:

+

# dd if=/dev/hdb of=/dev/hda bs=8225280 count=66

# dd if=/dev/hdb of=/dev/hda bs=8225280 count=66

# dd if=/dev/zero of=/dev/hdb count=64

# dd if=/dev/zero of=/dev/hdb count=64

# reboot

# reboot

−

The Terastation should come up with the first partition form the OS disk (/dev/hda1) part of the raid1 array (/dev/md0).

+

The TeraStation should come up with the first partition from the OS disk (/dev/hda1) part of the RAID1 array (/dev/md0).

Then we make /dev/md0 be exactly /dev/hda1:

Then we make /dev/md0 be exactly /dev/hda1:

+

# mdadm --manage /dev/md0 --fail /dev/hd{c,e,g}1

# mdadm --manage /dev/md0 --fail /dev/hd{c,e,g}1

# mdadm --manage /dev/md0 --remove /dev/hd{c,e,g}1

# mdadm --manage /dev/md0 --remove /dev/hd{c,e,g}1

−

Delete the partition tables form the remaining data disks and reboot:

+

Delete the partition tables from the remaining data disks and reboot:

+

# dd if=/dev/zero of=/dev/hdc count=64

# dd if=/dev/zero of=/dev/hdc count=64

# dd if=/dev/zero of=/dev/hde count=64

# dd if=/dev/zero of=/dev/hde count=64

Line 87:

Line 104:

If everything goes as it should, the Terastation should boot from the OS disk without even touching the DATA disks!

If everything goes as it should, the Terastation should boot from the OS disk without even touching the DATA disks!

−

== Installing the OS hard disk ==

+

== Put the OS hard disk into the TeraStation ==

+

+

The TeraStation has four EIDE channels, each capable of managing up to two disks (one Master and one Slave). This gives us a theoretical limit of 8 disks connected directly to the TeraStation, but in practice we should never connect more than one disk from the same array to one EIDE channel. Because a failed disk can render unusable the whole EIDE channel which would cause all the devices connected to that channel to fail as well. This would mean two disks fail from the array and therefore make the entire array fail.

−

The Terastation has four EIDE channels, each capable of managing up to two disks (one Master and one Slave). This gives us a theoretical limit of 8 disks connected directly to the Terastation, but in practice we should never connect more than one disk from the same array to one EIDE channel. Because a failed disk can render unusable the whole EIDE channel failing all devices connected to that channel, causing the lost of two disks form the array instead of one.

+

Having this in mind we connect each of the data disks to it's own EIDE channel and the OS disk as second disk to the channel of any (shouldn't matter which one) on the data disks.

−

Having this in mind we connect each of the data disks to it's own EIDE channel and the OS disk as second disk to the channel of any (should be indifferent) on the data disks.

+

In the author's experience it was easier to fit the OS disk into the TeraStation using the following scheme:

−

In the author's experience it was easier to fit the OS disk into the Terastation using the following scheme:

This way the os disk can be placed between the cables going from data disks {2,3,4} to ports labeled DISK{2,3,4} and the cable connecting the OS disk with the data disk 1 and the port labeled DISK1.

+

This way the OS disk can be placed between the cables going from data disks {2,3,4} to ports labeled DISK{2,3,4} and the cable connecting the OS disk with the data disk 1 and the port labeled DISK1.

−

Note: This placement has the big disadvantage of the OS disk being completely warped in cables without getting any ventilation at all, on the other hand, 2.5in laptop disks are supposed to work fine in that conditions. In any case, it may result better to use a 5400 rpm disk instead of a faster 7200 rpm one. And please, do experiment with other (better ventilated) placements and edit this section if you find one.

+

Note: This placement has the big disadvantage of the OS disk being completely wrapped in cables without getting any ventilation at all, on the other hand, 2.5in laptop disks are supposed to work fine in those conditions. In any case, it may be better to use a 5400RPM disk instead of a faster 7200RPM one. And please, do experiment with other (better ventilated) placements and edit this section if you find one.

== Modifying Buffalo's GNU/Linux distribution ==

== Modifying Buffalo's GNU/Linux distribution ==

−

The GNU/Linux the Terastation comes preinstalled with has a very limited set of tools, which are probably not enough to install and configure most operating systems we may want to install on the Terastation. So in this section we will install the tools we may need to make a successful installation and setup the boot loader we'll use to boot the soon to be installed OS.

+

The GNU/Linux distribution the TeraStation comes preinstalled with has a very limited set of tools, which are probably not enough to install and configure most operating systems we may want to install on the TeraStation. So in this section we will install the tools we may need to make a successful installation and setup the boot loader we'll use to boot the soon to be installed OS.

=== Installing some system tools ===

=== Installing some system tools ===

−

As in this howto we try to avoid making any assumptions with respect to witch OS we will install, we may need to add some other tools apart form the mentioned bellow. If that's the case, a good place to get the tools are the Debian PPC stable [http://packages.debian.org/ package repositories] as they stem to fit perfectly library wise.

+

As in this howto we try to avoid making any assumptions with respect to which OS we will install, we may need to add some other tools apart from the mentioned below. If that's the case, a good place to get the tools are the Debian PPC stable [http://packages.debian.org/ package repositories] as they seem to fit perfectly library wise.

−

; scp : It is always nice to have a safe way to transfer files form and to the Terastation and scp is just perfect for that. To install it we need to download the ssh stable deb ([http://packages.debian.org/stable/net/ssh ssh_3.8.1p1-8.sarge.4_powerpc.deb]) to our computer, extract the data.tar.gz:

+

; scp : It is always nice to have a safe way to transfer files form and to the TeraStation and scp is just perfect for that. To install it we need to download the ssh stable deb ([http://packages.debian.org/stable/net/ssh ssh_3.8.1p1-8.sarge.4_powerpc.deb]) to our computer, extract the data.tar.gz:

$ ar xv ssh_3.8.1p1-8.sarge.4_powerpc.deb data.tar.gz

$ ar xv ssh_3.8.1p1-8.sarge.4_powerpc.deb data.tar.gz

−

: transfer it to the Terastation (this one is a little bit tricky as we still don't have scp on the Tretastation):

+

: transfer it to the TeraStation (this one is a little bit tricky as we still don't have scp on the TeraStation):

$ cat data.tar.gz | ssh root@teratsation "cat - > ssh-data.tar.gz"

$ cat data.tar.gz | ssh root@teratsation "cat - > ssh-data.tar.gz"

−

: And extract the files we need form this tar archive (form the Terastation):

+

: And extract the files we need from this tar archive (from the TeraStation):

# tar -C / -xzpvf ssh-data.tar.gz ./usr/bin/{scp,sftp}

# tar -C / -xzpvf ssh-data.tar.gz ./usr/bin/{scp,sftp}

: This will extract just scp and sftp into /usr/bin directory.

: This will extract just scp and sftp into /usr/bin directory.

Line 120:

Line 138:

; coreutils : From the coreutils package we need to instal the chroot and mknod programs, to install them we need to download the appropriate deb file ([http://packages.debian.org/stable/base/coreutils coreutils_5.2.1-2_powerpc.deb]), extract the data.tar.gz file:

; coreutils : From the coreutils package we need to instal the chroot and mknod programs, to install them we need to download the appropriate deb file ([http://packages.debian.org/stable/base/coreutils coreutils_5.2.1-2_powerpc.deb]), extract the data.tar.gz file:

$ ar xv ssh_3.8.1p1-8.sarge.4_powerpc.deb data.tar.gz

$ ar xv ssh_3.8.1p1-8.sarge.4_powerpc.deb data.tar.gz

−

: and transfer it to the Terastation:

+

: and transfer it to the TeraStation:

$ scp data.tar.gz root@terastation:coreutils-data.tar.gz

$ scp data.tar.gz root@terastation:coreutils-data.tar.gz

−

: And extract the files we want on the Terastation:

+

: And extract the files we want on the TeraStation:

# tar -C / -xzpvf coreutils-data.tar.gz ./usr/sbin/chroot ./bin/mknod

# tar -C / -xzpvf coreutils-data.tar.gz ./usr/sbin/chroot ./bin/mknod

−

; nfs : To be able to mount nfs exports on the Terastation we'll need to put the sunrpc.o module to /lib/modules/2.4.20_mvl31-ppc_linkstation/kernel/net/ and the lockd.o and nfs.o modules to /lib/modules/2.4.20_mvl31-ppc_linkstation/kernel/fs/ on the Terastation, all available in one [http://yvasilev.main.hsphere.com/tentoo/modules/kmod_nfs.tar.gz tar archive] and load them runing:

+

; nfs : To be able to mount nfs exports on the TeraStation we'll need to put the sunrpc.o module to /lib/modules/2.4.20_mvl31-ppc_linkstation/kernel/net/ and the lockd.o and nfs.o modules to /lib/modules/2.4.20_mvl31-ppc_linkstation/kernel/fs/ on the TeraStation, all available in one [http://yvasilev.main.hsphere.com/tentoo/modules/kmod_nfs.tar.gz tar archive] and load them by running:

# modprobe sunrpc

# modprobe sunrpc

# modprobe lockd

# modprobe lockd

Line 133:

Line 151:

$ ar xv libncursesw5_5.4-4_powerpc.deb data.tar.gz

$ ar xv libncursesw5_5.4-4_powerpc.deb data.tar.gz

$ scp data.tar.gz root@terastation:ncurses-data.tar.gz

$ scp data.tar.gz root@terastation:ncurses-data.tar.gz

−

: And then extract on the Terastation:

+

: And then extract on the TeraStation:

# tar -C / -xzpvf ncurses-data.tar.gz './usr/lib/libncursesw.so*'

# tar -C / -xzpvf ncurses-data.tar.gz './usr/lib/libncursesw.so*'

Line 144:

Line 162:

=== Tweaking /etc/init.d scripts ===

=== Tweaking /etc/init.d scripts ===

−

This setup works fine with unchanged scripts, but some scripts should be updated to take into account the changes we are making to our Terastation.

+

This setup works fine with unchanged scripts, but some scripts should be updated to take into account the changes we are making to our TeraStation.

(This subsection will soon be extended.)

(This subsection will soon be extended.)

Line 152:

Line 170:

To boot into the OS we soon are going to install, this howto proposes the use of a [http://www.kurobox.com/forums/viewtopic.php?t=277 kernel module boot loader] written by Chih-Chung Chang (jochang) for the Kuro Box. With it we can safely boot other kernels keeping the flash chip untouched.

To boot into the OS we soon are going to install, this howto proposes the use of a [http://www.kurobox.com/forums/viewtopic.php?t=277 kernel module boot loader] written by Chih-Chung Chang (jochang) for the Kuro Box. With it we can safely boot other kernels keeping the flash chip untouched.

−

To install it we need to download the [http://yvasilev.main.hsphere.com/tentoo/modules/loader.o precompiled module] or compile it with the Terastation's 2.4.20 kernel headers. Put in to somewhere (like /root/) on the Terastation, write an init script and make the Terastation execute it at boot.

+

To install it we need to download the [http://yvasilev.main.hsphere.com/tentoo/modules/loader.o precompiled module] or compile it with the TeraStation's 2.4.20 kernel headers. Put in to somewhere (like /root/) on the TeraStation, write an init script and make the TeraStation execute it at boot.

The is an example for the init script:

The is an example for the init script:

Line 191:

Line 209:

== Installing another OS into the OS Hard Disk ==

== Installing another OS into the OS Hard Disk ==

−

At this point we are finally ready to install the operating system we will use on the Terastation. To do this we first repartition the OS disk according to our needs and then do the actual installation.

+

At this point we are finally ready to install the operating system we will use on the TeraStation. To do this we first repartition the OS disk according to our needs and then do the actual installation.

=== Repartitioning ===

=== Repartitioning ===

Line 197:

Line 215:

There are some rules imposed by Buffalo's firmware/kernel we should obey while changing the partition table.

There are some rules imposed by Buffalo's firmware/kernel we should obey while changing the partition table.

−

; /dev/hda1 : There most be a /dev/md0 for the kernel to boot form. So it is reasonable (and so far the only tested way) to leave /dev/hda1 unchanged (same size and type) so we can follow Buffalo's updates for our Buffalo's GNU/Linux installation.

+

; /dev/hda1 : There must be a /dev/md0 for the kernel to boot form. So it is reasonable (and so far the only tested way) to leave /dev/hda1 unchanged (same size and type) so we can follow Buffalo's updates for our Buffalo's GNU/Linux installation.

−

; /dev/hda2 : This partition is not strictly required to be swap for the Terastation to boot and work, but it is highly recommended for the swap partition to be as close as possible to the beginning of the disk (outer sectors of the disk).

+

; /dev/hda2 : This partition is not strictly required to be swap for the TeraStation to boot and work, but it is highly recommended for the swap partition to be as close as possible to the beginning of the disk (outer sectors of the disk).

; /dev/hda3 : This is the place we'll use as our playground, so to facilitate things we can create an extended partition on it.

; /dev/hda3 : This is the place we'll use as our playground, so to facilitate things we can create an extended partition on it.

−

; /dev/hda4 : For some reason this needs to have the exact type/size/offset as in the original data disks for the Terastation to boot. It is important to notice that it '''does not matter''' if this partition falls outside the physical sectors of the disk.

+

; /dev/hda4 : For some reason this needs to have the exact type/size/offset as in the original data disks for the TeraStation to boot. It is important to notice that it '''does not matter''' if this partition falls outside the physical sectors of the disk.

This leaves us with an empty extended partition we can fill with the partitions we want to use.

This leaves us with an empty extended partition we can fill with the partitions we want to use.

Line 217:

Line 235:

Device Boot Start End Blocks Id System

Device Boot Start End Blocks Id System

−

: 376.4 MiB Buffalo / and where the kernel from firmware will boot to:

+

: 376.4 MiB Buffalo / where the kernel from the firmware will boot to:

/dev/hda1 1 48 385528+ fd Linux raid autodetect

/dev/hda1 1 48 385528+ fd Linux raid autodetect

: 133.3 MiB swap:

: 133.3 MiB swap:

Line 234:

Line 252:

=== Instaling the Operating System ===

=== Instaling the Operating System ===

−

In theory the Terastation should be capable of running any operating system with support for Terastation's primary hardware components and the capability of running headless.

+

In theory the TeraStation should be capable of running any operating system with support for TeraStation's primary hardware components and the capability of running headless.

But being a little bit more practical, it should run:

But being a little bit more practical, it should run:

−

# PPC GNU/Linux distributions compiled without altivec support should run out of the box.

+

# PPC GNU/Linux distributions compiled without Altivec support should run out of the box.

#* Gentoo Linux: works nicely (howto soon to be posted)

#* Gentoo Linux: works nicely (howto soon to be posted)

#* Debian GNU/Linux: should work without a glitch (so far untested)

#* Debian GNU/Linux: should work without a glitch (so far untested)

−

#* Linux Form Scratch: should work without a glitch, but may be hard to setup if cross compilation is needed (so far untested)

+

#* Linux From Scratch: should work without a glitch, but may be hard to setup if cross compilation is needed (so far untested)

#* foobar Linux: should work without any problems, but some minor tweaks may be required (so far untested)

#* foobar Linux: should work without any problems, but some minor tweaks may be required (so far untested)

# Linux/uClibc almost works but has some issues with (I think) the dynamic loader.

# Linux/uClibc almost works but has some issues with (I think) the dynamic loader.

Line 253:

Line 271:

== Tweaking and booting the newly installed OS ==

== Tweaking and booting the newly installed OS ==

−

In this section we will do some minor tweaks specific our the Terastation setup.

+

In this section we will do some minor tweaks specific to our the TeraStation setup.

=== Addressing the &ldquo;watchdog&rdquo; ===

=== Addressing the &ldquo;watchdog&rdquo; ===

−

There is another catch (probably) from how Buffalo's kernel is configured that we need to address before we boot into our new OS. And the catch is that even so there is no real watchdog on the Terastation, the kernel appears to have a watchdog''ish'' something connected to /dev/ttyS1 and managed by the mc_ctld program (the program that should manage an UPS connected to the serial port). So this should only be needed if we will be booting a Linux based OS with the stock kernel.

+

There is another catch (probably) from how Buffalo's kernel is configured that we need to address before we boot into our new OS. And the catch is that even so there is no real watchdog on the TeraStation, the kernel appears to have a watchdog''ish'' something connected to /dev/ttyS1 and managed by the mc_ctld program (the program that should manage an UPS connected to the serial port). So this should only be needed if we will be booting a Linux based OS with the stock kernel.

To work around this catch we can copy the mc_ctld program with the files it uses to an empty directory and execute it chrooted on boot.

To work around this catch we can copy the mc_ctld program with the files it uses to an empty directory and execute it chrooted on boot.

Line 275:

Line 293:

/usr/sbin/mc_ctld

/usr/sbin/mc_ctld

−

And add something like the following to be executed by the new os at boot:

+

And add something like the following to be executed by the new OS at boot:

/usr/bin/chroot /empty/dir/we/copied/to /usr/sbin/mc_ctld

/usr/bin/chroot /empty/dir/we/copied/to /usr/sbin/mc_ctld

Line 287:

Line 305:

=== SSH Server ===

=== SSH Server ===

−

As the Terastation by its nature is headless, it is crucial to configure the new os to start the SSH server at boot.

+

As the TeraStation by its nature is headless, it is crucial to configure the new OS to start the SSH server at boot.

=== Getting ready to boot ===

=== Getting ready to boot ===

Line 293:

Line 311:

If we are going to boot into a Linux based OS with the stock kernel we need to hexedit it to make it boot from the device we want it to boot, else we should skip to the next subsection.

If we are going to boot into a Linux based OS with the stock kernel we need to hexedit it to make it boot from the device we want it to boot, else we should skip to the next subsection.

−

To accomplish this we first need to extract the kernel as shown on [[Firmware_update#Your_own_Firmware_update|Firmware Update]] and then replace the three occurrences of root=/dev/{md0,ram0,hda1} with root=/dev/hdaX, where X is the partition number we want to boot form (6 in our example). And then transfer it to the Terastation.

+

To accomplish this we first need to extract the kernel as shown on [[Firmware_update#Your_own_Firmware_update|Firmware Update]] and then replace the three occurrences of root=/dev/{md0,ram0,hda1} with root=/dev/hdaX, where X is the partition number we want to boot form (6 in our example). And then transfer it to the TeraStation.

It also may be wise to copy the /lib/modules directory for our newly installed Linux.

It also may be wise to copy the /lib/modules directory for our newly installed Linux.

Line 299:

Line 317:

=== Booting ===

=== Booting ===

−

First we need to unmount all the unneeded mounts and stop all raid devices we can (the only active should be /dev/md0):

+

First we need to unmount all the unneeded mounts and stop all RAID devices we can (the only active should be /dev/md0):

# umout /unneeded/mount

# umout /unneeded/mount

# mdadm /dev/mdX --stop

# mdadm /dev/mdX --stop

Line 306:

Line 324:

And finally we issue the magic command to boot the new OS:

And finally we issue the magic command to boot the new OS:

# sync && insmod loader.o kernel=the_kernel cmdline="root=/dev/hdaX"

# sync && insmod loader.o kernel=the_kernel cmdline="root=/dev/hdaX"

−

(the command line will be ignored by the stock kernel, but it is nice to specify it for consistency's sake)

+

(the command line will be ignored by the stock kernel, but it is nice to specify it for consistency sake)

−

And if everything goes well, in a couple of minutes the Terastation should come up booted into the os we just installed!

+

And if everything goes well, in a couple of minutes the TeraStation should come up booted into the OS we just installed!

=== Post first boot configuration ===

=== Post first boot configuration ===

−

There is just one tiny thing that needs to be done. And the thing is that when we power the Terastation on it'll first boot into /dev/md0 witch is supposed to consist of four identical partitions mirrored in raid1, but we changed that supposition several sections ago, so we should update /dev/md0's superblock (again, just for consistency's sake). If we booted Linux, we can do it executing:

+

There is just one tiny thing that needs to be done. And the thing is that when we power the TeraStation on it'll first boot into /dev/md0 wich is supposed to consist of four identical partitions mirrored in RAID1, but we changed that supposition several sections ago, so we should update /dev/md0's superblock (again, just for consistency sake). If we booted Linux, we can do it executing:

# mdadm --manage /dev/md0 --stop

# mdadm --manage /dev/md0 --stop

# mdadm --create /dev/md0 -l 1 -f -n 1 /dev/hda1

# mdadm --create /dev/md0 -l 1 -f -n 1 /dev/hda1

−

Also at this point we may want to activate the auto boot into new os feature creating the .tonewos file in Buffalo's /.

+

Also at this point we may want to activate the auto boot into new OS feature creating the .tonewos file in Buffalo's /.

== Setting up the DATA hard disks ==

== Setting up the DATA hard disks ==

−

At this point we can setup the data disks in any way we think will suit better our needs. As the Terastation should care about nothing more that the OS disk when it boots.

+

At this point we can setup the data disks in any way we think will suit better our needs. As the TeraStation should care about nothing more that the OS disk when it boots.

But in reality, this may not hold true as the initrd image that the kernel from firmware boots into may try to access our DATA disk, so some esoteric or close to stock configurations may confuse it.

But in reality, this may not hold true as the initrd image that the kernel from firmware boots into may try to access our DATA disk, so some esoteric or close to stock configurations may confuse it.

Abstract

This howto presents a step by step guide to convert the TeraStation into a real NAS like server. The principal motivation behind this conversion is that to maximize data reliability, the disks containing that data should be off as much as possible. To achieve this goal we will add another hard disk to hold the operating system and possibly some other frequently changing or frequently accessed data. Also, this conversion gives us a safe way to install another Operating System to unlock the usefulness of our TeraStation to its full potential.

Ingredients

1 TeraStation

1 2.5" HD

1 EIDE cable with 3 40 pins connectors

1 40 to 44 pins HD adapter

1 Y power cable

The 2.5" hard disk will be put into the TeraStation as a fifth drive. To do this we also need the EIDE cable with three connectors which will be connected to the motherboard of the TeraStation, the 2,5" hard disk and one of the 3.5" hard disks. It replaces one of the two-connector cables the TeraStation is equipped with. The Y power cable is needed to provide an additional power source for the 2.5" hard disk.

Prepare the soon to be installed OS Hard Disk

In this section we will setup the 2.5in laptop hard disk to have the shape/form the TeraStation expects form a disk that can be booted.

This can be done with the aid of a free EIDE port on a separate computer or directly on the TeraStation.

Using a Separate Computer

If we don't have any big-endian computer on hand and as the mdadm tool isn't endian agnostic, there no nice way to create a RAID partition and transfer files into it that will work on the TeraStation. But that does not present a real problem as we can copy the RAID partition as is (in RAW mode).

First we connect one of the TeraStation's 250GB data disks to our computer and run:

This gives us an image with the original partition table, the RAID1 partition the Terastation boots from and the swap partition. This image we will transfer to the new OS disk, as well as keep in case we need to recover the TeraStation to it's original state.

Then we disconnect the data disk, connect the soon to be OS disk and run:

# dd if=original-sectors-0-65.raw of=/dev/os_disk bs=8225280 count=66

And we are done!

Also, in case we have not yet setup SSH nor gained root access on the TeraStation, this is a good time to do it, as we have the disk we will boot the TeraStation from connected to our computer.

The RAID1 partition can be mounted to be modified with:

# mount -t xfs /dev/os_disk1 /mnt/teraroot

And in that case, to force the TeraStation to boot from our OS disk we need to connect all four 250GB data disks one by one to our computer and execute:

# dd if=/dev/zero of=/dev/250gb_disk count=64

This is to make them look to the TeraStation as if they were factory new disks.

Using the TeraStation

Note 1: This subsection assumes that we have root access to the TeraStation via SSH.Note 2: This method isn't actually tested (please make corrections and remove this note when/if it works)

In theory the partition scheme should not matter to the TeraStation nor it should interfere with the boot process unless the OS disk has a RAID partition whose super block suggests it to be /dev/md0 ("Preferred Minor : 0"). But as all data contained in the OS disk will be lost anyway, it may be reasonable to delete the partition table using a computer or an USB enclosure connected to the TeraStation before connecting to the TeraStation via EIDE port.

So if the OS disk gets recognized as /dev/sda we can clean it's partition table running:

# dd if=/dev/zero of=/dev/sda count=64

At this point we can connect all the disks to the TeraStation (this is detailed in the next section), boot it and continue setting up the OS disk.

First we enable DMA on hda and hdb to speed up things a little bit:

# hdparm -d1 /dev/hd{a,b}

Then remove /dev/hdb1 from /dev/md0 (the raid1 array the TeraStation boots form):

At this point it may be good to make a backup of a working RAID1 array used to boot the Terastation to another computer (just in case we make some mistake and have to recover). So we run the following command on the computer we want to back up to:

If everything goes as it should, the Terastation should boot from the OS disk without even touching the DATA disks!

Put the OS hard disk into the TeraStation

The TeraStation has four EIDE channels, each capable of managing up to two disks (one Master and one Slave). This gives us a theoretical limit of 8 disks connected directly to the TeraStation, but in practice we should never connect more than one disk from the same array to one EIDE channel. Because a failed disk can render unusable the whole EIDE channel which would cause all the devices connected to that channel to fail as well. This would mean two disks fail from the array and therefore make the entire array fail.

Having this in mind we connect each of the data disks to it's own EIDE channel and the OS disk as second disk to the channel of any (shouldn't matter which one) on the data disks.

In the author's experience it was easier to fit the OS disk into the TeraStation using the following scheme:

This way the OS disk can be placed between the cables going from data disks {2,3,4} to ports labeled DISK{2,3,4} and the cable connecting the OS disk with the data disk 1 and the port labeled DISK1.

Note: This placement has the big disadvantage of the OS disk being completely wrapped in cables without getting any ventilation at all, on the other hand, 2.5in laptop disks are supposed to work fine in those conditions. In any case, it may be better to use a 5400RPM disk instead of a faster 7200RPM one. And please, do experiment with other (better ventilated) placements and edit this section if you find one.

Modifying Buffalo's GNU/Linux distribution

The GNU/Linux distribution the TeraStation comes preinstalled with has a very limited set of tools, which are probably not enough to install and configure most operating systems we may want to install on the TeraStation. So in this section we will install the tools we may need to make a successful installation and setup the boot loader we'll use to boot the soon to be installed OS.

Installing some system tools

As in this howto we try to avoid making any assumptions with respect to which OS we will install, we may need to add some other tools apart from the mentioned below. If that's the case, a good place to get the tools are the Debian PPC stable package repositories as they seem to fit perfectly library wise.

scp

It is always nice to have a safe way to transfer files form and to the TeraStation and scp is just perfect for that. To install it we need to download the ssh stable deb (ssh_3.8.1p1-8.sarge.4_powerpc.deb) to our computer, extract the data.tar.gz:

$ ar xv ssh_3.8.1p1-8.sarge.4_powerpc.deb data.tar.gz

transfer it to the TeraStation (this one is a little bit tricky as we still don't have scp on the TeraStation):

$ cat data.tar.gz | ssh root@teratsation "cat - > ssh-data.tar.gz"

And extract the files we need from this tar archive (from the TeraStation):

# tar -C / -xzpvf ssh-data.tar.gz ./usr/bin/{scp,sftp}

This will extract just scp and sftp into /usr/bin directory.

coreutils

From the coreutils package we need to instal the chroot and mknod programs, to install them we need to download the appropriate deb file (coreutils_5.2.1-2_powerpc.deb), extract the data.tar.gz file:

$ ar xv ssh_3.8.1p1-8.sarge.4_powerpc.deb data.tar.gz

and transfer it to the TeraStation:

$ scp data.tar.gz root@terastation:coreutils-data.tar.gz

And extract the files we want on the TeraStation:

# tar -C / -xzpvf coreutils-data.tar.gz ./usr/sbin/chroot ./bin/mknod

nfs

To be able to mount nfs exports on the TeraStation we'll need to put the sunrpc.o module to /lib/modules/2.4.20_mvl31-ppc_linkstation/kernel/net/ and the lockd.o and nfs.o modules to /lib/modules/2.4.20_mvl31-ppc_linkstation/kernel/fs/ on the TeraStation, all available in one tar archive and load them by running:

# modprobe sunrpc
# modprobe lockd
# modprobe nfs

ncurses

The ncurses library is needed by many useful packages like screen, less and nano, so in case we want to use any of them we'll have to install ncurses. It is provided by the libncursesw5 deb (libncursesw5_5.4-4_powerpc.deb). To install it, first we get the deb and run:

The GNU Screen program is a quite nice tool to have when doing any nontrivial system management (like OS installation). It is provided by the screen deb package (screen_4.0.2-4.1_powerpc.deb). To install it we need to extract the ./usr/bin/screen and ./etc/screenrc files.

less and nano

There are more and vi, but “less is more” and nano is a little bit friendlier than vi and will serve us as an example of installing a text editor (we will need one to configure the boot loader). This packages are provided by the less and nano debs (less_382-1_powerpc.deb and nano_1.2.4-5_powerpc.deb). We will need ./usr/bin/less form less and ./bin/nano and ./etc/nanorc form nano.

LVM

In case we want our setup to use LVM (Logical Volume Manager) we just will need to install the LVM userland tools, as the kernel module is already provided by the original Buffalo installation. This tools are provided by the lvm10 deb package (lvm10_1.0.8-8_powerpc.deb). We will need to install the ./lib dir form it. (This will install all programs to /lib/lvm-10/, so to execute the foo program we will have to run # /lib/lvm-10/foo)

Tweaking /etc/init.d scripts

This setup works fine with unchanged scripts, but some scripts should be updated to take into account the changes we are making to our TeraStation.

(This subsection will soon be extended.)

Installing the “boot loader”

To boot into the OS we soon are going to install, this howto proposes the use of a kernel module boot loader written by Chih-Chung Chang (jochang) for the Kuro Box. With it we can safely boot other kernels keeping the flash chip untouched.

To install it we need to download the precompiled module or compile it with the TeraStation's 2.4.20 kernel headers. Put in to somewhere (like /root/) on the TeraStation, write an init script and make the TeraStation execute it at boot.

We should not create the /.tonewos file until our new OS is in working conditions, but when we are ready we just need to execute:

# touch /.tonewos

Installing another OS into the OS Hard Disk

At this point we are finally ready to install the operating system we will use on the TeraStation. To do this we first repartition the OS disk according to our needs and then do the actual installation.

Repartitioning

There are some rules imposed by Buffalo's firmware/kernel we should obey while changing the partition table.

/dev/hda1

There must be a /dev/md0 for the kernel to boot form. So it is reasonable (and so far the only tested way) to leave /dev/hda1 unchanged (same size and type) so we can follow Buffalo's updates for our Buffalo's GNU/Linux installation.

/dev/hda2

This partition is not strictly required to be swap for the TeraStation to boot and work, but it is highly recommended for the swap partition to be as close as possible to the beginning of the disk (outer sectors of the disk).

/dev/hda3

This is the place we'll use as our playground, so to facilitate things we can create an extended partition on it.

/dev/hda4

For some reason this needs to have the exact type/size/offset as in the original data disks for the TeraStation to boot. It is important to notice that it does not matter if this partition falls outside the physical sectors of the disk.

This leaves us with an empty extended partition we can fill with the partitions we want to use.

To change the partition table the mfdisk program is available, but DO NOT RUN it as if it were the normal fdisk program as then it will replace the existing partition table with a funky useless one. Instead run:

# mfdisk -c /dev/hda

To use it in interactive mode (a la fdisk). Or just to be safe we can set an alias for it to mimic fdisk:

Instaling the Operating System

In theory the TeraStation should be capable of running any operating system with support for TeraStation's primary hardware components and the capability of running headless.

But being a little bit more practical, it should run:

PPC GNU/Linux distributions compiled without Altivec support should run out of the box.

Gentoo Linux: works nicely (howto soon to be posted)

Debian GNU/Linux: should work without a glitch (so far untested)

Linux From Scratch: should work without a glitch, but may be hard to setup if cross compilation is needed (so far untested)

foobar Linux: should work without any problems, but some minor tweaks may be required (so far untested)

Linux/uClibc almost works but has some issues with (I think) the dynamic loader.

Gentoo Embedded: have problems

uClibc buildroot: the exact same problems as with Gentoo Embedded.

*BSD may work as the CPU, EIDE, NIC and USB chips are supported, but may need some (trivial) changes in the “boot loader” we are using to be able to boot non Linux kernels.

NetBSD: should be the best bet (so far untested)

At this point we follow the instructions associated with the operating system we decided to install.

Tweaking and booting the newly installed OS

In this section we will do some minor tweaks specific to our the TeraStation setup.

Addressing the “watchdog”

There is another catch (probably) from how Buffalo's kernel is configured that we need to address before we boot into our new OS. And the catch is that even so there is no real watchdog on the TeraStation, the kernel appears to have a watchdogish something connected to /dev/ttyS1 and managed by the mc_ctld program (the program that should manage an UPS connected to the serial port). So this should only be needed if we will be booting a Linux based OS with the stock kernel.

To work around this catch we can copy the mc_ctld program with the files it uses to an empty directory and execute it chrooted on boot.

And add something like the following to be executed by the new OS at boot:

/usr/bin/chroot /empty/dir/we/copied/to /usr/sbin/mc_ctld

It may also be necessary execute on boot (to be confirmed):

echo -n "aa8041" > /dev/ttyS1
echo -n "qqqq" > /dev/ttyS1

And on halt/reboot (also to be confirmed):

echo -n "rrrr" > /dev/ttyS1
echo -n "EEEE" > /dev/ttyS1

SSH Server

As the TeraStation by its nature is headless, it is crucial to configure the new OS to start the SSH server at boot.

Getting ready to boot

If we are going to boot into a Linux based OS with the stock kernel we need to hexedit it to make it boot from the device we want it to boot, else we should skip to the next subsection.

To accomplish this we first need to extract the kernel as shown on Firmware Update and then replace the three occurrences of root=/dev/{md0,ram0,hda1} with root=/dev/hdaX, where X is the partition number we want to boot form (6 in our example). And then transfer it to the TeraStation.

It also may be wise to copy the /lib/modules directory for our newly installed Linux.

Booting

First we need to unmount all the unneeded mounts and stop all RAID devices we can (the only active should be /dev/md0):

# umout /unneeded/mount
# mdadm /dev/mdX --stop

(we can see what is mounted with "mount" and the active raid arrays with "cat /proc/mdstat")

And finally we issue the magic command to boot the new OS:

# sync && insmod loader.o kernel=the_kernel cmdline="root=/dev/hdaX"

(the command line will be ignored by the stock kernel, but it is nice to specify it for consistency sake)

And if everything goes well, in a couple of minutes the TeraStation should come up booted into the OS we just installed!

Post first boot configuration

There is just one tiny thing that needs to be done. And the thing is that when we power the TeraStation on it'll first boot into /dev/md0 wich is supposed to consist of four identical partitions mirrored in RAID1, but we changed that supposition several sections ago, so we should update /dev/md0's superblock (again, just for consistency sake). If we booted Linux, we can do it executing: