Project

General

Profile

Recordings disappearing after rebooting TVH box (Ubuntu).

Added by Paraic McDonagh 26 days ago

I just wanted to share this with anyone that may be experiencing the same or a similar issue as myself.

The problem was that my recordings were disappearing from my TVH client's 'Recordings' list in Kodi whenever I rebooted the box that is running my tvheadend server.
However the recording files still existed on the drive in my 'Recorded TV' folder and they would play if directly opened in VLC player, but TVHeadend had lost track of them somehow.
I thought it was a corruption of some recording database or other. The missing recordings were all listed in the PVR 'Removed Recordings' tab of the TVH configurator.
The reason given was 'File Missing'. Odd, since the files were obviously where they should be.
In my case the server is an Ubuntu box but this solution can apply to other setups.

The root cause turned out to be a boot timing issue. The TVHeadend service was already started before the drive with my TV recordings had mounted.
TVH couldn't see my recordings when it started because of this, and it assumed that they had been deleted (or whatever). Additionally, TVH server doesn't seem to rectify this situation even after the drive has mounted, and so the recordings would never reappear. I eventually figured this out as a result of realising that issuing "sudo service tvheadend restart" in a terminal window would cause the Recordings to reappear where they should be, in 'Finished Recordings' and therefore also in Kodi.

The solution is to somehow delay the tvheadend service from starting, until the drive with my TV recordings is mounted. In my case, this was a separate internal drive dedicated solely to TV Recordings (and the TV buffer).
It happened to be formatted under windows as NTFS, but this shouldn't affect things, although it may explain why mounting is a little slow.

The mounting of drives and starting of services, is managed as 'units' by systemd. This is useful, because the sequence of these events can be managed under one umbrella.
To prevent the tvheadend service from starting before a specific drive has mounted, you need to edit the tvheadend.service unit override configuration using systemctl.
To do this, open an interactive session (a root session) in terminal.

sudo -i

Then type:
# systemctl edit tvheadend.service

(The hash symbol above is the root prompt, you don't type that bit). An editor will open with an empty configuration file.
It will be named something like /etc/systemd/system/tvheadend.service.d/.#override.confbe8889bcd33b05d2
You should copy the following 2 lines into the file:
[Unit]
RequiresMountsFor=/mnt/Multimedia

Then press 'Ctrl' + 'O' followed by 'Ctrl' + 'X' to save the changes and exit the editor.
In my case the path to my recordings is '/mnt/Multimedia/Recorded TV" Where 'Multimedia' is the drive we want to check for mounting. You can adapt this line for your own setup.

Note: The path should point to the drive and not a folder or sub-folder on it.

You can adapt this general idea to delay the starting of the tvheadend service until other dependencies are available, such as other services, mounts or devices.
Hope this helps someone!


Replies (11)

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Janne Kollin 24 days ago

Hi Paraic,

thank you for good description of the issue. My son and I are completely newbies what comes to Linux environment and method is learn by doing/reading, our main environment have been so far in WIN10.

Now when we decided to do project together by building RPI3+ entertainment center with live TV capability we have had interesting journey or learning:)

Our setup is following:
  1. RPI3+ board
  2. Noobs installation (Multiboot Raspbian strecth, LibreElec9 and OSMC boot from SD card)
  3. Suptronics X830 expansion board with 3,5" 8Tb Toshiba X300 HDD attached (where RPI is attached on top of the board)

We actually had difficulties with HDD partitioning in RPI and only way was to use WIN NTFS partition as you described as well, this cause similar behavior as you experienced THV service is starting before HDD is mounted. After boot and restarting TVH service recordings becomes visible.

To do the same what you did in LE was slightly different (just writing those down here if that helps LE users):

1. Connecting with terminal to RPI (putty where actually SUDO is not needed since you already are as root user)
2. Running command systemctl edit service.tvheadend42.service(due TVH server is version 4.2)
3. Input lines in editor as you instruction says [Unit]
RequiresMountsFor=/mnt/Toshiba
4. System generated this temp file in the path you explained and CTRL+O was writing lines in that temp file .#override.confdf1ee7222b2dc6e
5. CTRL+X exits from editor and temp file contents were copied to file override.conf (We were checking that lines really were there)
6. Rebooting RPI

But still TVH service starts before HDD and latest recordings dissapear in insert seems not work as it should..
What we are missing in here and clue?

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Mark Clarkstone 23 days ago

Janne Kollin wrote:

...

Just to add, I saw this post and created a PR to try and avoid this with the next version of Tvheadend using systemd. This of course will only work if you create systemd mount service files, and/or using fstab. mounting any other way won't have any effect.

