RPi 2 LE 8 : Set /storage and /var to USB flash drive

  • Installed LE 8 today and wanted to move locations of frequent disk writes away from the sd card and to a usb flash drive. I had a peek at fstab and it is empty (first time I have observed this in Linux). Flash drive is installed and recognised.

    My interest is to redirect /storage and /var to the flash drive - but what is the recommended approach with the LE architecture?


  • Easiest way would be to actually install LibreELEC to the USB drive.

    Not disputing your advice, in hindsight this could be best, but I've already installed it on the microsd - don't want to re-install now. With other RPi OS's I've followed the traditional method using fstab. But I got a shock when I opened fstab and found nothing there.

    Another possible method is to just put a symbolic link from the microsd to the flash drive although it is not what I would want to do.

    Wondering if this should be done by other means, the LibreElec way, such as, for example, altering autostart.sh or setting up a systemd device?

    By the way I am very very impressed with this distro.

  • The obvious ways are either, as vitorp07 suggests, to boot from usb (which has only recently become an option) or to boot from sd card but use a usb stick formatted to ext4 as a storage partition - that can be accomplished by editing cmdline.txt on the fat partition of your sd.


  • The obvious ways are either, as vitorp07 suggests, to boot from usb (which has only recently become an option) or to boot from sd card but use a usb stick formatted to ext4 as a storage partition - that can be accomplished by editing cmdline.txt on the fat partition of your sd.

    I've got an 8 gb microsd with LE 8 on it. For the moment all source is on this disk. Then there is an empty SanDisk Cruizer 32 gb usb formatted to ext4 (it is recognized but not used at the moment).

    With cmdline.txt is there a way to redirect just the storage directory to the usb or will the entire root have to be redirected?

  • I've got an 8 gb microsd with LE 8 on it. For the moment all source is on this disk. Then there is an empty SanDisk Cruizer 32 gb usb formatted to ext4 (it is recognized but not used at the moment).

    With cmdline.txt is there a way to redirect just the storage directory to the usb or will the entire root have to be redirected?


    Rather than write it again:
    thread-1456-post-12362.html#pid12362

    Bear in mind that will boot to an empty partition on your stick. But if you make a backup on your sd card you can restore that to your stick.

    Edit: other people will tell you to use UUIDs rather than labels. Up to you, it all works.

    Edited once, last by trogggy (February 25, 2017 at 10:25 PM).

  • Thanks Troggy - OK - I've tried to implement this but it breaks the TVHeadEnd 4.2 server.

    Here's the situation more explicitly; my default /flash/cmdline.txt contains:

    boot=/dev/mmcblk0p1 disk=/dev/mmcblk0p2 quiet

    I have a 32 GB USB (ext4) disk with the label TV-201702 mounted at /var/media/TV-201702.

    So here's what I did: 1) copy over the contents of /storage to the flash drive, 2) replace contents of cmdline.txt, and 3) reboot:

    Code
    # systemctl stop kodi
    # rsync -rtv /storage/ /var/media/TV-201702/
    # mount -o remount,rw /flash
    # nano /flash/cmdline.txt

    boot=/dev/mmcblk0p1 disk=LABEL=TV-201702 quiet

    Saved the file (ctrl-x y enter).

    Code
    # mount -o remount,ro /flash
    # reboot

    Now as I understand it, disk=LABEL=TV-201702 will become the data storage location - and sure enough checking the disks with df we find:

    /dev/mmcblk0p1 524008 141600 382408 27% /flash
    /dev/sda1 29766716 495272 27736316 2% /storage

    So far so good - but now there is no TVHeadEnd server.

    I've since reverted cmdline.txt back to default and rebooted - the TVHeadEnd server is working as before. I need to do some more investigation of this. There is no /storage/.hts subdirectory - the TVHeadEnd configuration must be somewhere else.


  • There is no /storage/.hts subdirectory - the TVHeadEnd configuration must be somewhere else.

    the userdata is at /storage/.kodi/userdata/addon_data/service.tvheadend42
    and the binaries are at /storage/.kodi/addons/service.tvheadend42

    you could run systemctl status service.tvheadend42 if it shows something crazy

    at /storage/.kodi/userdata/addon_data/service.tvheadend42/service.log you have the tvh log and you can look if there is happening something crazy

  • the userdata is at /storage/.kodi/userdata/addon_data/service.tvheadend42
    and the binaries are at /storage/.kodi/addons/service.tvheadend42

    you could run systemctl status service.tvheadend42 if it shows something crazy

    at /storage/.kodi/userdata/addon_data/service.tvheadend42/service.log you have the tvh log and you can look if there is happening something crazy

    Thank you CvH. Yes when I examined the initial /storage location I could not find the .hts directory. When I moved the /storage to USB and the tvheadend server did not start, I manually tried to start it - this led to an .hts directory being created under the new (usb) /storage location. There are no journal messages and there is no service.log created, even after I manually start it. The messages I have provided are those emitted (to stdout/stderr) to the console.

    When I point /storage to USB (/dev/sda1), the original disk is moved to /var/media/mmcblk0p2-mmc-00000_0xb8c813ec/. Are there libraries on that disk mount that tvheadend under /dev/sda1 cannot locate?

    I have tried your suggestion to do 'systemctl status service.tvheadend42' (which works under the original installation) but the message I get in reply is:

    Unit service.tvheadend42.service could not be found

    Doing just 'systemctl status tvheadend42' yields:

    Unit tvheadend42.service could not be found

    Any ideas? For example would a symlink to service.tvheadend42 as tvheadend42.service solve the problem?

    I've just compared the PATH env variable of both installations and they are identical: /usr/bin:/usr/sbin:/storage/.kodi/addons/service.tvheadend42/bin:/storage/.kodi/addons/virtual.network-tools/bin:/storage/.kodi/addons/virtual.rpi-tools/bin:/storage/.kodi/addons/virtual.system-tools/bin

    Edited once, last by csimai (February 28, 2017 at 4:03 PM).


  • I could not find the .hts directory

    there is no .hts folder, the stuff that is usually at these folder is at /storage/.kodi/userdata/addon_data/service.tvheadend42 <- this should be there

    I guess that systemd isn't aware of the different disk and the service.tvheadend42.service aren't created. Idk if this is intention or an bug.

    Btw I have no real idea why you want to use the USB Stick instead of the SD card as it has speed wise downsides (USB stick, network and DVB stick sharing the same lousy bandwidth).

  • there is no .hts folder, the stuff that is usually at these folder is at /storage/.kodi/userdata/addon_data/service.tvheadend42 <- this should be there

    I guess that systemd isn't aware of the different disk and the service.tvheadend42.service aren't created. Idk if this is intention or an bug.

    Btw I have no real idea why you want to use the USB Stick instead of the SD card as it has speed wise downsides (USB stick, network and DVB stick sharing the same lousy bandwidth).

    Thanks again. Yes I understand that there should not be an .hts and that there is a userdata folder instead (which I think is a better solution). I just wanted to identify my surprise that an .hts was created when /storage was moved. Sorry if I have belaboured the issue.

    I wanted to have the flexibility to add more storage capacity on the RasPi 2. It's not really for speed. Also there is some debate over the reliability and lifespan of USB vs MicroSD - I have recent experience of a MicroSD failing (16 GB Samsung Ultra - have just thrown it out) whereas the USB still chugs on. They were both on the same RasPi box for about 18 months.

    Thanks for your help CvH I hope this can be resolved now.

  • there is no .hts folder, the stuff that is usually at these folder is at /storage/.kodi/userdata/addon_data/service.tvheadend42 <- this should be there

    I guess that systemd isn't aware of the different disk and the service.tvheadend42.service aren't created. Idk if this is intention or an bug.

    Btw I have no real idea why you want to use the USB Stick instead of the SD card as it has speed wise downsides (USB stick, network and DVB stick sharing the same lousy bandwidth).

    CvH - I've made an enquiry [ thread-5672-post-37514.html#pid37514 ] as to documentation for systemd on LE8 - I don't yet understand how it works. A reply (Irusak) has indicated that there should be a symlink from /etc/systemd/system -> /storage/.config/system.d. My installation of LE8 does not have this link. Could this be the source of the problem?

    • Official Post


    Could this be the source of the problem?

    yes, but it is unclear why it is missing (you don't do there anything manually)

    btw you can use a sd card and just mount your USB stick to /storage/downloads/ or whatever, should reduce headaches a lot ;)

    btw the .hts was there because you started Tvh without the "special" start parameters and Tvh just behaves plain default -> creates .hts ...

  • Thanks - I will not make any changes to the system - but I think this symlink is somehow related. I'm not familiar with the LibreELEC 8 OS so I'm doing some 'brute force' investigation - for example grepping all files for anything that contains 'tvheadend' and brute force searches for all symlinks with 'system' in them, etc.

    It seems that it would be safe to redirect anything that is not a hidden directory (and lost+found) under /storage. But the .kodi directory will be subject to frequent writes and the /run directory appears to contain the system logs (journals) - so they are going to put some wear and tear on a less reliable MicroSD. I've just gone through a failed MicroSD (using another OS, not LE) but fortunately when I set up the system a year or so ago I redirected all data and logs to a USB drive - so I didn't lose any data.

    Under LE8, what would be the best way to redirect a /storage directory, say /storage/videos; by fstab or by symlink? You see, with /flash/cmdlne.txt (and the related init scripts - a very clever implementation actually), I don't understand when fstab will be of use (if at all) ...


  • But the .kodi directory will be subject to frequent writes

    Not really that problematic, wear and tear isn't really a problem these days for SD Cards (at LE). USB Sticks aren't better for this purpose. The only file that is written frequently is kodi.log iirc.


    by fstab or by symlink?

    with udevil you can mount some stick to anything you like (besides /storage/ ) - pls don't ask me about udevil because I really never use it ;D (wiki for this is missing :( )


  • So here's what I did: 1) copy over the contents of /storage to the flash drive, 2) replace contents of cmdline.txt, and 3) reboot:

    Code
    # systemctl stop kodi
    # rsync -rtv /storage/ /var/media/TV-201702/
    # mount -o remount,rw /flash
    # nano /flash/cmdline.txt

    Unfortunately your rsync line does not copy all content, i.e. symlinks are skipped.

    I recommend wiping the USB disk and retry with

    Code
    rsync -a /storage/ /var/media/TV-201702/

  • Unfortunately your rsync line does not copy all content, i.e. symlinks are skipped.
    I recommend wiping the USB disk and retry with

    Code
    rsync -a /storage/ /var/media/TV-201702/

    Thank you mglae - I'm happy to report that this works! For future reference, given a USB disk with label TV-201702, here are the steps that have worked (assuming that the destination is a newly formatted ext4 disk - otherwise wipe it clean first):

    # systemctl stop kodi# rsync -av /storage/ /var/media/TV-201702/# mount -o remount,rw /flash# nano /flash/cmdline.txt

    In my case, given a clean EXT4 formatted usb disk labelled TV-201702, change disk=/dev/mmcblk0p2 to:

    boot=/dev/mmcblk0p1 disk=LABEL=TV-201702 quiet

    Save the file (ctrl-x y enter). Then:

    # mount -o remount,ro /flash# reboot

    Checking the result after reboot, do:

    # dfFilesystem      . . .  Mounted on ./dev/mmcblk0p1  . . .  /flash/dev/sda1       . . .  /storage . . ./dev/mmcblk0p2  . . .  /var/media/mmcblk0p2-mmc-00000_0xb8c813ec

    That checks. Then do:

    # systemctl status service.tvheadend42service.tvheadend42.service - TVHeadend42 Service   Loaded: loaded . . .   Active: active (running) . . .  .  .  .

    Done!

    Edited once, last by csimai (March 1, 2017 at 5:03 PM).