Disclaimer: do this at your own risk. No fancy web gui here, just raw unix power.
Requirements:
- a PC running Ubuntu 18 or similar… and some experience with unix.
- USB flash drive (8GB+)
- WD My Cloud PR2100/PR4100
If you’re lazy and in a hurry, skip the guide and go straight for the boot image at the end of the post.
Get KVM
sudo apt install qemu-kvm ovmf
Prepare a working directory
mkdir ubuntu && cd ubuntu
Copy the UEFI bootloader to a local file named bios.bin
cp /usr/share/ovmf/OVMF.fd bios.bin
Download the Ubuntu 18.04.1 server iso.
Find out the name of your USB flash drive with lsblk
. I’ll use /dev/sdX here.
Boot the iso installer.
sudo kvm -bios ./bios.bin -cdrom <path_to_iso> \
-drive format=raw,file=/dev/sdX -boot once=d -m 1G
It should mention TIANO CORE during boot and then enter a black grub screen to install Ubuntu.
Complete the installation with the defaults and any extra package that you may be interested in (e.g. Nextcloud).
Note down the user and password, you need it to login into the machine later.
At the end, it will reboot and ask you to remove the cdrom.
Just close the whole window to shutdown the whole virtual machine.
Then boot without cdrom straight from the USB flash drive.
sudo kvm -bios ./bios.bin -drive format=raw,file=/dev/sdX -m 1G
Login in the virtual machine and update packages if you like.
Networking
Ubuntu is now installed for a virtual network interface with the new udev persistent networking naming.
You’ll see the current network interface is called ens3
or similar.
ip addr show
This won’t work on actual My Cloud hardware.
Create the netplan configuration as follows
sudo editor /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eno1:
dhcp4: true
eno2:
dhcp4: true
This causes the NAS to get a dynamic IPv4 address on both of its onboard (eno
) interfaces.
Example with static IP and bonding
Here’s how to combine the throughput of the 2 network interfaces on a single static IP address.
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: false
optional: true
enp2s0:
dhcp4: false
optional: true
bonds:
bond0:
interfaces: [enp1s0, enp2s0]
addresses: [192.168.0.100/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
parameters:
mode: 802.3ad
mii-monitor-interval: 1
More info (static IP, bonding, …) on https://netplan.io
Hardware Control
Thanks to the research of Michael Roland and @dswv42 we now have full control over the fan, lcd, buttons and sensors. Ubuntu ships with the 8250_lpss
module, so you don’t need to build a custom kernel.
The PMC is accessible at serial port /dev/ttyS5
.
You need some packages from the universe
repo.
sudo add-apt-repository universe
git clone https://github.com/WDCommunity/wdnas-hwtools
cd wdnas-hwtools
sudo ./install.sh
The Ubuntu boot disk is now ready. Shutdown with
sudo halt -p
and plug the USB drive in the PR4100 NAS.
Boot up and enjoy!
Extras
Download example boot disk image
Download my image here, unzip (use 7zip on winwods) and burn to a 16GB+ flash drive.
Direct unzip and write with
cat foo.img.gz | gunzip | dd of=/dev/sdX
Login: wdnas
Password: mycloud
Warning: risk for data loss when using the wrong device
To grow the file system to use the complete usb boot drive, delete the second partition.
sudo sgdisk /dev/sdX --delete=2
Create it again, it will automatically use all available space.
sudo sgdisk /dev/sdX --new=2
Refresh the partitions
sudo partprobe
Now that the partition has been resized, you can grow the file system. This is done on the second partition /dev/sdX2, not on the disk /dev/sdX.
sudo e2fsck -f /dev/sdX2
sudo resize2fs /dev/sdX2
Create a new ZFS array
Here’s a great overview on the core features of ZFS.
Now let’s create a ZFS array on the PRx100.
Insert your disks (hotplug is allowed). List them.
wdnas@wdnas:~$ lsblk -d
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 86.9M 1 loop /snap/core/4917
loop1 7:1 0 89.5M 1 loop /snap/core/6130
sda 8:0 0 1.8T 0 disk
sdb 8:16 0 1.8T 0 disk
sdc 8:32 0 1.8T 0 disk
sdd 8:48 0 1.8T 0 disk
sde 8:64 1 14.3G 0 disk
mmcblk0 179:0 0 3.7G 0 disk
mmcblk0boot0 179:8 0 2M 1 disk
mmcblk0boot1 179:16 0 2M 1 disk
Here we see sde
is the USB boot disk.
Create a mirror pool over sda
and sdb
based on the Ubuntu Tutorial.
It’s recommended to name your pool media
.
sudo zpool create media mirror sda sdb
Alternatively, create a raidz pool over 4 disks. This is similar to a RAID5 pool, using 1 disk for parity.
sudo zpool create media raidz sda sdb sdc sdd
In order to use it, you need to create a file system (also called dataset) on the zpool. This is similar to a ‘share’ in the My Cloud OS.
Here’s an example
sudo zfs create media/pictures
The file system gets mounted automatically at /media/pictures.
or import existing data
SSH into My Cloud NAS running Ubuntu.
cat /proc/mdstat
sudo mdadm --assemble --scan
or if you used my FreeNAS image to create a ZFS array
sudo apt install zfsutils-linux
sudo zpool import
Follow the instructions.
It’s recommended to name your zpool ‘media’ so that the Ubuntu snap system can easily use it.
Prevent disks from spinning up every 10 minutes
Disable udisks2
Setup Nextcloud
I couldn’t explain it better than this Digital Ocean guide.
All data will be stored on the USB boot disk, which is not so interesting.
Here’s how to change the nextcloud snap data partition to your zfs pool.
First create a zfs dataset for nextcloud.
sudo zfs create media/nextcloud
Allow the nextcloud snap to use the zpool
sudo snap connect nextcloud:removable-media
Change the data path in /var/snap/nextcloud/current/nextcloud/config/autoconfig.php
sudo sed -i "s#'directory' => .*#'directory' => '/media/nextcloud/data',#" /var/snap/nextcloud/current/nextcloud/config/autoconfig.php
Restart nextcloud
sudo snap restart nextcloud.php-fpm
Now visit your nextcloud website and create the admin user.
Disable internal flash memory
If the internal flash memory is completely broken, you may be unable to restore the origal WD OS.
Installing Ubuntu is a solution, but you’ll see system freezes when polling the disks in the dmesg
output.
A solution is to blacklist the mmc_block
driver.
sudo editor /etc/modprobe.d/blacklist.conf
Add a line with
blacklist mmc_block
Then
sudo update-initramfs -u