This guide will demonstrate how to boot the NAS from a USB stick for testing, diagnosis and recovery purposes. No modifications to the NAS or its firmware are required.
WARNING: THE FOLLOWING PROCEDURES MAY VOID YOUR WARRANTY OR BRICK YOUR NAS - USE EXTREME CAUTION AT ALL TIMES
NOTE: BASIC LINUX SKILLS AND ROOT ACCESS VIA SSH ARE REQUIRED
Each of the Linux command examples shown below is preceeded with "# " (no quotes). This indicates a command prompt with root access. If copying/pasting a command, do not copy/paste the "# " portion of the example.
The following instructions are based on the WD My Cloud PR4100 NAS firmware, but they may be applicable to other WD My Cloud models, possibly with minor variations applied as needed.
Format a USB stick using the Fat32 filesystem and change its volume label to USB_RESCUE.
Download a copy of the My Cloud PR4100 GPL Source Code and extract the following files.
/WDMyCloud_PR4100_GPL_v2.30.165_20170321/firmware/merge/grub.tgz
/WDMyCloud_PR4100_GPL_v2.30.165_20170321/firmware/merge/uImage
/WDMyCloud_PR4100_GPL_v2.30.165_20170321/firmware/merge/uRamdisk
Extract the contents of the grub.tgz file.
/grub/EFI/BOOT/bootx64.efi
/grub/EFI/BOOT/grub.cfg
/grub/startup.nsh
Edit the grub.cfg file and replace its contents with the following.
set default="0"
set fallback="1"
set timeout="5"
set kcmdline="acpi_enforce_resources=lax net.ifnames=0 console=ttyS0,115200n8"
menuentry "USB Test Firmware" {
Alpha_CRC32_Reset
search --no-floppy --set=root --label USB_RESCUE
Alpha_CRC32_Check /uImage /uRamdisk
linux /uImage ${kcmdline}
initrd /uRamdisk
}
menuentry "USB Rescue Firmware" {
Alpha_CRC32_Reset
search --no-floppy --set=root --label USB_RESCUE
Alpha_CRC32_Check /uImage-rescue /uRamdisk-rescue
linux /uImage-rescue ${kcmdline}
initrd /uRamdisk-rescue
}
Copy uImage, uRamdisk and the contents of the grub folder to the root of the USB stick as follows. Do not copy the grub folder, only its contents.
/EFI/BOOT/bootx64.efi
/EFI/BOOT/grub.cfg
/startup.nsh
/uImage
/uRamdisk
The bootx64.efi file is the GRUB bootloader, which is configured by the grub.cfg file. The startup.nsh file is a script, which automatically runs every time a bootloader shell environment is opened. The uImage file is the Linux kernel, and the uRamdisk file is the initial RAM filesystem.
At this point, the first GRUB menu entry will be sufficient to boot a Linux kernel and initramfs for testing purposes. However, the NAS firmware also requires a SquashFS file named image.cfs to load the primary root filesystem, which is currently loaded from NAND flash memory. Loading the image.cfs file from the USB stick is possible, but knowledge of the firmware build process is required.
If the NAS fails to boot from USB, try using a different USB flash drive. In some cases there may be certain hardware incompatibilities which can cause it to fail to boot properly. In my experience, small inexpensive USB flash drives tend to work best for booting purposes.
To enable the rescue firmware functionality contained in the second GRUB menu entry, one must first copy the rescue firmware from the NAND flash partition using SSH.
To determine which NAND flash partition contains the rescue firmware, execute the following command.
# blkid -o list
Look for the device with an entry labeled wdnas_rescue_fw and note the device path. The path is /dev/mmcblk0p5 for the PR4100 NAS.
Next, create a folder named rescue_firmware on the Public share and copy the contents of the rescue firmware partition by executing the following commands, one at a time.
# mkdir /tmp/rescue_firmware
# mkdir /shares/Public/rescue_firmware
# mount -t ext4 /dev/mmcblk0p5 /tmp/rescue_firmware
# cp -Rf /tmp/rescue_firmware/* /shares/Public/rescue_firmware
# umount /tmp/rescue_firmware
# cd /shares/Public/rescue_firmware
# ls -l
Close the SSH connection, and browse to the Public share using the local network. Copy the rescue_firmware folder to the local computer and rename the uImage and uRamdisk files as follows.
uImage --> uImage-rescue
uRamdisk --> uRamdisk-rescue
Copy the uImage-rescue and uRamdisk-rescue files to the root of the USB sitck, then shut down the NAS and insert the USB stick into one of its USB ports. Power on the NAS and it should now boot from the USB stick.
To verify that the rescue firmware is booting properly, remove or rename the uImage and uRamdisk files, which will cause the GRUB bootloader to default to loading the rescue firmware (uImage-rescue and uRamdisk-rescue) from the USB stick. After the NAS has finished booting, simply enter its IP address in a browser, which should then display a āSafe Modeā prompt. Note: The firmware is not corrupted as the āSafe Modeā message indicates, itās programmed to say that.
To return the NAS to normal operation, simply hold the power button until it shuts down, then remove the USB stick and press the power button again.
To view the boot process from the serial console, please refer to the instructions contained in the following thread.