How To: Mount a Google Nexus 7 Tablet in Linux

In Windows you can just plug it in and it’ll mount and recognise just fine, but in Linux you need to work a little bit harder. Not that much harder, though – it’s a 4-step….

1 – Get the right tools

sudo apt-get install mtp-tools mtpfs

2 – Set up a udev rule to do the right thing on connection

gksu gedit /etc/udev/rules.d/51-android.rules

Add this text to the rule to specify the Vendor ID, Product ID and user who has access to the device (change YOUR-USERNAME-HERE to your username, obv):

SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", OWNER="YOUR-USERNAME-HERE"

3 – Restart udev and set up a mount point

sudo service udev restart
sudo mkdir /media/Nexus7
sudo chmod a+rwx /media/Nexus7

4 – Hook it up

Plug in your Nexus 7 and select MTP device as the connection type.

Then enter:

sudo mtpfs -o allow_other /media/Nexus7

At this point you should be able to read/write to your N7 via the /media/Nexus7 folder through any means you choose.

When you need to, just run either of the following for a clean dismount:

sudo umount /media/Nexus7


sudo umount mtpfs

Source:, I just paraphrased it a little to simplify.

How To: Properly automount NTFS and vfat partitions in Linux using fstab

This is more for my own notes than anything else, but to properly mount NTFS or vfat (i.e. FAT16/FAT32) partitions in Linux, first find the UUID of the drive using:

ls -l /dev/disk/by-uuid

For example:

r3dux@r3d-laptop:~$ ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx 1 root root 10 Jul 14 08:40 3f55aec7-b4be-4b51-bce7-ce32ec661eba -> ../../sda2
lrwxrwxrwx 1 root root 10 Jul 14 09:46 669A58CD9A589B7F -> ../../sdb3
lrwxrwxrwx 1 root root 10 Jul 14 08:40 bb15a473-2531-441a-a9d9-a6bbef705a57 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jul 14 08:40 C2B2D3AEB2D3A567 -> ../../sdb2
lrwxrwxrwx 1 root root 10 Jul 14 08:40 c5364a36-80ee-495f-9379-982a2c0397ea -> ../../sda3
lrwxrwxrwx 1 root root 10 Jul 14 08:40 EA26C54026C50E8F -> ../../sdb1

To mount NTFS or vfat partitions properly, you need to specify dmask (directory mask) and fmask (file mask) values, which as you might expect are the MASKS of the values you want to use (i.e. the octal compliments). Yeah, I’m not sure why it’s done this way either, but to calculate the mask value just subtract the value you want from 7.

As long as you know the following you should be just fine:

  • Read is 4,
  • Write is 2, and
  • Execute is 1.

For example:

  • If you want to mount the drive with 777 permissions (owner, group and other all r+w+x), then the mask of that is 000 – i.e. 7-7 = 0 for read, write and execute
  • If you want to mount the drive with 751 permissions (owner r+w+x, group r+x, other x), then the mask is 026 – i.e. 7 – 7 = 0, 7 – 5 = 2, 7 – 1 = 6)

So once you’ve identified your partition, you can add the following to your /etc/fstab file to have it mount automatically on boot:

UUID=<YOUR-UUID-HERE>    <DIRECTORY-TO-MOUNT-AT>    ntfs    uid=<YOUR-UID>,gid=<YOUR-GID>,dmask=<YOUR-DMASK>,fmask=<YOUR-FMASK>    0    0

So if I want to automatically mount my sdb3 partition at boot (which I know is formatted as ntfs) at /media/DATA with 755 permissions (owner r, group r+X, other r+x, i.e. 022 mask), I could use:

UUID=669A58CD9A589B7F    /media/DATA    ntfs    uid=r3dux,gid=r3dux,dmask=022,fmask=022    0    0

For the user ID (uid) or group ID (gid) values, you can use the numerical or actual values, i.e. uid=r3dux,gid=r3dux is fine, as is uid=1000,gid=1000 etc.

The first user account and group ID for any user on a Linux system are generally 1000.

If you’re not sure of your uid or gid values, just enter id in a terminal and it’ll tell you:

r3dux@r3d-laptop:~$ id
uid=1000(r3dux) gid=1000(r3dux) groups=1000(r3dux),4(adm),20(dialout),24(cdrom),25(floppy),26(tape),27(sudo),29(audio),30(dip),44(video),46(plugdev),108(netdev),111(fuse),113(lpadmin),116(powerdev),117(scanner),125(vboxusers)

Happy NTFS & vfat automouting ;-)

How to: Create an ISO image of directories in Linux

I ripped some DVDs I own the other day as I wanted to create a back-up for the kids travel DVD players (so the originals don’t get scratched and trashed on the road), only the DVDs themselves were DVD-9’s (so single-sided dual-layer with a capacity of up to 8.54GB) while I can only write DVD-5’s (single-sided single layer with a capacity of up to 4.7GB) – this isn’t a big problem as I compressed them down to fit using Handbrake and elements of Shetboy’s meticulously crafted AVI to DVD technique. However, both Brasero and GnomeBaker would flat out refuse to burn Video projects – they’d just choke on the folder containing the AUDIO_TS and VIDEO_TS folders – so why not covert the directory including the *_TS folders to an ISO and burn that? No reason why not! Let’s get it done! =P

