Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maatthc/792471812150010c935aedd34c93aedf to your computer and use it in GitHub Desktop.
Save maatthc/792471812150010c935aedd34c93aedf to your computer and use it in GitHub Desktop.
LG WebOStv - Play games on RetroArch from USB drive
#!/bin/bash
# === For rooted LG TVs with WebOsBrew installed only ===
#
# On LG WebOStv, RetroArch only have access to a few jailed folders so to run games on a usb drive,
# we need to 'merge' the USB mounting point with one of those jailed folders using OverlayFS.
# The scripts on folder '/var/lib/webosbrew/init.d/' will run after every tv boot.
# Remove the $STARTUP_FOLDER/$SCRIPT_TO_RUN_AFTER_BOOT and reboot to revert the change.
#
# Tested on 7.3.0-03.30.72
#
# Steps:
# - Copy this script to a pen drive and insert it to the TV
# - Check if the folder '/tmp/usb/sda/sda1/' exists and have the content of your pen drive.
# - Run the script
#
# The folder structure might be different depending of your TV version
set -euo pipefail
JAILED_FOLDER=/var/palm/jail/com.retroarch/media/internal
USB_MOUTING_POINT=/tmp/usb/sda/sda1/
SCRIPT_TO_RUN_AFTER_BOOT=add_usb_drive_to_retroarch_media_folder
STARTUP_FOLDER=/var/lib/webosbrew/init.d
echo -e "#!/bin/bash \nmount -t overlay -olowerdir=${JAILED_FOLDER}:${USB_MOUTING_POINT},nofail overlay ${JAILED_FOLDER}" > $STARTUP_FOLDER/$SCRIPT_TO_RUN_AFTER_BOOT
chmod +x $STARTUP_FOLDER/$SCRIPT_TO_RUN_AFTER_BOOT
echo "Script ${STARTUP_FOLDER}/${SCRIPT_TO_RUN_AFTER_BOOT} created."
echo "Press any key to reboot and activate changes or CRTL+C to quit."
read -n 1
reboot
@maatthc
Copy link
Author

maatthc commented Dec 20, 2023 via email

@shienok
Copy link

shienok commented Jan 8, 2024

I have rooted lg c3.
On my fat32 flash device parent directory i created folders: tmp, on tmp folder i created sda folder, then sda1 on tmp/sda.
Then i placed file add_usb_drive_to_retroarch_media_folder_install.sh on this tmp/sda/sda1 folder.
Then i connected my rooted tv to webOS Dev Manager.
On terminal i entered: cd /tmp/usb/sda/sda1/
Then checked that file exist: ls
Then i successfully run the script and tv rebooted.
Then i put some snes and smd roms to folder /tmp/usb/sda/sda1/ - but retroarch still dont see my usb flash drive...
I tried to reboot tv, i tried to put roms on sda or sda1 or tmp or parent usb drive folders - still do not see it. Yes i run snes or smd retroarch core, and use properate roms extension.
I uploaded roms on tv rom with webOS Dev Manager - and retroarch perfectly see and run them. But usb flash drive still do not work.
Any suggestions? Thanx!

@maatthc
Copy link
Author

maatthc commented Jan 9, 2024

Hi Shienok,
When you plug your usb drive to the TV, the folder "/tmp/usb/sda/sda1/" should be automatically created for you by the TV itself on its filesystem - the path may vary depending on the TV model.
On the usb drive, you only need the script "
add_usb_drive_to_retroarch_media_folder_install.sh" and your roms.

@shienok
Copy link

shienok commented Jan 10, 2024

