This is a guide (which isn’t short, unfortunately, sorry) on how to enable Samba support in your LG WebOS Smart TV.
If you want to know the store on how I came up with this, read part 1, part 2 and part 3.

If you just want the instructions, read on.
For those willing to build their own binaries for WebOS TVs, I’ve created a GCC toolchain which should work for most TVs. You can download it here.

DISCLAIMER: ROOT SHELL ALLOWS FULL UNRESTRICTED ACCESS TO YOUR TV’S LINUX OS. THIS IS VERY DANGEROUS IF YOU DON’T KNOW WHAT YOU’RE DOING. I WILL NOT BE RESPONSIBLE IF YOU BRICK OR OTHERWISE HARM YOUR SMART TV WHILE FOLLOWING THESE INSTRUCTIONS. YOU TAKE ALL RESPONSIBILITY FOR YOUR ACTIONS. IF YOU CHOOSE TO FOLLOW THESE INSTRUCTIONS PLEASE READ EACH STEP VERY CAREFULLY AND MAKE SURE YOU UNDERSTAND WHAT TO DO.

What you will need:
1. A WebOS Smart TV (of course), connected to the Internet, preferably over Ethernet.
2. A spare USB drive which you can keep inserted permanently. It would be best if this was the only USB drive or at least the only drive at the moment the TV is turned on.
3. Some Linux knowledge and patience would help as well.

This guide consists of 4 steps, each divided into substeps. I’ve tried to be as detailed as possible, but if you still have trouble following these instructions, do write in the comments.

Commands to run in the shell and text which you need to paste use this font.

Make sure to replace the text “IP address” in commands with your actual IP address !

UPDATE: I’ve replaced the mount.cifs binary inside the samba-webos-support-tar.gz archive with a more compatible version. Should now be compatible even with very old WebOS versions (tested this on 1.4).

——

Step 1: Root your TV

1. Install an app called Developer Mode from LG’s app store.
2. Go to http://developer.lge.com/main/Intro.dev and click on Sign In (the link should be in the upper right corner).
3. Click on Create Account (above the login form) and follow the instructions.
4. Start the Developer Mode app on your TV and log-in with your account.
5. Enable Developer Mode. Your TV will restart.
6. After your TV boots up, open Developer Mode app again and enable Key Server.
7. Download Cygwin (64-bit or 32-bit) and install it. Make sure you select the openssh, telnet and wget packages.
8. Open Cygwin terminal and type this command: wget http://IP address:9991/webos_rsa
(IP address of your TV should be visible in Developer Mode app)
9. Type this command: ssh -i ./webos_rsa prisoner@IP address -p 9922 '/bin/sh -i' and enter the 6 character password from Developer Mode app. You should now be in a new shell, inside /media/developer directory.
10. In your new shell, type these commands (one after another):

wget http://zebra-mirror.ddscentral.org/webos-samba/6937580_root -O root;
chmod +x root
./root

11. When prompted, try installing any app from the app store. You should get an error on the TV screen.
If the app installs successfully STOP HERE. Your TV’s firmware cannot be rooted with the tool provided and you will need to downgrade your firmware. There’s a link to a tutorial on how to do this in part 2.
12. Type 1111 when prompted. You should now have a root shell with no prompt. Type: id and press Enter. You should a line of text confirming that you are now root.

——

Step 2: Make root access permanent

You now have root access but it’s not permanent. We’re going to make it permanent so you don’t have to root the TV again.
1. First, we need to change the root password and run telnet, so we can get out of the crappy LG shell (try arrow keys…). Type these commands as root:

