How to Boot from a USB Stick

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.

7 Likes

This guide will be quite helpful to other Users in need. Thanks for sharing it.

I installed OMV (debian based) with a flash drive onto another flash drive.
The OMV grub bootloader is located in the /boot/grub directory instead /grub

I could modify the WD NAS grub to pick the OS on the USB drive, but maybe itā€™s better to create a symlink at /grub to /boot/grub. Any other tips before I go ahead?

Last night I loaded GRML, a debian based live system on my PR4100.
A live system lives in RAM memory so it doesnā€™t touch the WD flash firmware and doesnā€™t void your warranty.
You get a recent kernel, the apt package manager and a lot of handy tools, but the cooling fan whirling at full speedā€¦ Iā€™ll see what I can do about that.

Get a pendrive of at least 512MB.
Find the device name of the pendrive. Iā€™ll use /dev/sdX in this tutorial.

df

Format the pendrive and create a partition with a FAT32 filesystem.

sudo parted /dev/sdX

print mklabel msdos mkpart primary fat32 1M 100% set 1 BOOT ON quit

Change the partition label.

sudo fatlabel /dev/sdX USB_RESCUE

Download the grml64 iso of your choice. I chose the recent GRML prerelease.
Get grml2usb to install the iso.

sudo apt-get install grml2usb

As we can only do a headless install, weā€™ll add the SSH boot option with a password of your choice.
Install grml to the first partition of /dev/sdX as follows

sudo grml2usb --bootoptions='hostname=wdnas ssh=p1ck4s3cr3t' grml64-small-XXX.iso /dev/sdX1

Unmount and plug the pendrive in the NAS, then boot the NAS.
You can ssh into your box with your password, p1ck4s3cr3t in this caseā€¦

ssh root@wdnas

The full grml64 live ISO used only 500MB RAM of the 4GB present in the PR4100ā€¦

Another great Guide.
I havenā€™t tried it yet since I have couple of questions.
I understand itā€™s for testing, diagnosis, and recovery purposes. But Iā€™m thinking to modify the firmware for my needs and boot the modified firmware from USB.

  1. Can we persistently boot from USB? (possibly from SSD)
  2. Will there be any performance issues?
  3. For regular boot (without rescue), are uLmage and uRamdisk files sufficient?
  4. In which circumstances NAS can be bricked?

Best,

Well, the rescue firmware didnā€™t work (On the NAS led screen, it was saying ā€œFirmware update failureā€), but uImage, uRamdisk worked
I successfully boot from USB, changed the corrupted firmware, and now NAS works normal.

As you pointed out, USB boot can be used to test custom firmware to make sure itā€™s booting as expected.

Best,

There was no internet connection. It was saying ā€œFirmware update failedā€ on the led screen. Have you seen anything like that?

Current USB boot allows to update the kernel, and root level settings, but there are also WD config and modules, which are mounted from /dev/mmcblk0pX.
Have you figured it out how to by-pass those mounts so that config and other changes are possible without touching the original firmware?

I know you have a guide to update config.xml, but that may result to a brick nas.

Best

#This one need the mount from util-linux, busyboxā€™s one canā€™t handle LABEL
#echo ā€œinitramfs: mounting label=image.cfs partitionā€
#mount -t ext4 LABEL=image.cfs /usr/local/tmp
chk_image

Here is the code from GPL firmware, ramdisk/root/etc/rc.sh.
They commented out mount commands, but similar mounting has been done in ā€œchk_imageā€.
Have you tried mounting image.cfs from above commented code blocks? I think if itā€™s succefully, image.cfs can be mounted from USB Stick - just pointing to a USB partition or file inside the USB.

Hello there!
My PR2100 is not booting anymore - i dont know why acctually.
Maybe someone can help me hereā€¦

When i got the NAS i installed Debian on a 16GB USB Stick, then iā€™ve been in holiday two weeks.

