RPi4 - prevent boot from specific USB HDD

  • I'm still trying to understand why my 6TB USB HDD became corrupted twice. I think the first time was because I hadn't powered up the drive before turning the Pi on. I have a theory that the second time could have been caused by the Pi trying to boot from the 6TB HDD rather than the 128GB SSD even though the 6TB drive was powered up.

    I don't think its going to be possible (tried googling but haven't found anything to support the idea) but I'd like to be able to say to the Pi - "you can boot from the SSD but not the HDD" by USB port, disk name or anything. Is there a way?

  • your thought/theory are unlikely

    the most against your thinking was declared in the other thread (closed cause of "layer 8 problem" on both ends).

    again:

    mostly a filesystem gets corrupt when the drive is disconnected while being in use/mounted (e.g. hard power cut).


    against the "boot theory" and for the "dear Pi don't boot my external drive":

    usually LE is configured where to boot from during LE installation.

    with the UUID's form the disk what is attached during installation.

    in an LE terminal the command

    dmesg|grep "Kernel command line:"

    will show what UUID's are involved.

    there are usually two entries (from my sata ssd):

    - boot=UUID=...

    and

    - disk=UUID=...

    what UUID belongs to what partition/disk is shown by the command "blkid"

    long story short:

    I'm not aware off by only attaching an external disk would change the above entries where to boot from !

    - that changes need more work -

    therefore I'm - for the main part - NOT convinced that the external disk is bootable at all and if it would somehow, with the lack of needed boot files you would see an error message only (unable to boot from ... or such ), but it wouldn't corrupt the filesystem.

    ===

    to boot from a disk you additional need the disk marked as bootable (don't know if that is still true with EFI !)

    if you only partitioned and formated your external disk this bootable flag is usually NOT set (unsure).

    there are some tools (fdisk, parted, etc.) out there to see and change the boot flag.

    !!! playing with those tools could damage partitions !!!

    parted is available on LE.

    please read the help files/manuals for parted, e.g. "man parted" => internet

    there the "print" command and how to find out if a external disk IS bootable or NOT

    my LE internal and bootable sata ssd:

    ...

    1 4194kB 541MB 537MB fat16 System boot, legacy_boot, esp

    ...

    Edited 4 times, last by GDPR-7 (August 21, 2022 at 5:06 PM).

  • "your thought/theory are unlikely"

    Agreed, but it is the best fit I have to the facts I know

    "against the "boot theory" and for the "dear Pi don't boot my external drive":

    usually LE is configured where to boot from during LE installation.

    with the UUID's form the disk what is attached during installation."

    OK, but all I could find while searching was you can toggle between SD card & USB device as the first one to look at. What I have no idea about and why I thought disabling boot from specified disks is what happens if LibreElec starts its boot from SSD and then tries to spin up the HDD and fails? I know the Pi will close down but I have no idea what else its doing.

    "mostly a filesystem gets corrupt when the drive is disconnected while being in use/mounted (e.g. hard power cut)."

    We do get the occasional power cut or voltage fluctuation in the Highlands (not as many as I expected when we moved up here though).

    The RPi4 is connected to a 128GB SSD for boot and a 6TB HDD for source (videos, records). The 6TB HDD should not be written to unless I carry out a media export and I do not recall ever seeing a disk / memory stick corrupted simply by unplugging unless it had been written to and items not flushed to disk.

    OK my experience is primarily Windows based so Linux / LibreElec may be different.

  • Booting is handled by the bootloader in the RPi's EEPROM.

    You can configure where to boot from (SD, USB, network) and then it'll search on these devices for a FAT partition (on SD/USB) containing firmware files (http://start.elf/fixup.dat).

    So if you don't have a FAT partition on your 6TB the RPi won't boot from it - the bootloader will scan through the USB devices and spin it up though (to read the partition table).

    cmdline.txt on the boot partition then determines which partitions LE should use for boot/flash (pointing back to the boot partition) and storage - by default these will be the ones from your LE installation (eg on SSD).

    During bootup LE will then scan for all USB devices and mount all partitions (except boot/flash and storage, which are already mounted) in /var/media so you can access them - here your 6TB HDD will get mounted.

    so long,

    Hias

  • Hias

    Thanks for that. The 6TB HDD did have an extra partition on it (can't remember how it was formatted) but it was rapidly removed with Mini Tool Partition Manager and the whole thing formatted to NTFS.

    Your's and Joe's comments pretty much destroy my theory. I'll just have to hope it doesn't recur.

    Edited once, last by LybsterKodi (August 22, 2022 at 3:31 PM).

  • I completely overread it's an RPi....

    Your's and Joe's comments pretty much destroy my theory. ...

    well, not complete, if the main question was: what causes FS corruption !

    why "not complete" ?

    cause of this:

    During bootup LE will then scan for all USB devices and mount all partitions (except boot/flash and storage, which are already mounted) in /var/media so you can access them - here your 6TB HDD will get mounted.

    so to prevent FS corruption you need to do either

    - shutdown the RPi (system shutdown will unmount all mounted disks for you)

    or

    - in an terminal run "umount /var/media/*" or better "sync && sync && umount /var/media/*"

    before unplugging the disk.

    to iterate:

    a FS gets corrupt when a disk gets unplugged or a power cut, while the FS/disk is in use.

    and "being mounted" translates to being "in use", here.


    Edited 3 times, last by GDPR-7 (August 22, 2022 at 5:12 PM).

  • so to prevent FS corruption you need to either

    - shutdown the RPi (system will umount all mounted disks)

    or

    - in an terminal run "umount /var/media/*" or better "sysnc && sync && umount /var/media/*"

    before unplugging the disk.

    Or just use the "remove media" option from the context menu in the video files view.

    so long,

    Hias

  • Joe

    "a FS gets corrupt when a disk gets unplugged or a power cut, while the FS/disk is in use.

    and "being mounted" translates to being "in use", here."

    WOW! To my Windows centric eyes that seems like a major design flaw.

    Hias

    "Or just use the "remove media" option from the context menu in the video files view."

    I knew it was there but assumed that I'd need to recreate the source and re-scan to the database. I've obviously misinterpreted as I did with EXPORT for videos.