Making the ISO

Once you’ve got a folder structure containing the AUDIO_TS folder (which is empty) and the VIDEO_TS folder (which contains your .BUP, .IFO and .VOB files), just run the following command to generate your ISO:


So, for example, you might use the following command to create an ISO of the directory containing the *_TS folders for the film Avatar:

mkisofs -o ~/AvatarDVD.iso -V Avatar -r ~/dvdprep/Avatar/

Once you hit return, you’ll see something like the following output:

I: -input-charset not specified, using utf-8 (detected in locale settings)
  0.22% done, estimate finish Wed Jul 27 12:30:27 2011
..... all the rest ......
 99.96% done, estimate finish Wed Jul 27 12:27:58 2011
Total translation table size: 0
Total rockridge attributes bytes: 1353
Total directory bytes: 4096
Path table size(bytes): 42
Max brk space used 21000
2275896 extents written (4445 MB)

Measure Twice, Cut Once

If you wanted to make sure you got it right, as in, you ONLY have the *_TS folders in the iso, not the top level folder containing those two folders also, then just open the created iso file with Archive Manager and take a look, or mount it to a folder with:

mkdir test
sudo mount -o loop -t iso9660 ./AvatarDVD.iso ./test
ls test
[ which should show "AUDIO_TS  VIDEO_TS" ]
sudo umount ./test

When you’re happy with the iso, burn it with your burning software of choice and you’re all sorted!


How To: Mount a NAS in Linux (via CIFS)

Apparently CIFS is the new Samba, so to mount your NAS via CIFS instead of Samba, read this, then change the fstab line to:


i.e. For me it’s:

// /mnt/Share cifs credentials=/root/.credentials,rw,auto,uid=r3dux,gid=r3dux 0 0

You might notice reference to a .credentials file above. You need to create this!!

The format of the credentials file [you can call it anything & place it anywhere – just make sure you point to it in the fstab lines(s)] is:


So stick the above two lines in a file, substituting appropriately for the accounts and passwords on your NAS, then sudo chmod 600 it and remount the filesystem with sudo mount -a.

Job’s a good ‘un!

Update: Don’t forget – you’ll need to have samba, smbfs and cifs-utils installed for this to work! So go nuts with:

sudo apt-get install samba smbfs cifs-utils

How To: Mount a NAS in Linux (via Samba)

Rehaul: CIFS is the new Samba – and while the below is still a good way, CIFS seems to be the way & the path – so glance at this lot to get the fundamentals, then read this article to change to mounting your NAS via CIFS.

First, get samba with the following command: sudo apt-get install samba smbfs

Now, create a folder to use as your mount point on your linux drive (I’m using /mnt/NAS – you can use whatever you’d like): sudo mkdir /mnt/NAS

Then edit your /etc/fstab file with: sudo gedit /etc/fstab

On my NAS I have two separate shares, one of which is called (unimaginatively enough) Share, so I’m going to add lines to /etc/fstab in the following format:

# Mount NAS share

So  –  for my own personal setup, and because I’ve already created a username and password on the NAS [via the NAS’ web interface – available at http://IP-OF-YOUR-NAS] called r3dux, I’d put:

# Mount NAS share
// /mnt/NAS smbfs username=r3dux,password=MyPasswordHere,uid=1000,gid=1000 0 0

There are other ways where you don’t have to put your password in plaintext in the fstab file, but as long as you’ve got it set to read/write only by the root account, no one else can even look at the file to read the password. To set permissions that way, just use: sudo chmod 600 /etc/fstab

Which gives read and write permissions to root, but denies groups and any other users any access whatsoever (even just looking at!)

Job done.

Update: When mounting a NAS there are two user acounts you’re using: 1.) Your linux user account which goes in the uid and gid fields, and 2.) The NAS user account (which is set up from the NAS’ web interface) which goes into the username and password fields.

So if you want to have write access to the NAS, then you’ll need to set up a user account from the NAS’ web interface | Users sections, and mount the NAS as the user the NAS knows about with required privileges. In the fstab line above we’re mounting with user (uid) and group (gid) permissions set to 1000, that is user id 1000 (the id number of the first user on a linux system) [your user id can be looked up in /etc/passwd] and group id 1000 (i.e. the first user on a linux system [in my case my own r3dux group] – your group id can be looked up in /etc/group) – if you want to use other users/group to mount as, feel free.

Update 2: Forgot to mention that this will mount the NAS on reboot, to force a mount using the fstab details you’ve just entered, simply run the command sudo mount -a

Update 3: Fixed the above uid/gid mentions to NOT say anything about linux file permissions – it’s user and group identifiers to mount the NAS by, and NOT standard linux file permissions, mea culpa – fixed.