MyBookLive: Fresh installation of Debian 8 (Jessie)

WARNING: this is currently under development and being revised, you can use this current version at your own risk.  I will update this once I have confirmed all is correct.

 

This guide will step you through the process to install Debian 8 (Jessie) to either a new hard drive or to replace the original OS of your MyBookLive NAS.

I built this guide after researching multiple sources trying to get a detailed step by step, but all of the sources I found either built off other guides with confusing instructions or were very broken and hard to follow. So this is what I have come up with. I’ve tested this many, many times as I was changing configurations and just trying out different things to see what the MyBookLive could handle and a lot of the time it ended with the system no longer responding on the network. Since I don’t have a JTAG device to access the device I have just found it easier to just reload the drive with a new system.

There are some limitations to what you can load onto the drive since the processor is a PowerPC, but the stuff that could be loaded in the OS makes it a pretty useful network device.

WARRANTY WARNING: The following steps will void your warranty, if you still have one!

There are steps to reset your drive back to factory if you so desire to, a quick search on Google will guide you through that.

Prerequisites

You need to be able to connect to the hard disk and therefore you must open the MyBookLive case. There’s a nice video of how to do this on YouTube.

  • Debian Linux 8 – 64bit (Either a physical system or through a virtual machine) installed.
    NOTE: All of the code listed below is done from a virtual machine setup.  You will need to make sure that you attach the hard drive to the virtual machine.
  • USB to SATA
    Unless you can connect your drive directly to your computer
    Note: Depending on how old your USB to SATA adapter is you might noticed when you go to partition the hard drive the drive size is only reported as about 750GB, this doesn’t stop anything but you will want to wait on making all of the partitions on the hard drive since you technically won’t be able to configure all of the space during the initial setup.
  • Active Internet Connection (You will be downloading files from the internet, so this is important)

If you are performing these steps on a virtual machine you need to DISABLE ANY AUTO RESTART APPLICATIONS on your host system. I’ve had this happen a couple of times where the host system installed new updates and decided, hey there isn’t anything going on let’s restart your computer! Nothing is really lost, but it leaves you wondering at what point in the processes did it restart!

If you run into major problems it is also very helpful, if you can attach a serial converter to debug the boot process. Otherwise you can connect the drive to your computer so that you can look at the logs to figure out where the problems during boot up are.

Partition the hard drive

If this is a brand new hard drive or you have decided to wipe everything from your existing hard drive (hopefully you backed up your data before you started this adventure!) Then you will partition your hard disk with GPT partition table e.g. using parted or gparted if you have a GUI installed.

I created a 10 Gb EXT3 partition for the system as the first partition, you are welcome to create whatever size you’d like but I recommend no less than 5 GB.

user@debian:~# sudo parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart
 Label: (optional)
 Filesystem [ext2]: (press enter)
 Start: 1
 End:  (this is up to you, if you want 10 GB enter 10.00GB)
(parted) print
(parted) quit

user@debian:~# sudo mkfs -t ext3 /dev/sdb1

If you are using a USB to SATA adapter and it isn’t showing you the correct volume size then you need to wait on creating the other partitions later.

Otherwise, create a second partition that is ext4 that uses all but 1 GB of space and then create the swap partition of 1 GB at the end of the drive

Install debootstraping

You should already have the debootstrap package installed if you followed the first guide. If you didn’t follow those steps, then follow this next step if you did follow it you can skip this next step.

The machine you are using needs to have an active internet connection, otherwise this will not work.

user@debian:~# sudo apt-get install binfmt-support qemu qemu-user-static debootstrap

Mount MyBookLive hard drive partition

You should have partitioned and formatted your hard disk by now because you need to mount the partition next.

user@debian:~# sudo mkdir /mnt/mbl
user@debian:~# sudo mount -t ext3 /dev/sdb1 /mnt/mbl

Bootstrap the base system to the MyBookLive hard drive

The command below will initially load the system to your hard drive for the MyBookLive. The “include” option allows you to install packages to the system. You can add more to it if you want the system to have these packages installed right away rather than installing them later. I have found that these are the minimum packages that should be initially installed

user@debian:~# sudo debootstrap --verbose --foreign --include linux-image-powerpc,ntp,openssh-server,locales --arch powerpc jessie /mnt/mbl http://ftp.us.debian.org/debian/

This will take some time, eventually you will be back at the command prompt.

Setup QEMU emulator

To be able to chroot into a target file system, the qemu emulator for the target CPU needs to be accessible from inside the chroot jail.

user@debian:~# sudo cp /usr/bin/qemu-ppc-static /mnt/mbl/usr/bin
user@debian:~# sudo mkdir /mnt/mbl/dev/pts
user@debian:~# sudo mount devpts /mnt/mbl/dev/pts -t devpts
user@debian:~# sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot /mnt/mbl /debootstrap/debootstrap --second-stage

Depending on your setup this process could take 10 to 15 minutes. You should eventually get a “Base system installed successfully”.

Trigger post install scripts

user@debian:~# sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot /mnt/mbl dpkg --configure -a

No status will be shown, you will just be back at the command prompt.

Configuring the new system (target specific)

The system you have just created needs a few tweaks so you can use it for specific tasks.

Mounting dev and proc:

user@debian:~# sudo mount -o bind /proc /mnt/mbl/proc/
user@debian:~# sudo mount -o bind /dev /mnt/mbl/dev/

Chroot

user@debian:~# sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot /mnt/mbl/

You are now in a “virtual” jailed environment of the system installed on your MyBookLive hard drive. All of the commands executed will be making changes on that system. You will notice that the prompt is now different.

Change hostname

Your new system will assume the name of the computer that you used to build. Example I named my debian install “debian” so looking at the hostname file on the new system will show the same hostname. Execute the following command to change the hostname of the MyBookLive system.

root@debian:/# echo 'saturn' > /etc/hostname

Of course you can change the name to whatever you’d like, just as long as it is something different than any system on your network.

Change the root password on your new system

One of the first things I did was to set the password for the new system, this will be the root password. Change it to something that is secure, unless you just don’t care about security.

root@debian:/# passwd

SSH settings

Newer versions of openssh in debian disallow password based login for the root user. Therefore we have to change the following line in /etc/ssh/sshd_config to allow the root user to login via SSH:

PermitRootLogin without-password

to

PermitRootLogin yes

Alternatively, you can place the public part of your ssh key in /root/.ssh/authorized_keys.

 

Prepare /boot and compile a kernel

Compile a kernel according to the guide update using a cross compiler (one dos not need to build the modules, uImage is fine). Place the resulting uBoot image in /boot and the apollo3g.dtb from the original harddisk as well.

Create a boot.scr with the uboot-tools package as described in the original guide. Since the bootloader is on a separate flash, one doesn’t need to install it as on several other arm boards. Just as a warning – the default kernel config does not support booting using UUIDs as root parameter for the kernel.

Kernel & UBoot

Preparation and Patching

root@debian:~/# mkdir /boot/kernel
root@debian:~/# cd /boot/kernel

In our chroot, we now install all the tools we require for kernel building and creation of the u-boot bootloader entrypoint.

root@debian:~/kernel# apt-get install ca-certificates build-essential uboot-mkimage ncurses-dev unzip

Download and patch the kernel

root@debian:~/kernel# wget https://github.com/MyBookLive/kernel-2.6.32/raw/master/kernel_2.6.32-65/kernel-2.6.32.65-wd.patch
root@debian:~/kernel# wget https://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.32/linux-2.6.32.65.tar.xz
root@debian:~/kernel# xz -dc linux-2.6.32.65.tar.xz | tar -x
root@debian:~/kernel# cd linux-2.6.32.65
root@debian:~/kernel/linux-2.6.32.65# patch -p1 -i ../kernel-2.6.32.65-wd.patch

Building and installing kernel

Kernel building steps…

root@debian:~/kernel/linux-2.6.32.65# make distclean
root@debian:~/kernel/linux-2.6.32.65# make mrproper
root@debian:~/kernel/linux-2.6.32.65# make 44x/apollo_3G_nas_defconfig
root@debian:~/kernel/linux-2.6.32.65# make uImage

about three hours later…

Copy the kernel image to its new location

root@debian:~/kernel/linux-2.6.32.65# cp arch/powerpc/boot/uImage /boot/

UBoot Configuration

Create boot.cmd with following content

echo Boot from U-boot configuration
setenv md0_args 'setenv bootargs root=/dev/sda1 rw rootfstype=ext3 rootflags=data=ordered'
setenv load_sata 'sata init; ext2load sata 1:1 ${kernel_addr_r} /boot/uImage; ext2load sata 1:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv boot_sata 'run load_sata; run md0_args addtty; bootm ${kernel_addr_r} - ${fdt_addr_r}'
echo ==== Loading Linux kernel, Device tree, Root filesystem ====
run boot_sata

Convert to binary bootloader config

root@debian:~/kernel/linux-2.6.32.65# mkimage -A powerpc -O linux -T script -C none -a 0 -e 0 -n 'Execute uImage' -d boot.cmd boot.scr
root@debian:~/kernel/linux-2.6.32.65# cp boot.scr /boot/

Changes to INITTAB

Edit inittab

root@debian:~/kernel/linux-2.6.32.65# vi /etc/inittab

Find the following line and comment out the ca:12345…

# What to do when CTRL-ALT-DEL is pressed.
# ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

Next comment out the following lines (virtual consoles are not needed for our purposes):

1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

Find the following line near the bottom:

#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100

uncomment the line and change the port(baud) speed to 115200 instead of 9600

T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100

It should look like the above line when you are done.

Save your changes and quit

Assign a static address
If you are like me, you like “servers” to have a consistent address. I went ahead and staticaly assigned an address to my device.

root@debian:~/kernel/linux-2.6.32.65# vi /etc/network/interfaces

Add the following below the iface lo inet loopback line

auto eth0
iface eth0 inet static
    address XXX.XXX.XXX.XXX
    netmask XXX.XXX.XXX.XXX
    gateway XXX.XXX.XXX.XXX

save and quit

DNS settings
Depending on your system the resolv.conf file might have grabbed IPv6 nameserver entries. I would go ahead and update your entries to IPv4.

root@debian:~/kernel/linux-2.6.32.65# vi /etc/resolv.conf

Change out the nameserver lines to your favorite DNS servers.

nameserver 208.67.222.222
nameserver 208.67.220.220

Hosts
For good measures I also update the hosts file to reflect the name of the server.

root@debian:~/kernel/linux-2.6.32.65# vi /etc/hosts

I add a line just below the 127.0.0.1 line to reflect the static address and name I’ve assigned to this server.
Exit the chroot via exit and copy the device tree blob in the new system.

root@debian:/boot# cp /boot/apollo3g.dtb /newsys/boot/

Copy APOLLO3G.DTB

The final and kind of a pain step is to copy the apollo3g.dtb file to the hard drive, this is necessary for the system to boot up. The only way to get the file is to extract it from the image. It could be hosted somewhere for all I know, but it is just easiest for me to download the firmware file from WD, extract the package, mount the image and then copy the file to the hard drive. Yeah sounds like a lot of steps, but I’ve done it a bunch of times so… If you already have the file extracted somewhere then copy it to the /boot directory on your MyBookLive hard drive. Otherwise here are the steps I used to get it downloaded and extracted.

user@debian:~$ wget http://download.wdc.com/nas/apnc-024310-048-20150507.deb
user@debian:~$ sudo mkdir os
user@debian:~$ dpkg --extract apnc-024310-048-20150507.deb ./os

Copy the device tree blob in the new system.

root@debian:/boot# cp /boot/apollo3g.dtb /mbl/boot/

Unmount the drive

After you have copied over the apollo3g.dtb file to the hard drive you now need to unmount the partitions you mounted earlier before you disconnect the drive and mate it with the mainboard from the MyBookLive.

Once you have unmounted the partitions, then you can disconnect the hard drive (if you used a USB to SATA adapter) or shutdown your system to remove it from your computer.

Connect the Hard Drive back to the mainboard