busybox chroot /proc/1/root
mkdir /media/cryptofs/root
mkdir /media/cryptofs/root/etc
cp -r /etc/* /media/cryptofs/root/etc/
mount --bind /media/cryptofs/root/etc /etc
passwd
(type new password for root user)
nohup telnetd -l /sbin/sulogin &

2. Switch to Cygwin terminal. Type command: telnet IP address and enter your password when prompted. You should now get a better shell to your TV.
3. In your new shell, type these commands:

cd /home/root
wget http://zebra-mirror.ddscentral.org/webos-samba/samba-webos-support.tar.gz
tar -xvf samba-webos-support.tar.gz
cd bin
chmod +x *
./edit_devmode.sh

4. You should now be in text editor. Press “i” to enter insert mode. After the first line (it should say #!/bin/sh), add this text:

mount -o bind /media/cryptofs/root/etc /etc
telnetd -l /sbin/sulogin &

5. Scroll down until you see this code (I wanted to retain lines as they are in the actual code, zoom in if you can’t see):


    if [ $OnLine ]; then
        sessionToken=$(cat /var/luna/preferences/devmode_enabled);
        checkSession=$(curl --max-time 3 -s https://developer.lge.com/secure/CheckDevModeSession.dev?sessionToken=$sessionToken);

        if [ "$checkSession" != "" ] ; then
            result=$(node -pe 'JSON.parse(process.argv[1]).result' "$checkSession");
            if [ "$result" == "success" ] ; then
                rm -rf /var/luna/preferences/dc*;
                # create devSessionTime file to remain session time in devmode app
                remainTime=$(node -pe 'JSON.parse(process.argv[1]).errorMsg' "$checkSession");
                resultValidTimeCheck=$(echo "${remainTime}" | egrep "^([0-9]{1,4}(:[0-5][0-9]){2})$");
                if [ "$resultValidTimeCheck" != "" ] ; then
                    echo $resultValidTimeCheck > ${DEVMODE_SERVICE_DIR}/devSessionTime;
                    chgrp 5000 ${DEVMODE_SERVICE_DIR}/devSessionTime;
                    chmod 664 ${DEVMODE_SERVICE_DIR}/devSessionTime;
                fi
            elif [ "$result" == "fail" ] ; then
                rm -rf /var/luna/preferences/devmode_enabled;
                rm -rf /var/luna/preferences/dc*;
                if [ -e ${DEVMODE_SERVICE_DIR}/devSessionTime ] ; then
                    rm ${DEVMODE_SERVICE_DIR}/devSessionTime;
                fi
            fi
        fi
    fi

6. Modify it, so it looks like this (see highlighted characters for changes):


#    if [ $OnLine ]; then
#        sessionToken=$(cat /var/luna/preferences/devmode_enabled);
#        checkSession=$(curl --max-time 3 -s https://developer.lge.com/secure/CheckDevModeSession.dev?sessionToken=$sessionToken);

#        if [ "$checkSession" != "" ] ; then
#            result=$(node -pe 'JSON.parse(process.argv[1]).result' "$checkSession");
#            if [ "$result" == "success" ] ; then
                rm -rf /var/luna/preferences/dc*;
#                # create devSessionTime file to remain session time in devmode app
#                remainTime=$(node -pe 'JSON.parse(process.argv[1]).errorMsg' "$checkSession");
#                resultValidTimeCheck=$(echo "${remainTime}" | egrep "^([0-9]{1,4}(:[0-5][0-9]){2})$");
#                if [ "$resultValidTimeCheck" != "" ] ; then
                    echo '900:00:00' > ${DEVMODE_SERVICE_DIR}/devSessionTime;
                    chgrp 5000 ${DEVMODE_SERVICE_DIR}/devSessionTime;
                    chmod 664 ${DEVMODE_SERVICE_DIR}/devSessionTime;
#                fi
#            elif [ "$result" == "fail" ] ; then
#                rm -rf /var/luna/preferences/devmode_enabled;
#                rm -rf /var/luna/preferences/dc*;
#                if [ -e ${DEVMODE_SERVICE_DIR}/devSessionTime ] ; then
#                    rm ${DEVMODE_SERVICE_DIR}/devSessionTime;
#                fi
#            fi
#        fi
#    fi

7. Double and triple check to make sure you’ve changed the right lines. Then press Esc key to exit insert mode. After that, press Shift + : , type w and then press Enter key to save. After that, press Shift + : again, type q and press Enter key to exit.
8. I recommend testing you root access. Type reboot. Wait until the TV restarts then try typing telnet IP address in Cygwin shell again. If you get a shell, that means you did everything correctly. If you don’t get anything, restart rooting process from the beginning and make sure you do it right this time.

——

Step 3: Configure Samba

1. In Cygwin shell, type telnet IP address. If you rooted your TV correctly, you should get a password prompt and a root shell.
2. Type this command cd /home/root/bin to go to “bin” directory.
3. Type ./mount.cifs. If you get usage instructions, all is fine. If you get an error STOP HERE. That means the mount.cifs binary isn’t compatible with your TV. Post your TV model, WebOS version and the error message you get in the comments and I will try to help.
4. Connect your USB drive to the TV and wait until the TV detects it. Then type mount command in the shell. Check for line which looks like this:

/dev/sda1 on /tmp/usb/sda/sda1 type tfat (some more stuff in parentheses)

The important parts are /dev/sda1 on /tmp/usb/sda/sda1. /dev/sda1 is your USB drive’s device name and /tmp/usb/sda/sda1 is your USB drive’s mount point.

5. Type vi samba.cfg to edit Samba configuration. Edit the file the same way you did with edit_devmode.sh. There’s a note above each configuration option, telling what that option does. If you don’t understand something, do post a comment and I will try to help.
6. Create a directory inside your USB drive for mounting shares on. Then create additional directories for each of your shares inside that directory. For example, my share configuration looks like this:


...

# List of shares to mount. Use double quotes around the list. List is space separated.
# For example: SHARELIST="Example1 Example2 MyPhotos MyMovies"
SHARELIST="Junkie Scrapheap Capone Stormtrooper Violet Blue Blackbird KoreanServer VenusMedia StoreServer"

# Mount point of the USB drive. Use "mount" command after inserting the USB drive to find out where it was mounted.
USB_ROOT=/tmp/usb/sda/sda1

# Directory inside your flash drive for mounting shares. Don't forget to create mount point directories for each share in it.
# For example, if your directory is /tmp/usb/sda/sda1/NAS and share name is Example1, create directory  /tmp/usb/sda/sda1/NAS/Example1
# Do not delete $USB_ROOT prefix !
HOSTDIR_USB=$USB_ROOT/NAS

...

To create directories for this setup, you would run these commands:

mkdir /tmp/usb/sda/sda1/NAS
cd /tmp/usb/sda/sda1/NAS
mkdir Junkie Scrapheap Capone Stormtrooper Violet Blue Blackbird KoreanServer VenusMedia StoreServer

First command will create your share root directory, second one will go to it. Finally, third one will create all your share mount directories. I recommend you simply copy your share list (without the quotes !) from terminal for the last command.

When you’re done, type cd /home/root/bin to return to your “bin” directory.
7. Test your configuration. Type ./smbsharemond.sh. Wait at least 10-15 seconds. Then type cat /tmp/smbsharemond.log This will show the mounter log. If you get any errors, check your configuration and try again. If all shares were mounted fine, read on.
8. Pick up your remote and open Photos & Videos or Music app (or SmartShare app in older TVs) on your TV. Select your USB drive and navigate to your shares directory. Then try opening one of the share directories. Your shared files should be visible. You can try opening a file if you want.

You’ve successfully added Samba support to your WebOS TV. But there’s still one more thing to do: make the share mounts permanent.

——

Step 4: Make share mounts permanent

1. Go to your “bin” directory if you’re not already there (that command again cd /home/root/bin) and type ./edit_devmode.sh.
2. Enter insert mode with i key. Then, below line
telnetd -l /sbin/sulogin &

insert this text:

/home/root/bin/smbsharemond.sh

Then save and exit the same way as you did before.
3. Reboot your TV by using the reboot command. After your TV boots, wait 40 – 50 seconds. Then open Photos & Videos or Music app and check your shares again. Your files should still be visible.

Congratulations ! Your setup is complete. Enjoy using your Samba shares !

——

Additional notes

1. The mounter script is designed to remount all your shares automatically every time you turn on your TV. It will take about 30 seconds or so for the shares to be remounted after the TV is turned on.
2. Do not unplug your USB drive when using the shares or they will be dismounted. I recommend keeping the drive plugged-in all the time when the TV is on if possible.
3. If you have downgraded your TV’s firmware, do NOT update it back to the latest version or you will lose both root access and Samba. To disable update nags, open root shell to your TV (telnet IP address), type vi /etc/hosts and insert these lines:


127.0.0.1 snu.lge.com
127.0.0.1 rdvs.alljoyn.org
127.0.0.1 fi.lgtvsdp.com
127.0.0.1 us.lgtvsdp.com
127.0.0.1 in.lgtvsdp.com
127.0.0.1 fr.lgtvsdp.com

The save and quit the same way as you did before.

4. I’ve only tested this configuration with Samba shares on my Linux server. Using Windows shares is possible but you will most likely need to edit your mount options (OPTIONS in samba.cfg). Let me know I will try to help if you can’t get Windows shares to work.
5. The mounter script assumes all shares are always available and will not remount shares if computer hosting them is turned off. To force remount your shares, turn your TV off and back on again.
6. Although using WiFi will work, Samba will likely be much slower than over wired Ethernet.

If you have any questions, post in the comments below.