Updating my WD My Book Live

I have a Western Digital My Book Live, WD MBL, with a single 2TB disk that I wanted to update as the kernel and OS were over 5 years old. My aim was to use this a backup for my music collection that is currently hosted on my other NAS server, a ZyXel NAS520 with 2 1TB HDDs using Raid 1. I also wanted to transcode my music collection into several different formats and host them on the MBL instead of just the FLAC that is on my NAS.

After some googling, I found the OpenWrt project https://openwrt.org/toh/wd/mybooklive and decided to out their image. The first problem was that I had to take the HDD out of the MBL case. This is not easy but this video really helped:

Once I had the HDD out, I hooked it up to my PC using a HDD docking station, much easier than opening up my desktop and wiring it up directly. I installed the latest OpenWrt installation image, 18.06.4, following the excellent instructions on the OpenWrt site. I then took the HDD out of the docking station and reconnected it to the MBL circuit board and powered it up. The image worked just fine but I had forgotten that OpenWrt sets everything up like a router and I didn’t want that. So I tried to work out how to configure OpenWrt to not be a router and after a bit reading around, I realised that OpenWrt is not very standard so I could waste a lot of time working out how to set up the NAS the way I wanted.

After some more googling, I found this thread on the WD community site https://community.wd.com/t/any-interests-in-kernel-4-0-on-my-book-live/60483/. Debbie Jessie is a lot like Kubuntu that I use on most of my PCs so there was a minimal learning curve. A lot of the thread was about how to install Debian Jessie from scratch but later on, there was a series of posts from Ewald who had created his own distro and made it available to download and install. I think to myself, ‘Great, I’ll be done in a couple of hours!’ Famous last words! Many days later, I had something working and the following is a summary of what I learnt.

The boot process

There are a few key things to understand about the boot process on the WD MBL.

  1. U-Boot is installed in flash and cannot be changed without a lot of effort. This version of U-Boot can only boot onto ext2 or ext3 partitions and always uses /dev/sda1.
  2. U-Boot will use a script called boot.scr on the root of /dev/sda1 if it is present. This script can run any U-Boot commands but in this case it is told which kernel image to use, the kernel device tree file and where the root partition is.
  3. Once the kernel is running, it uses the /etc/fstab file to set up the partitions.

This is all basic stuff but you have to get everything right or nothing happens.

As I had previously installed OpenWrt, I had to re-partition the HDD to match what was expected by Ewald’s Debian Jessie distribution. Initially, I tried following the instructions here: https://github.com/ewaldc/My-Book-Live/tree/master/debian/debian%208%20(Jessie)#how-to-install-with-ext4-. If this had worked, I would have had a minimal boot partition using ext3 and the rest of the rootfs install on a much larger ext4 partition. However, I wasted an awful lot of time trying to make this work with no success.

I eventually opted for the ext3 only method described here: https://github.com/ewaldc/My-Book-Live/tree/master/debian/debian%208%20(Jessie)#how-to-install-a-combined-boot-and–with-ext2ext3. These instructions are fine but they rely on the disk being partitioned correctly which is not explained clearly. The following instructions show how I eventually made it work.

Installing the distribution

Once you know what you are doing, the installation is actually fairly straightforward and goes like this:

  1. Remove the HHD from the WD MBL.
  2. Attach the HDD to your PC.
  3. Partition the HDD.
  4. Create the file systems.
  5. Unpack the Debian Jessie image.
  6. Change the boot.scr file.
  7. Modify the /etc/fstab file.
  8. Attach the HDD to the WD MBL circuit board and verify that it boots and that you can connect using SSH.
  9. Re-assemble the WD MBL.
  10. Do all the basic tidying up that Ewald suggests.
  11. Customise as required.

Partition the HDD

When I tried de-bricking the WD MBL just I case I messed up, I successfully recovered the MBL. I then tried to find out what partitions were created by the factory image. There were several problems with trying to read the partition info and fdisk couldn’t do it. I found out that gdisk worked and after fixing the errors that it found, I was able to read the partition info (see below).

 Partition Table: 
 gptNumber  Start   End     Size    File system     Name     Flags
 3          15.7MB  528MB   513MB   linux-swap(v1)  primary 
 1          528MB   2576MB  2048MB  ext3            primary  raid 
 2          2576MB  4624MB  2048MB  ext3            primary  raid 
 4          4624MB  1000GB  996GB   ext4            primary

This is what is expected by the default /etc/fstab file but I wanted a bigger root partition so that I wouldn’t run out of space. I used gdisk to create the following partition table.

Number  Start (sector)    End (sector)  Size       Code  Name
    1            2048        20973567   10.0 GiB    8300  OS
    2        20973568      3904931982   1.8 TiB     8300  Data
    3      3904933888      3907029134   1023.1 MiB  8200  Linux swap

Set up the file systems

This is simply:

sudo mkfs.ext3 /dev/sdh1
sudo mkfs.ext4 /dev/sdh2

(/dev/sdh was where the disk appeared on my system). Once the file systems were created, they were automatically mounted on /media/andy.

Unpacking the tarball

Again this was pretty simple. Just make sure that you unpack the tarball on the correct partition. I used df -h work out which partition to use as this shows the mount points.

cd /media/andy/d8710e6e-34e8-4e59-bb19-74de7238a97d/
sudo tar xf /home/andy/software/WDMyBookLive/DebianJessie8.11.tgz

Set the right boot.scr file

Replace the /boot/boot.scr file with this one: https://github.com/ewaldc/My-Book-Live/blob/master/uboot/boot_ext3_sda1/boot.scr. It contains the following U-Boot commands:

setenv md0_args 'setenv bootargs root=/dev/sda1 rw rootfstype=ext3 rootflags=data=ordered ipv6.disable=1'
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

This file tells U-Boot which kernel to use, /boot/uImage, and passes a bunch of commands to the kernel, the most important of which is the path to the root FS, /dev/sda1.

Amend the /etc/fstab file

The /etc/fstab file in Ewalds Debian Jessie “distribution” looks like this:

/dev/sda1       /       ext3    defaults,noatime,nodiratime,barrier=1   0 0
/dev/sda3       swap    swap    defaults        0 0
/dev/sda4       /DataVolume     ext4    exec,rw,noatime,nodiratime,data=writeback,barrier=0,errors=remount-ro,suid      0 1
/DataVolume/cache       /CacheVolume    none defaults,bind 0 0
/DataVolume/shares      /shares         none defaults,bind 0 0
/DataVolume/shares      /nfs            none defaults,bind 0 0

The problem with this is that the swap and data partitions are not where the /etc/fstab file expects them to be but it was simple to fix. I simply edited the /etc/fstab file to change /dev/sda4 to /dev/sda2.

After that, I plugged the HDD into the WD MBL circuit board and tested the new system. It booted and I was able to SSH into the newly updated MBL. There was still a lot of work to do to clean up and get everything working and that will be in my next post.

Links

The following links might be useful.

Leave a comment