Sunday, May 27, 2007

Mounting Windows Partition

I need to mount 2 ntfs partitions and a Fat32 partition in Ubuntu. Right now, since I'm not setting up the ntfs write utility on my system, I need to only the Fat32 partition as writable. I would want these partitions to be automatically mounted every time I boot into Ubuntu, the easiest method would be to use the /etc/fstab file.

The fstab file is well structured into columns each separated by either a tab or space, I prefer tab since its easier on the eyes and I need it ;) !!

The structure of the file:


1st Column - This is the device/filesystem to be mounted (e.g. /dev/sda, foo.test.in:/home/test/)

2nd Column - This is the mount point for the filesystem, i.e. where we want to mount the device or fielsystem on the system (e.g. /mnt/Win/common)

3rd Column - Type of the filesystem i.e. to be mounted (vfat, ntfs, e.t.c.)

4th Column - A comma separated list of mount options for the filesystem.
Some common options (from manpage of fstab):
noauto - this means do not mount the filesystem on boot
user - allow a user to mount
owner - allow device owner to mount

5th Column - This field is used by dump command to determine which filesystems needs to be dumped. If '0' then filesystem does not need to be dumped.

6th Column - Used by fsck program to determine the order in which filesystem checks are to be done during reboot. If no value is specified then fsck will not check this filesystem. (NOTE: Linux automatically does an fsck check if the filesystem has been mounted, unmounted for a specific number of times.)
Initially I created the following /etc/fstab:


proc /proc proc defaults 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/sda5 /mnt/Win/softvideo ntfs rw,users 0 0
/dev/sda6 /mnt/Win/games ntfs rw,users 0 0
/dev/sda7 /mnt/Win/common vfat rw,users 0 0
And my designated mount points at the moment have the following permissions and owners:


libu@toxicware:/$ ll mnt/
total 4
drwxr-xr-x 5 libu libu 4096 2007-05-27 01:19 Win
libu@toxicware:/$ ll mnt/*
total 12
drwxr-xr-x 2 libu libu 4096 2007-05-27 01:19 common
drwxr-xr-x 2 libu libu 4096 2007-05-27 01:19 games
drwxr-xr-x 2 libu libu 4096 2007-05-27 01:19 softvideo
Now when I run the command "sudo mount -a", the directory structure changes as follows:


libu@toxicware:/$ ls -l mnt
total 4
drwxr-xr-x 5 libu libu 4096 2007-05-27 01:19 Win
libu@toxicware:/$ ls -l mnt/Win
total 20
drwxr-xr-x 13 root root 4096 1969-12-31 19:00 common
dr-x------ 1 root root 8192 2007-05-24 18:44 games
dr-x------ 1 root root 8192 2007-05-24 18:44 softvideo
I'm not sure why common has different directory permission from games and softvideo. The only reason I can think of is 'coz its a vfat filesystem.
Edit: I believe I was wrong about that. It must be because, I set game and softvideo as read-only partitions. That must be it me thinks.

And this setup does not help me, since I can't access the Windows partition as a normal user.
I solved this by setting umask to 0. (The default would have been 022). Now my fstab file looks like this:


proc /proc proc defaults 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/sda5 /mnt/Win/softvideo ntfs rw,users,umask=0 0 0
/dev/sda6 /mnt/Win/games ntfs rw,users,umask=0 0 0
/dev/sda7 /mnt/Win/common vfat rw,users,umask=0 0 0
So now after mounting the directory ownership and permissions read as follows:


libu@toxicware:/mnt$ ls -l Win/
total 20
drwxrwxrwx 13 root root 4096 1969-12-31 19:00 common
dr-xr-xr-x 1 root root 8192 2007-05-24 18:44 games
dr-xr-xr-x 1 root root 8192 2007-05-24 18:44 softvideo
So now I can access the directories as a normal user as well as write into the vfat common directory.

No comments: