December 16, 2013 · bash debian fstab linux productivity raspberrypi shell symlinks tricks windows

Mount a Windows Partition in Linux Using fstab

If you have dual-boot on your computer, you might realize you can use the same applications (or configuration/cachce/data direcotries) across installed operating systems without the need of configuring them separately.

This is a frequent scenario across my systems. I needed to create a symlink from my main system (Debian) to a folder on the same hard drive, but under Windows 7, which is located on a different partition. When you're using GUI, you might have noticed Nautilus mounting NTFS file systems (Windows fs) on each boot, but the symlinks break every single time. It might be tiring to manually create the symlink each and every time you boot up your computer. Thus, it's a good idea to create a mount point in fstab as a more reliable solution.

A bit of introduction. /dev/sda2 is my Windows 7 partition and I want it to be read+write in Linux under /mnt/windows.

First off we'll check the list of devices (partitions) with

sudo blkid

This will output something like:

/dev/sda5: UUID='a30XV7-BPsH-wURD-u0vU-Na3l-JL1I-HvxIgq' TYPE='LVM2_member' 
/dev/sda1: UUID='f56f8ad1-ee39-4a5b-bca1-ae3f744d0c1f' TYPE='ext2' 
/dev/sda2: UUID='E88450A5845077D0' TYPE='ntfs'

What this shows, are the unique identifiers of devices on the computer.

For example I now know 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.

Next, we create a location to mount the partition. The 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

Having done that, we edit fstab with

sudo nano /etc/fstab

After inspecting the file, on the top you will see lines of the 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="">
proc /proc proc nodev,noexec,nosuid 0 0

This is mostly self-explanatory:

<file system=""></file>, 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=""></mount> 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></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></options> provides extra settings for permission and such. You can use "default", but more advanced options can be read in the manual:

man fstab

Next, we add a new line for the partition or device you want to mount. Again, I wanted to mount the partition at /dev/sda2 to the location /mnt/windows

Add the following line to fstab:

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

Save the changes.

Now, you can mount all partitions with

sudo mount -a

Or, you can reboot your system and it will be mounted automatically.

Using the above steps you can successfully create a mount point using fstab and this allow (permanent) symlinks, persistent even after a reboot. I will write about creating symlinks and the possibilities of using them next time.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket