FooDeas / raspberrypi-ua-netinst

RaspberryPi (minimal) unattended netinstaller
ISC License
218 stars 45 forks source link

Implement booting from USB storage #5

Closed FooDeas closed 7 years ago

FooDeas commented 8 years ago

The installer should implement the new feature to install and boot from USB storage as described here: PI 3 BOOTING PART I: USB MASS STORAGE BOOT BETA

FooDeas commented 8 years ago

Important info from Raspberry Pi Forum:

..."program_usb_timeout" is non reversible written to OTP...

... Yes it's permanent otherwise it couldn't effect the bootrom, it readable in the otp_dump it's bit 24 up near the top of the range... ... new empty file called TIMEOUT on the sdcard (this triggers the same effect of setting the above extra delay without setting the OTP bit)

So if booting from MSD, the installer should create this file and stay away from other OTP bits than usb_boot_mode.

FooDeas commented 8 years ago

Functionality is given with 305196ca1b6614e57402812ef5b7f13cf9c92a78. This should be working as soon as the firmware package is updated by package maintainers.

Documentation is not completed yet.

thijstriemstra commented 7 years ago

Is there any documentation on how to do this?

FooDeas commented 7 years ago

You have to replace the bootcode.bin before and after the installation and set usbboot=1 in installer-config.txt. Have an extra look at the installer output belonging to the msd boot bit you might have to program once!

thijstriemstra commented 7 years ago

Ordered a PiDrive and will test this. Also, support for raspberrypi-ua-netinst in https://github.com/maxnet/berryboot would be nice. It uses a Qt front-end, maybe I can hack it a little. This page also mentions a 4GB swap can be created and used as RAM which sounds awesome.

FooDeas commented 7 years ago

You know, that you can use a simple USB flash drive, too?

thijstriemstra commented 7 years ago

True, but they're much slower and more expensive (this disk was 30 euros for 250GB). Benchmarks here: http://www.legitreviews.com/wd-labs-pidrive-314gb-hard-drive-review_180301/4

FooDeas commented 7 years ago

đź‘Ť

thijstriemstra commented 7 years ago

This should be working as soon as the firmware package is updated by package maintainers.

@FooDeas has it been updated, where to check? I just flashed my PiDrive with a raspberrypi-ua-netinst build but it's not booting without an SD-card..

FooDeas commented 7 years ago

It's still in beta. I'm testing if it is moved to stable from time to time. I'm pretty sure, it will be posted on the RPi Blog when the time comes.

thijstriemstra commented 7 years ago

Alright, too bad.

thijstriemstra commented 7 years ago

So according to this page the following steps are required:

Which I'll test now.

thijstriemstra commented 7 years ago

Rebooted and checked the output of OTP but this didn't return the expected result (17:3020000a):

$ vcgencmd otp_dump | grep 17:
17:1020000a

So I did the recommended branch update instead:

$ sudo BRANCH=next rpi-update
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 4.9.9-v7+
 *** depmod 4.9.9+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to 719eb18d040b53903f7083cef2ee9f92300a90ab
 *** A reboot is needed to activate the new firmware