lg c3, rooted, ver.03.20.17
Tried 2 usb flash drives, formated fat32.
On empty flash drive i put only 1 file add_usb_drive_to_retroarch_media_folder_install.sh
Connected to tv via webOS Dev Manager Terminal
Entered: cd /tmp/usb/sda/sda1/, then entered: ls - it shows me only 1 file add_usb_drive_to_retroarch_media_folder_install.sh.
Then i entered: sh add_usb_drive_to_retroarch_media_folder_install.sh
It succesfully installing and rebooting tv.
After that no files or folders are creating on usb flash drive, only this 1 file add_usb_drive_to_retroarch_media_folder_install.sh as it was before all the procedure... I put roms on flash - retroarch do not see anything(

@maatthc
Copy link
Author

maatthc commented Jan 14, 2024

Are the roms zipped? It must be uncompressed to retroarch to find it.

@shienok
Copy link

shienok commented Jan 15, 2024

Are the roms zipped? It must be uncompressed to retroarch to find it.
no, all roms are unzipped of course

@maatthc
Copy link
Author

maatthc commented Jan 16, 2024

On RetroArch, if you go to "Load content" and select "/media/internal", what do you see?

@maatthc
Copy link
Author

maatthc commented Jan 16, 2024

Also, please send the output of following command with the usb drive attached:

ls -la /var/palm/jail/com.retroarch/media/internal/

And

cat /var/lib/webosbrew/init.d/add_usb_drive_to_retroarch_media_folder

And

ls -la /var/lib/webosbrew/init.d/add_usb_drive_to_retroarch_media_folder

@shienok
Copy link

shienok commented Jan 18, 2024

1
2
screen 1 with donkey kong sfc rom - this rom i uploded on tv memory with the help of webOS Dev Manager.
screen 2 with above 3 commands on terminal

@maatthc
Copy link
Author

maatthc commented Jan 19, 2024

Everything looks okay.. could you please add all your roms to the usb drive and repeat all steps, adding the following?

ls -la /tmp/usb/sda/sda1/

@Simon34545
Copy link

I'm having an issue as well.
image
Here is output of script:
image

@Simon34545
Copy link

Fixed after reformatting usb using NTFS (overlayfs: filesystem on '/tmp/usb/sda/sda1' not supported)

@bejamartins
Copy link

bejamartins commented Aug 21, 2024

@maatthc I have the same problem. run the script, TV rebooted, no new files or folders in /media/internal/ seen in retroarch.

root@LGwebOSTV:~# ls -la /var/palm/jail/com.retroarch/media/internal/
total 40
drwxrwxrwx 10 root root 4096 Aug 20 03:07 .
dr-xr-xr-x 5 6103 5000 4096 Aug 18 2023 ..
-rw-r--r-- 1 root root 0 Jan 1 2022 .VolumeIcon.icns
drwxr-xr-x 2 root root 4096 Jan 1 2022 .sysservice
drwxr-xr-x 2 root root 4096 Jan 1 2022 .temp
drwxr-xr-x 3 root root 4096 Jan 1 2022 .wallpapers
drwxr-xr-x 6 root root 4096 Aug 19 04:25 ROMs
drwxr-xr-x 2 6799 5000 4096 Aug 20 2023 avs
drwxr-xr-x 2 root root 4096 Feb 26 2023 downloads
drwxr-xr-x 2 root root 4096 Jan 1 2022 ringtones
drwxr-xr-x 2 6799 5000 4096 Aug 18 2023 vsk
root@LGwebOSTV:~# cat /var/lib/webosbrew/init.d/add_usb_drive_to_retroarch_media_folder
#!/bin/bash
mount -t overlay -olowerdir=/var/palm/jail/com.retroarch/media/internal:/tmp/usb/sda/sda1/,nofail overlay /var/palm/jail/com.retroarch/media/internal
root@LGwebOSTV:~# ls -la /var/lib/webosbrew/init.d/add_usb_drive_to_retroarch_media_folder
-rwxr-xr-x 1 root root 163 Aug 21 00:56 /var/lib/webosbrew/init.d/add_usb_drive_to_retroarch_media_folder
root@LGwebOSTV:~# ls -la /tmp/usb/sda/sda1/
total 640
drwxr-xr-x 5 root root 131072 Jan 1 2022 .
drwxr-xr-x 3 root root 60 Jan 1 2022 ..
drwxr-xr-x 2 root root 131072 Aug 21 00:21 Smart TV
drwxr-xr-x 2 root root 131072 Aug 21 00:10 System Volume Information
-rwxr-xr-x 1 root root 1318 Aug 21 00:56 add_usb_drive_to_retroarch_media_folder_install.sh
drwxr-xr-x 3 root root 131072 Aug 21 00:10 roms

(Note that the ROMs folder in /media/internal was already there)

Edit: nevermind, it was the file format as well. Apparently only NTFS works, which is odd for a Linux system,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment