MyBookLive: Fresh installation of Debian 7

This guide will step you through the process to install Debian 7 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

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 where at in the processes did it restart!

You need to be able to connect to the hard disk and therefore you must open the MyBookLive case. There’s a nice video 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 run into major problems it is also very helpful to attach a serial converter to debug the boot process. Again you can search online to find out more information about this.  Otherwise you can connect the drive to your computer to look at the logs and figure out where the problem is during boot up are.

Partition the hard disk

Partition your hard disk with GPT partition table e.g. using parted or gparted if you have the gui installed.

I created a 10 Gb EXT3 disk 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.

Note:
 The actual drive letter of the hard drive might be different based on the amount of other hard drives you have connected to your system. Just substitute the drive letter in the commands below.

user@debian:~$ sudo parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart
Partition Name? []? (optional, I entered OS just for reference)
File system type? [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.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 debootstrap

If you didn’t follow the first guide on setting up your Virtual Machine, then you will need to complete the following command. If you setup your Virtual Machine using the guide, then you can skip this next command and move on to the mounting of the partition you just created.

Install debootstrap and a few other packages

user@debian:~# sudo apt-get install parted 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.

The directory “mbl” used below is just an easy reference, you can make the directory whatever you’d like. But I found this to be the easiest because it is short. You will be using the path a LOT! So if you decide to use a different directory name, just use it in place of the “mbl” that is used throughout this guide.

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

Bootstrap the base system

This will load the debian OS to the hard drive

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

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

Extract the Debian OS

To extract the OS you will CHROOT, or run the OS in a jailed environment.  For chroot to work correctly 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 -t devpts devpts /mnt/mbl/dev/pts/
user@debian:~$ sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot /mnt/mbl /debootstrap/debootstrap --second-stage

You will eventually get a “Base system installed successfully”.

Trigger post install scripts

There are some final scripts and actions that need to run after the base system is installed.

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

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

Change the MyBookLive hostname

Your new system will assume the name from the computer that you used to build the OS for the MyBookLive. For example I named my virtual machine installation “debian” so looking at the hostname file on the new system will show the same hostname.

user@debian:~$ sudo vi /mnt/mbl/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.

Mounting dev and proc:

This step is needed for the next steps to work properly

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

Chroot into the new system

This command will launch a CHROOT environment of your new OS allowing you to interface with the new system as if it was currently running.  This is very important!!!

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

Change the 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

(I have not needed to do this step during the installation of Wheezy, this has to be done for Jessie. But I left it here for reference just in case!)

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:

PermitRootLogin prohibit-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:/boot/kernel# apt-get install ca-certificates build-essential uboot-mkimage ncurses-dev unzip git

You will see a warning scrolling through near the end, it will go on for a while. Just let it go, this has to do with the certificates being installed. Since when are in a jailed environment I suspect that is the reason for the failure.

Download and patch the kernel

So I am going to put this information out there right away. I don’t know what is done differently on the kernel for the original OS for the MyBookLive to allow the mounting of a large partition but I have found that if you compile the kernel 2.6.32-65 as listed below you will NOT be able to mount a large partition. I have the 3TB MyBookLive and when it is all said and done I have about a 2.9TB partition for storage. So if you have a smaller MyBookLive hard drive, then you might be able to use kernel 2.6.32-65. I will list out the directions to compile a 4.0.x kernel as I have found files to compile kernel 4.0.x and has worked quite well!  I suggest compiling 2.6.32-65, finish all the steps and then compile the 4.0.x kernel using the steps at the end of this guide.  I think in my testing it didn’t work too well to compile the 4.0.x kernel now.

Steps to compile kernel 2.6.32-65

root@debian:/boot/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:/boot/kernel# wget https://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.32/linux-2.6.32.65.tar.xz
root@debian:/boot/kernel# xz -dc linux-2.6.32.65.tar.xz | tar -x
root@debian:/boot/kernel# cd linux-2.6.32.65
root@debian:/boot/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:/boot/kernel/linux-2.6.32.65# make distclean
root@debian:/boot/kernel/linux-2.6.32.65# make mrproper
root@debian:/boot/kernel/linux-2.6.32.65# make 44x/apollo_3G_nas_defconfig
root@debian:/boot/kernel/linux-2.6.32.65# make uImage

about three hours later…

Copy the kernel image to its new location

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

UBoot Configuration

Create boot.cmd with following content, you can use your favorite editor I use VI.

root@debian:/boot/kernel/linux-2.6.32.65# vi boot.cmd

You will be generating a new file, enter the following lines into that file.

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

Save the file and quit your editor

Convert to binary bootloader config

root@debian:/boot/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:/boot/kernel/linux-2.6.32.65# cp boot.scr /boot/

Changes to INITTAB

Edit inittab

root@debian:/boot/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 speed (baud) 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 statically assigned an address to my device.

root@debian:/boot/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 IPv4 and/or IPv6 name server entries. I would go ahead and update your entries to IPv4.

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

Change out the nameserver lines to your favorite DNS servers.  If you already have a DNS server on your network then you can substitute that in place of the OpenDNS servers

nameserver 208.67.222.222
nameserver 208.67.220.220

Save the file and quit the editor

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

root@debian:/boot/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.

Save the file and exit the editor

root@debian:/boot/kernel/Linux-2.6.32.65# exit

This will take you out of the chroot environment for the next step.

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.

(Optional) Compile 4.0.x kernel

These are the steps for kernel 4.0.x which will be performed from an SSH session

root@yourservername:/# cd /boot/kernel
root@yourservername:/boot/kernel# git clone https://github.com/MyBookLive/kernel-4.0.x.git
root@yourservername:/boot/kernel# wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.0.2.tar.xz
root@yourservername:/boot/kernel# xz -dc linux-4.0.2.tar.xz | tar -x
root@yourservername:/boot/kernel# cd linux-4.0.2
root@yourservername:/boot/kernel/linux-4.0.2# patch -p1 -i ../kernel-4.0.x/01_mbl.patch
root@yourservername:/boot/kernel/linux-4.0.2# patch -p1 -i ../kernel-4.0.x/02_ppc4xx_ocm_enable.patch
root@yourservername:/boot/kernel/linux-4.0.2# patch -p1 -i ../kernel-4.0.x/03_enable_leds.patch
root@yourservername:/boot/kernel/linux-4.0.2# patch -p1 -i ../kernel-4.0.x/04_enable_button.patch

Building and installing kernel

Kernel building steps

root@yourservername:/boot/kernel/linux-4.0.2# make distclean
root@yourservername:/boot/kernel/linux-4.0.2# make mrproper
root@yourservername:/boot/kernel/linux-4.0.2# make 44x/apollo_3G_nas_defconfig
root@yourservername:/boot/kernel/linux-4.0.2# cp ../kernel-4.0.x/config_mbl .config
root@yourservername:/boot/kernel/linux-4.0.2# make uImage

about three hours later…

Copy the kernel image to its new location

root@yourservername:/boot/kernel/linux-4.0.2# cp arch/powerpc/boot/uImage /boot/

Reboot the unit and upon startup the new kernel should be loaded.

 

After successful startup of the MyBookLive you are free to customize the OS anyway you like.

 

Enjoy!

12 thoughts on “MyBookLive: Fresh installation of Debian 7”

    1. I don’t have a DUO to try this with. I would have to go back through a few of the different sites I used to make this to see if it does.

  1. Hi Aaron! Thanks for sharing this excellent tutorial, by far the most clear guide I could find. I noticed you added the info about compiling a 4.x kernel, but can’t seem to find a tutorial to do a fresh install of Jessie (or maybe even Stretch?). I did find a post mentioning it would be ‘coming soon’, the instructions to install Jessie. Am I overlooking something or did you never get around to it? If so, I’m defintely still interested! Best regards, Marco

    1. Hi Marco. I had started tinkering with this before I started school. I haven’t had a chance to work through loading other versions of Debian yet. I need to look into it soon as I have found that I can no longer update the system. I will post those instructions once I get them completed.

  2. I think I found one minor typo in the instructions above. When extracting the device tree blob from the firmware, I guess it should be done with sudo, ie. sudo dpkg –extract apnc-024310-048-20150507.deb ./os, because ‘user’ has insufficient permissions to create the directories needed to extract the package and the newly created directory ./os remains empty otherwise.

    If you have time, could you please answer my previous answer about installing Jessie instead of Wheezy? Can I just edit /etc/apt/sources.list and run apt-get update && apt-get dist-upgrade or is there more to it? Please advice. Thanks again! Best regards, Marco.

    1. I guess I need to back everything up and run through my steps and see what I did. My NAS as it sits right now is on Debian 8 (Jessie), I am not sure if I did an upgrade via apt-get or if I had worked through the steps of a fresh install of Debian 8, got it working and just didn’t publish the post of how to get a fresh install of Debian 8 done. I have a pending post for it, but I’m thinking I wanted to go through all of the steps again as written to make sure all worked fine before I published it, but like I said in the previous comment I started playing with this before I started school so I had time to experiment with it. Hopefully once I wrap up school in the next couple of months I can get back to this.

  3. Some more feedback: when extracting apnc-024310-048-20150507.deb to ./os, I couldn’t find apollo3g.dtb. I figured it would be in inside ./os/CacheVolume/upgrade/rootfs.img and it was. So I did
    root@debian:/home/user/os/CacheVolume/upgrade# mkdir rootfs
    root@debian:/home/user/os/CacheVolume/upgrade# mount -o loop rootfs.img ./rootfs
    root@debian:/home/user/os/CacheVolume/upgrade# cd rootfs
    and found apollo3g.dtb inside the mounted rootfs.img in the boot directory.
    I copied apollo3g.dtb:
    root@debian:/home/user/os/CacheVolume/upgrade/rootfs/boot# cp apollo3g.dtb /mnt/mbl/boot/ (and made a local copy for future use…)

    Now unmounting and crossing fingers…

  4. Rebooting went fine, but unfortunately I wasn’t able to mount my 1.9Tb data partition with the 2.6.62.35 kernel. Every time I tried, mount said the file was too big. I compiled a more recent kernel (found here: https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.1.39.tar.xz) which is the most recent kernel apparently tested with the MBL patches here: https://github.com/MyBookLive/kernel-4.0.x. Now it mounts fine. The only thing I missing in the tutorial is configuring fstab to make sure swap and data partition are mounted automatically. Following the instructions above I only get rootfs mounted. Other than that this tutorial is (nearly) perfect. Thanks Aaron!

    1. I’m going to make note of this issue in the instructions above. I think I hit the same issue before but I had just moved straight into compiling the 4.x kernel as you noted.

  5. For those interested, I’ve set up the following fstab and now everything gets mounted automatically at boot. Make sure you replace the UUID’s with your own (use blkid) and the mountpoint /mnt/data.

    # /etc/fstab: static file system information.
    #
    # Use ‘blkid’ to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    #
    # /dev/sda1
    UUID=45b5a0cc-0b9b-42fe-95b5-f68fac8bb920 / ext3 errors=remount-ro 0 1
    # /dev/sda2
    UUID=f5d4220f-9887-47b7-b975-42651c907043 /mnt/data ext4 defaults 0 2
    # /dev/sda3
    UUID=57011691-2706-4d44-ac8d-342a339cffdf none swap sw 0 0

    So, for now, the only question remaining is how to upgrade to Jessie without issues…?

  6. Hi Aaron, thanks for taking the time to reply. I’ve managed to upgrade to Jessie in the meantime (decided to just take a shot at it) using your instructions to install Wheezy, combined with other tutorials on the web. I did compile a newer kernel and performed an apt-get dist-upgrade after changing sources.list to the jessie repositories, which went fine. I have two 2TB My Book Lives, so I will try your instructions to do a fresh install on the second one, which is currently not yet in use. The first one is now being completely up to date with Jessie (allthough still on a 4.1.39 kernel, which seems to work just fine) and it’s running stable as a remote rsyslogd server for the entire network. Will soon try to install Logstash, Elasticsearch and Kibana to see if it’s able to run this on it’s 800Mhz CPU, for monitoring logs. Thanks again!

  7. Pingback: Updating my WD My Book Live | Andy's Blog

Leave a Reply

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

Scroll to Top