And rebooted but still same result. Maybe it's because I'm using a RPi2 (the tutorial says it's for RPi3)?

Tried it on a RPi3 (with master branch, not next) and gives the same 17:1020000a.

According to this post: "however, I didn’t receive the correct output as stated (0x3020000a) but I decided to continue rather than investigate and as it turned out it made no difference to the outcome".

So I'm moving to the next step.

FooDeas commented 7 years ago

The first byte (0x10) has to contain the 1 on 3rd position (0b00100000). So you're right with 0x30....

The config.txt has to include program_usb_boot_mode=1 (this is needed only once). At this time, the bootcode.bin has to be already replaced from here. Do that by yourself. During the next boot, the OTP will get programmed.

Now vcgencmd otp_dump | grep 17: should return the 0x30....

thijstriemstra commented 7 years ago

completed the tutorial and my machine isn't booting from USB; most likely because of this otp_dump issue. Maybe I should hold off until it's officially supported..

FooDeas commented 7 years ago

It definitely works! Have you get the OTP setup working with my comment from above now? (I'm unsure, what you've meant with "tutorial"...)

It's a strong requirement - and works with RPi 3 only!

thijstriemstra commented 7 years ago

I meant this tutorial, I haven't used raspberrypi-ua-netinst for this yet; first I'd like to get it working without but this OTP returns the wrong nr. Will try with a raspberrypi 3 vs rpi2

FooDeas commented 7 years ago

Forget the RPi 2 - it only works with RPi 3:

Will it be possible to boot a Pi 1 or Pi 2 using MSD?

Unfortunately not. The boot code is stored in the BCM2837 device only, so the Pi 1, Pi 2, and Pi Zero will all require SD cards.

(Source from post 1 above.)

thijstriemstra commented 7 years ago

ah thanks, hopeful.

FooDeas commented 7 years ago

What I wrote here has to work definitely! I'm confident that you'll get it working, too.

(Stupid "Close and comment" button...)

thijstriemstra commented 7 years ago

Alright this is better (on RPi 3):

$ vcgencmd otp_dump | grep 17:
17:3020000a

And booting now works! Feels like it's running a lot slower though..

thijstriemstra commented 7 years ago

So raspberrypi-ua-netinst basically needs to:

Thoughts?

FooDeas commented 7 years ago

Everything else is already working! But I paused this topic because the main problem above - so at the moment the branch is a bit outdated (but should be mergable easily).

thijstriemstra commented 7 years ago

The problem is to keep them [start.elf and bootcode.bin] during a kernel (wheezy)/bootloader (jessy and above) update because they're not delivered by the raspberrypi.org packages yet. So they may be overwritten and your Pi stops booting until you replace them again...

I suppose this is something I can live with; I simply cannot update (the kernel using apt-get)? Until the next firmware branch is merged into master?

thijstriemstra commented 7 years ago

And what about these instructions: raspberrypi-ua-netinst does most of that right?

Create the boot and root file systems:

sudo mkfs.vfat -n BOOT -F 32 /dev/sda1
sudo mkfs.ext4 /dev/sda2

Mount the target file system and copy the running raspbian system to it:

sudo mkdir /mnt/target
sudo mount /dev/sda2 /mnt/target/
sudo mkdir /mnt/target/boot
sudo mount /dev/sda1 /mnt/target/boot/
sudo apt-get update; sudo apt-get install rsync
sudo rsync -ax --progress / /boot /mnt/target
FooDeas commented 7 years ago

Post 1: You can update, but you can't be sure that a reboot will work if the files got replaced. Post 2: The system will be installed directly on the target USB device. Nothing special to copy/move/config.

thijstriemstra commented 7 years ago

Also see https://learn.adafruit.com/external-drive-as-raspberry-pi-root/hooking-up-the-drive-and-copying-slash

FooDeas commented 7 years ago

Starting with the 2017-04-10 release of Raspbian there finally is some progress here! (see https://github.com/raspberrypi/firmware/commit/e44f66a9e4e41636634501a093f9a55ceefb46d6) I need some testing and will possibly release that in very few days.

FooDeas commented 7 years ago

OK - it's done! Checkout: ~d00f3c9900a989e0aaf1d6b692fc68bd6f2642a5~ 7ff846f086ffaffa1678633a157bfc704edb1be4

thijstriemstra commented 7 years ago

Awesome, will do!

FooDeas commented 7 years ago

Results?

thijstriemstra commented 7 years ago

Testing now with:

usbroot=1
usbboot=1
thijstriemstra commented 7 years ago

And it looks like it worked out of the box using a PiDrive. Nice work!

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       233G  1,8G  220G   1% /
devtmpfs        236M     0  236M   0% /dev
tmpfs           240M     0  240M   0% /dev/shm
tmpfs           240M  4,7M  236M   2% /run
tmpfs           5,0M  4,0K  5,0M   1% /run/lock
tmpfs           240M     0  240M   0% /sys/fs/cgroup
tmpfs           240M     0  240M   0% /tmp
/dev/sda1       128M   22M  107M  17% /boot
tmpfs            48M     0   48M   0% /run/user/1000
thijstriemstra commented 7 years ago
==================================================
raspberrypi-ua-netinst
==================================================
Revision d01fd04
Built on ma 11 sep 2017 23:47:54 CEST
Running on Raspberry Pi version 3 Model B
==================================================
https://github.com/FooDeas/raspberrypi-ua-netinst/
==================================================
Starting HWRNG... OK
Mounting boot partition... OK
Copying boot files... OK
Executing installer-config.txt...
OK

This OK shouldn't be on newline.

Searching for deprecated variables...

Checking if config.txt needs to be modified before starting installation...
  Setting HDMI options... OK
  Checking USB boot flag... OK
OK

This OK doesn't have a description.


Unmounting boot partition... OK

Network configuration:
  ifname = eth0
  ip_addr = dhcp
  online_config = 

Waiting for eth0... OK
Configuring eth0 with DHCP... 192.168.2.54
Set time using ntpdate... OK

Installation started at Mon Sep 11 22:39:11 UTC 2017 (UTC).

=============================================================================================
                                  !!! IMPORTANT NOTICE !!!
Because you are installing from SD card and want to boot from USB,
the system will POWERED OFF after installation.
After finishing the installation, you must REMOVE the SD card and reboot the system MANUALLY.

The installation will continue in 15 seconds...
=============================================================================================

This notice should be in the documentation as well (if it's not already). And there's a typo:

'the system will be POWERED OFF after installation.'

And later:

Configuring user 'foo':
    Adding user `foo' ...
    Adding new group `foo' (1000) ...
    Adding new user `foo' (1000) with group `foo' ...
    Creating home directory `/home/foo' ...
    Copying files from `/etc/skel' ...

None of these lines have an OK.