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.

No comments:

Post a Comment