Showing posts with label symlink. Show all posts
Showing posts with label symlink. Show all posts

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.

Thursday, April 4, 2013

Create Symbolic Links in Ubuntu

The 2 types of links are hard links and soft links .

A hard link is essentially a file with multiple names, there are multiple copies of the file. So that if one of the hard links is deleted, the file persists to exist.

A soft link (also called symlink or symbolic link) is a file system entry that points to the file name and location. Deleting the symbolic link does not remove the original file. If, however, the file to which the soft link points is removed, the soft link stops working, it is broken.

Symbolic links can be created both from the terminal and from nautilus (file manager, GUI). 
 

Terminal

 

The syntax for creating a symbolic link is,
ln -s target source
where,
  • target - The existing file/directory you would like to link TO.
  • source - The file/folder to be created, copying the contents of the target. The LINK itself.
For more help see ln --help

Example:
ln -s /home/nargren/Pictures /home/nargren/Pictures_Backup
This would create a symbolic link directory called "Pictures_Backup" to my "Pictures" directory. All the content in either of the 2 directories would appear in the other one as well.

GUI

 

You can easily create a symbolic link to a folder or file by middle clicking on the folder with the mouse and dragging it to its new location, while holding the middle mouse button.

Remove Symbolic Links

 

To remove a symbolic link, be it a file or directory, simply remove the created link. This can be done either through nautilus (GUI) or using the rm and rm -f commands in the terminal.

Use of Symbolic Links

 

Symbolic links are especially useful on computers with dual-boot, running for example Windows and Linux. As symbolic links can be created across partitions and file systems, windows folders can be linked to appropriate Ubuntu folders.

I will bring my own example of using Mozilla Thunderbird as e-mail client. I would like to have my emails and profiles available, including all my downloaded emails on both operating systems. This could be done either by downloading all new e-mails when I start the software on any of the two operating systems, or via symbolic links. As I had problems downloading new emails with multiple clients, I have chosen to make a symbolic link.

I have linked my Windows
[USER]\AppData\Roaming\Thunderbird
 folder to the Ubuntu directory
 home/.thunderbird
This allowed me to download my emails only once and have them available on both Windows and Linux while keeping my entire profile.