when i came back the device didnt stared anymore correctly and it is not (!) booting from the installing USB Stick anymore, neither from the debian usb Stick (from the guide thread here), nor from any other USB Stick (i tried the rescue stick, a freenas stick and a grml stick)

i already tried to boot in the normal wd OS, making the 5s and 40s resetā€¦

in every case the NAS is not getting an IP Adress and i cannot ping it or access via SSH

EDIT:
OK, i just soldered a wire to the UART Port and connected it to my pc, over screen i came to the bios and was able to set my booting device to the USB Stick. The second option was some unknown device (i just connected the usb stick)ā€¦

could maybe someone upload the images of the original boot partition or can i find this online?

thank you for sharing but I have come across issues so far and just want to share. My unit is a DL4100 so not sure if that could be a reason but here are big ones:

1: The USB drive must have a GPT partition table and must have itā€™s boot flag set. That might have been implied but I saw the grub config set root and assumed it had to be msdos.
2: Because of this previous step, the grub config had to have a different set root location

set root=(hd1,gpt1)

also, DL4100 has hd0 enumerated for internal flash, where hd1 was the plug in usb drive.

3: I might have misread this but this got me tooā€¦

My DL4100 will only load with the bootx64.efi and grub.cfg in the /EFI/BOOT folder structure. I read the post as delete the folders and put all files all in the root. That didnā€™t work, but post above also shows the folder structure so it could be read as correct. I just wanted to clarify because this took me some timeā€¦

I have spent about 6 hrs on this **** box and I finally got the grub to pull the kernel and ramdisk. still a ways to go for a full minimal ubuntu or debian (my end goal)ā€¦

gotcha, the guide was very helpful and got me in a better direction for sure.

From my testing, 3 usb drives that are proven working if set to GPT and boot flags set. I couldnā€™t get any of them to work with MSDOS partition table, boot flags set or not.

The exact drives Iā€™m using are:
Kingston Datatraveler DT100/2GB (circa 2005) 2gb drive
HP v125/8GB (circa 2011) 8gb drive
Kingston Datatraveler DTSE9/64GB (circa 2016) 64gb drive

Is there a YouTube video that can help with this. The file attached did not contain Grub file.

I have a DL4100 too that just flashes blue power led and powers off then on in a vicious cycle. NOTHING seems to change that.

Could you clarify what you mean about setting a different root location? So what did you change or add in the grub.cfg file? I made the correct folder layout on my flash drive with partition set to GPT but then you also said to set boot flag. Since Iā€™m doing this in Windows 10 how am I supposed to do that? Thereā€™s option to make it bootable or active since my OS already did that on its disk.

Lastly, did you have the same problem with your DL4100 as I have (blinking blue power button led) and it kept recycling its power?

Naturally. Nice find. Youā€™re probably right. Thanks for sharing.

I received two units of the DL4100. One is dead (C2000 CPU issue it seems). The other one is still functioning. While experimenting to boot from an USB stick I discovered this thread. Which led to a question:

How does one get the DL4100 to boot from an USB drive?

After trying with several different USB sticks with multiple different images I discovered the DL4100 NEVER boots from any of them. What I did next was connect up the RS232 UART port to a console, this allowed me to enter the BIOS of the DL4100, which showed that the boot order (for HDD and USB devices) will always cause it to boot from the internal USB device and not any externally connected USB drive.
I had to manually reorder the USB device boot order (or select the ā€˜override boot deviceā€™ option) to have the DL4100 boot from my thumb drive. (Which booted fine and running ubuntu 22.04 now)

Is something wrong/non-standard with my DL4100? What procedure do other people use to get the DL4100 to boot from a USB stick who do not have access to the RS232 serial port to fiddle with the BIOS boot order device list???

Also: This particular guide mentions ttyS0 as the serial console, for my DL4100 itā€™s actually ttyS1 that needs to be configured in the grub.cfg