Wednesday, July 31, 2013

How to Mount a Windows Partition in Ubuntu Using fstab

If you have dual-boot on your computer or in a range of other events, a partition might be mounted in nautilus automatically, but not using fstab.

This was my scenario as well, I needed to create a symlink from my Ubuntu system to a folder on the same hard drive, but under Windows 7 (different partition). Nautilus has mounted the Windows 7 NTFS file system on each boot, but the symlink became broken every single time. Talking to some friends on IRC I was told to set up a mount point in fstab as this will be more reliable.

I will use my own example where I wanted to add a mount point for the device /dev/sda2 to /mnt/windows. (Simply put /dev/sda2 is my Windows 7 partition and I want this to be readable and writeable under the location /mnt/windows)

1. First off check the list of devices (partitions) with
sudo blkid

This will output something like:

/dev/sda2: UUID="E88450A5845077D0" TYPE="ntfs"
/dev/sda6: UUID="3ce77abd-dcf9-43f3-a94a-1369855d16b2" TYPE="ext4"
/dev/sdb1: LABEL="Mass Storage" UUID="4E84E9E384E9CE11" TYPE="ntfs"
/dev/mapper/cryptswap1: UUID="444536d6-705b-4626-b0a5-382107c3ec96" TYPE="swap"

What this tells, are the unique identifiers of devices on the computer. 
For example I know now that /dev/sda2 is my Windows partition based on the fact that it has ntfs file system. This information will be useful in the next steps.

2. Create the location where you want to mount your partition. This directory must be created first, so go ahead and create a directory in /media or /mnt. In my case this was:

sudo mkdir /mnt/windows

3. Edit fstab with

sudo gedit /etc/fstab

After inspecting the file, on the top you will see lines of already mounted devices, these will be different depending on your system and configuration. Just to shown an example here are my first 2 lines.

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0

This is mostly self-explanatory.
<file system>, the first tag of the line is the device, hence the /dev/sda2 in my case if I wanted my external Win7 partition.

<mount point> is the point where you want this partition to be mounted at. This can be in /media or /mnt or wherever you like it. As explained above, in my case this is /mnt/windows

<type> defines the type of the partition, that is ext3, ext4, ntfs and so on. This information was also obtained in step 1, ntfs.

<options> provides extra settings for permission and such. I used "default", but more advanced options can be read in the manual:

man fstab

4. Add  a new line for the partition or device you want to mount. In my case again, I wanted to mount the partition at /dev/sda2 to the location /mnt/windows

Add the following  line to fstab:

#Windows mount point
/dev/sda2 /mnt/windows    ntfs    defaults    0    0  

Save the changes.

5. After this you can mount all partitions with

sudo mount -a
Or you can reboot your system and it will be booted automatically.

Using the above steps I could successfully create a mount point in /mnt/windows to my /dev/sda2 device and this mounting also allows (permanent) symlinks and is persistent even after a reboot.

Saturday, July 27, 2013

How Install Flash Games on PirateBox

Although it was not designed for this, PirateBox can support browser games as well. It's main purpose is to allow anonymous file sharing and chat between the connected users, but hey, it doesn't hurt to have a little fun while sharing files right?
My TP-LINK MR3020 is loaded with a custom UI and I was experimenting to see if I can get some flash games running sort of "out of the box".

It turned out, it is simpler than I have imagined, flash games can be used on the PirateBox by simply copying them over and embedding them with <embed media>.

Here is a screenshot of the flash games running on my box:

Guide to Install a Game:

  1. Your PirateBox has to be version 0.5.1 or above, that is use lighttpd.
  2. Find the flash game you want on your box. Search on the internet what you like, e.g. mario, sonic and so on. After you found the game, download it on your computer. This should be an ".swf" file.
  3. Take your USB drive from the PirateBox and plug it in your computer. The file USB/PirateBox/pbIMG_ws.img has to be edited. This is an img file container mounted when the PirateBox starts and contains the UI files among others.
    This pbIMG_ws.img is 20 Mb by default so if you have a custom UI and 1-2 game you might need to create a bigger file container.

    To mount this file do:

    sudo mkdir -p /tmp/tmp_mount/ && sudo mount -o loop,rw,sync /media/[$usb]/PirateBox/pbIMG_ws.img /tmp/tmp_mount
    sudo chmod -R 777 /tmp/tmp_mount

    (Where [$usb] is the name of your USB drive)
  4. The file will be mounted at /tmp/tmp_mount/
    Navigate here and open the html file from the www folder you want to add the flash game to.
    Or create a new html page with the game in it. Don't forget to link this to the landing page, so itt will be easily available for users.
  5. Use the following code to embed the flash game into your site:

    <embed src="path/to/flash-game.swf"  type="application/x-shockwave-flash" name="obj1" width="600" height="450">

    src - path to the file within the www directory. Hence if you have a "games" folder in www then the route should be games/yourgame.swf
    width - width of the flash game (advised to keep original)
    height - height of the flash gem (advised to keep original)
  6. After finished, unmount the img container before ejecting the USB drive with:

    sudo umount /media/[$usb]/PirateBox/pbIMG_ws.img

  7. Eject your USB drive, plug in into your PirateBox and boot it.

The easiest way to quickly mount and unmount this
is to create a script that does this for you. 

Here is the script I wrote to make things easier for myself.

CAUTION: Flash games load by default in the browser. Therefore, many games on the same page (especially landing page) will most likely create an unnecessarily high load for the PirateBox. I would advise that you create separate html pages for games.

    pbIMG_ws.img mounter script

    People are often having issues with changing and mostly finding the UI/html files on the piratebox. These are located in an img file container located at

    To access the files inside this .img container, you have to mount this file. See guide here.

    The best way to do this mounting is to use a script so you don't need to type the command all the time. The script I am using to quickly mount and unmount the pbIMG_ws.img file from your USB drive that contains the www foler (UI files) is shown below. Feel free to take a copy.

    1. Copy the code below into a text file (starting from the line "#!/bin/bash")
    2. Give it execute permissions either by "properties/allow execution as program" or
    sudo chmod +X
    2. Replace "TOSHIBA" in the configuration part with the name of your USB stick
    3. Run it in the terminal


    #Script to mount & unmount pbIMG_ws.img

    ############## CONFIGURE #######################
    #Change this to the name of your USB drive


    echo "What do you want to do?"
    PS3='Select an option:'
    select main in "Mount PirateBox Image" "Unmount PirateBox image"
    case $main in

    "Mount PirateBox Image")
    sudo mkdir -p /tmp/tmp_mount/ && sudo mount -o loop,rw,sync /media/$usb/PirateBox/pbIMG_ws.img /tmp/tmp_mount
    sudo chmod -R 777 /tmp/tmp_mount
    echo ""
    echo "Image was successfully mounted at /tmp/tmp_mount"
    echo "
    1) Mount PirateBox Image
    2) Unmount PirateBox image"

    "Unmount PirateBox image")
    sudo chmod -R 777 /tmp/tmp_mount
    sudo umount /media/$usb/PirateBox/pbIMG_ws.img
    echo ""
    echo "PirateBox image was successfully unmounted!"
    echo "
    1) Mount PirateBox Image
    2) Unmount PirateBox image"
    *) echo PEBKAC;;