@Janne Kollin create yourself a mount service file instead then modify the tvheadend.service file to match my PR. (don't forget to enable your mount file first!!)

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Paraic McDonagh 23 days ago

Hi Janne,

Thanks for your reply. Can I ask when you said that you entered:

systemctl edit service.tvheadend42.service

was this a typo? Did you mean?:

systemctl edit tvheadend42.service

Also, I am assuming that the drive is present as Toshiba under /mnt
Can you navigate to /mnt/Toshiba ?

cd /mnt
ls

You should then see Toshiba listed.

Or even, just do

cd /mnt/Toshiba

to verify that path is navigable.
Also, as I'm not familiar with TVH server on Libreelec, when you issue the following:

service --status-all

you should get a list of all running services in alphabetical order. Is the tvheadend service named 'tvheadend' or 'tvheadend42' on this list?

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Paraic McDonagh 23 days ago

Mark Clarkstone wrote:
> ...

Thanks Mark!

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Janne Kollin 23 days ago

Hi Paraic,

Thank you for answering as said we are a bit newbies here, but learning fast. Somehow this libreelec seems to be reduced from any other linux installation

But ok we tried following:

LibreELEC:~ # systemctl edit tvheadend.service
No files found for tvheadend.service.
Run 'systemctl edit --force tvheadend.service' to create a new unit.

LibreELEC:~ # CD /mnt
-sh: cd: can't cd to /mnt: No such file or directory

but
LibreELEC:~ # CD \mnt works though it is empty

and ls shows this

LibreELEC:~ # ls
backup
downloads
emulators
logfiles
lost+found
mnt
music
picons
pictures
recordings
screenshots
tvshows
videos
ystemctl tvheadend.status

service seems not work
LibreELEC:~ # service --status-all
-sh: service: not found

blkid looks like this
LibreELEC:~ # blkid
/dev/mmcblk0: PTUUID="00078d62" PTTYPE="dos"
/dev/mmcblk0p1: LABEL="RECOVERY" UUID="0F07-0FF3" TYPE="vfat" PARTUUID="00078d62-01"
/dev/mmcblk0p5: LABEL="SETTINGS" UUID="28bb8f51-e268-4f63-8a1d-b9006a9fdcda" TYPE="ext4" PARTUUID="00078d62-05"
/dev/mmcblk0p6: LABEL="boot" UUID="4E4C-5069" TYPE="vfat" PARTUUID="00078d62-06"
/dev/mmcblk0p7: LABEL="root" UUID="4e26f4ba-f753-4b14-b195-8c99940b2b5f" TYPE="ext4" PARTUUID="00078d62-07"
/dev/mmcblk0p8: SEC_TYPE="msdos" LABEL="System" UUID="7A9C-9EDE" TYPE="vfat" PARTUUID="00078d62-08"
/dev/mmcblk0p9: LABEL="Storage" UUID="bffec4f4-3f78-47db-aca7-43e837e78908" TYPE="ext4" PARTUUID="00078d62-09"
/dev/mmcblk0p10: LABEL="boot-rbp2" UUID="7E22-3557" TYPE="vfat" PARTUUID="00078d62-0a"
/dev/mmcblk0p11: LABEL="root-rbp2" UUID="590bb8f6-3ff9-44cf-b55d-df539ed425c8" TYPE="ext4" PARTUUID="00078d62-0b"
/dev/loop0: TYPE="squashfs"
/dev/sda1: LABEL="Toshiba" UUID="01D4CAC1575ABBD0" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="58049860-cac1-01d4-3048-02ac6065ea00"

I need to check also what Mark linked and see what it does now battery of my laptop drains.

Thx for helping us out.. once we get this sorted out, we will create some tutorial for others for disposal.

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Hiro Protagonist 23 days ago

Janne Kollin wrote:

LibreELEC:~ # CD /mnt
-sh: cd: can't cd to /mnt: No such file or directory

This tells you that 'RequiresMountsFor=/mnt/Toshiba' is not valid as /mnt doesn't exist. You need to use the actual mountpoint for Toshiba.

but
LibreELEC:~ # CD \mnt works though it is empty

Careful what you type. '\' is an escape character on the linux commandline, not a directory separator.

and ls shows this

LibreELEC:~ # ls

The prompt above shows you haven't changed directory at all.

blkid looks like this
LibreELEC:~ # blkid
/dev/sda1: LABEL="Toshiba" UUID="01D4CAC1575ABBD0" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="58049860-cac1-01d4-3048-02ac6065ea00"

Look for the mount point for /dev/sda1 in the output from 'df'. This will tell you where "Toshiba" is really mounted.

Somehow this libreelec seems to be reduced from any other linux installation

Yes, libreelec has very limited capabilities compared to a normal linux. Why are you using libreelec for this?
OSMC will give you a much more normal linux to work with.

We actually had difficulties with HDD partitioning in RPI and only way was to use WIN NTFS partition

I can guarantee you that NTFS is not the "only way". Formatting as ext4 will give you considerably improved performance.

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Paraic McDonagh 22 days ago

Sorry Janne, I meant to respond to your post yesterday and didn't get back to it. But as Hiro has correctly pointed out:
It looks as though your drive's mount point is not /mnt/Toshiba so putting this into the config file will not point the drive.
Issuing df or mount at the terminal prompt should list all mounts. From there you can take note of the mount path of your Toshiba drive.
It will be in the format of /somewhere/Toshiba or even /somewhere/somewhereelse/Toshiba, that's assuming the drive is actually called Toshiba on your system.
But whatever the case, you should be able to identify the drive from df and with that information, edit the config file as before and correct the entry.
If you are unsure, just post the output here.

With respect to the use of NTFS, yes it would be better to have the drive formatted as ext4.
On my own system, I had a lot of movies on my NTFS formatted drive that I wanted to preserve, hence the reluctance to format.
I suspect you may be in a similar situation. I meant to fix this before now but have been procrastinating.
The general steps would be to A copy the directories and files to another drive on the system, format the drive as ext4, then copy the files back. Of course fixing everywhere that refers to paths on the drive.
or B (If you have no alternative drive), the general steps are:

1. Shrink the existing NTFS partition.
2. Create and format an additional ext4 partition on the drive.
3. Copy the folders/files from the NTFS partition to the ext4 partition.
4. Change the RecordedTV path in tvheadend point to the ext4 partition. Make sure any other paths are adjusted also (E.g. Kodi's path to Movies) and everything works as expected.
5. Delete the NTFS partition.
6. Grow the ext4 partition to the full capacity of the drive.

Of course not forgetting to edit the tvheadend config file to update the mount point.
The above assumes that you have enough remaining capacity on the drive. If you have 1Tb of files to copy, you need 1Tb free space.
I wouldn't blame you if you decide to procrastinate also though : )

Hope this helps. Let me know how you get on.

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Paraic McDonagh 22 days ago

Just an update:
I decided to bite the bullet and change my own NTFS drive over to ext4.
Long story short. It would have taken many hours to shrink a large NTFS drive under Linux (apparently it could be days).
During that time, the drive will be unmounted and so TVH will not be able to save any new recordings.
When you add to that the additional time needed to move large files around (about 1Tb in my case), it would have been time prohibitive.
In the end, I just deleted the NTFS partition without any backup and created a new ext4 partition in its place. I sacrificed all my existing recordings.
In your case if you are using a USB attached drive, it could take even longer to carry out. So my advice is not to use option B at least from my previous post if you have a large amount of files. Even option A will take quite a while.

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Janne Kollin 21 days ago

Hi Paraic,

well we had together my son interesting journey around this topic..

Long story short

we followed your advice to
1. Shrink ntfs part of HDD
2. Allocate more disk to EXT4
3. Copy files to NTFS to EXT4 partition
4. Delete NTFS partion
5. Expand remaining space to EXT4
6. This point after restart it got crazy => none of the USB was shown and we booted with raspbian stretch which got stuck on boot

1. We ejected SD
2. Reinstall noobs multiboot
3. Converted HDD to EXT4 with MiniTool Partition Wizard
4. Add noobs back to SD
5. Select OS (Raspbian, Libre Elect, OSMC) and install
6. Boot to raspbian when running sudo blkid show weird microsoft dedicated partition and we were not able to mount it
7. Format HDD with AOMEI Partition Assistant Standard Edition 8.0 to EXT4
8. Boot to LE and wow it worked now when starting rec in live tv rebooot recording are showing

Long journey bro.. finally it is working as should..

Thus negative side of having partitions running as EXST4 is really slow file copy from NTFS and back.. as well as we tried to avoid HDD not showing on WIN10 as native.. but hey we cannot obviously get all advantages:)

We are still noobs on Linux eventough it is build by Finn:D

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Paraic McDonagh 14 days ago

That's great to hear! The moral of the story is to format as ext4 from the beginning.
Failing that, edit the config to delay tvheadend service start if you absolutely must have NTFS.
But copying large files around just takes too long.

RE: Recordings disappearing after rebooting TVH box (Ubuntu). - Added by Janne Kollin 13 days ago

Hi Paraic,

yes good stuff and thx for helping us out.

Yeah it would be nice to have this delay check already in TVHEADEND in case NTFS disk is must have.. in our case it would have been better due visibility on WIN PC, but we can live with that .At least we learned a lot which is good when struggling with stuff.

I suppose anyone who follows this thread can get things done.

For other WIN background users one remark, when formatting to EXT4 your disk, don't worry about constant disk access. There is linux journal service which makes this constant read write to disk. This is normal activity since format doesn't build all indexing during format, but major part is left to this journal service. For us this read and write indexing took 11 hours for 8 Tb SATA disk (around 1,5 hour per Tb). So just let it do it's job:)

    (1-11/11)