Once you have the mainboard connected to the hard drive and secured to the hard drive, you can power it on to see if everything worked. The easiest way to find out is to start a ping to the address you assigned to it above. Once it starts replying then you should be able to SSH into the drive.

As I mentioned above you can now compile the 4.0.x kernel for the system.  You will do this all via SSH (unless you have a serial device connected), otherwise you are free to customize the system as you like.  You will need to finish the partitioning of the hard drive as I mentioned at the start, this is completely up to you on how you partition the drive.

(WIP) Compiling 4.x Kernel

The follow is something I was experimenting with as a way to just compile a 4.x kernel directly rather than compile 2.6.x, boot the system and then compile another kernel.  I have moved the following out of the main section of this document as a work in progress.  If you have input about this or notes for making this all work, please comment it below.

 

Install crosstool-ng and configure cross compiler

To compile the powerpc kernel on a x86_64 machine, we need a cross compiler. We do not need this step, if we compile the kernel directly on the MyBook Live. I tried various options and found installation via crosstool-ng to be the most convenient one.

First, we clone the repository and switch into the checked out path

debianuser:debian:~# git clone https://github.com/crosstool-ng/crosstool-ng 
debianuser:debian:~# cd crosstool-ng/

Next, we bootstrap, configure and install the ct-ng tool

./bootstrap 
./configure --prefix=/usr/local 
make 
sudo make install

Now, we should have ct-ng available in path so that it can be used to install the required cross compiler suite. The available cross compilers can be listed and inspected via

ct-ng list-samples 
ct-ng show-powerpc-405-linux-gnu

Lets install the powerpc cross compiler for powerpc 405 – it’s compatible with powerpc 440 arch of our MyBook Live:

ct-ng updatetools 
ct-ng powerpc-405-linux-gnu 
ct-ng build

Now we should have a working cross compiler in the x-tools directory in your home.

Building a 4.x Kernel MyBook Live

To build a Kernel image suitable to boot directly from u-boot bootloader, we need to have the u-boot-tools installed

sudo apt-get install u-boot-tools

Next, we pull, extract and patch the kernel-sources:

wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.1.17.tar.xz 
git clone https://github.com/MyBookLive/kernel-4.0.x.git 
tar -xvJf linux-4.1.17.tar.xz 
cd linux-4.1.17 
patch -p1 < ../kernel-4.0.x/01_mbl.patch 
patch -p1 < ../kernel-4.0.x/02_ppc4xx_ocm_enable.patch 
patch -p1 < ../kernel-4.0.x/03_enable_leds.patch 
patch -p1 < ../kernel-4.0.x/04_enable_button.patch

We have to set some environment variables before build:

export PATH=$PATH:~/x-tools/powerpc-405-linux-gnu/bin 
export ARCH=powerpc 
export CROSS_COMPILE=powerpc-405-linux-gnu-

Next, we copy the example config and adapt it if required

cp ../kernel-4.0.x/config_mbl .config 
make menuconfig

When configured, we build a uImage, which we can copy into the /boot directory on the MyBook Live. Alternatively, we can copy the image via scp, if we cross compile.

make -j 10 
make uImage 
sudo cp arch/powerpc/boot/uImage /mnt/mbl/boot/

Copy the source tree and install them on the device

make modules 
rsync -av ./ /data/linux-4.1.17/

# switch to mybook live 
cd /data/linux-4.1.17/ 
make modules install
 #else
 	BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
-		     offsetof(struct thread_fp_state, fpr[32][0]));
+		     offsetof(struct thread_fp_state, fpr[32]));
 
 	return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 				   &target->thread.fp_state, 0, -1);
@@ -405,7 +405,7 @@ static int fpr_set(struct task_struct *target, const struct user_regset *regset,
 	return 0;
 #else
 	BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
-		     offsetof(struct thread_fp_state, fpr[32][0]));
+		     offsetof(struct thread_fp_state, fpr[32]));
 
 	return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 				  &target->thread.fp_state, 0, -1);

 

In theory if this works, you should be able to skip the compile of the 2.6.x kernel and finish your config and try starting up the NAS.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.