Automatically Mounting Windows Partitions at Boot Up
Monday, April 12, 2010 8:20:26 PM
If you are dual booting with windows, chances are that you'll need to share data between both windows and linux. Its very easy to do that with linux. The list of partitions that are to be mounted are specified in the /etc/fstab. Let me show you my fstab, before i add the windows partition.
Step 1:
Determine the id of the partition you want to mount. You can list all your partitions with fdisk.
I have all my music and movies in the partition /dev/sdb5 it is ntfs.
Step 2:
Now lets find my user id and group id. We'll use a nifty utility grep to search the /etc/passwd.Replace nikhil with your own username in the example below.
You can see that my uid is 1000 and gid is 100. Make a note of these values, these are different for different distros.
Step 3:
Modify the fstab file (You'll need to edit it as root).Now your fstab should look like this.
Step 4:
Let us check if we did it all correctly. Make sure you have the destination directory created before hand in this case /mnt/Data.You'll also need ntfs-3g most distributions ship it by default.
That should mount your partition correctly.You can check this by trying to delete/rename files there.This way you can access this partition as an ordinary user and create/modify/delete files as well.
Step 5:
Chances are that your fstab file wont be like mine.It'll have UUID's instead of the device nodes. You can find the UUID's for your partitions with the following command
All you have to do is replace your /dev/XXX with its UUID in the fstab.The lines will typically look like this.
Add entries in a similar manner for all partitions that you want to mount at boot.
Thats all you need to be able to mount your windows partitions on boot and access them as an ordinary user.
However you should be aware that if you get this wrong your computer may get stuck up at boot. Alwas check the changes that you make to the fstab by unmounting the partition and then "sudo mount -a".
# # /etc/fstab: static file system information # # <file system> <dir> <type> <options> <dump> <pass> devpts /dev/pts devpts defaults 0 0 shm /dev/shm tmpfs nodev,nosuid 0 0 #/dev/cdrom /media/cd auto ro,user,noauto,unhide 0 0 #/dev/dvd /media/dvd auto ro,user,noauto,unhide 0 0 #/dev/fd0 /media/fl auto user,noauto 0 0 /dev/sda1 / ext4 defaults 0 1 /dev/sda5 /home ext4 defaults 0 1 /dev/sda6 swap swap defaults 0 0
Step 1:
Determine the id of the partition you want to mount. You can list all your partitions with fdisk.
[nikhil@linux ~]$ sudo fdisk -l Password: Disk /dev/sda: 40.1 GB, 40059321856 bytes 255 heads, 63 sectors/track, 4870 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0004a919 Device Boot Start End Blocks Id System /dev/sda1 * 1 1252 10056658+ 83 Linux /dev/sda2 1253 4870 29061585 5 Extended /dev/sda5 1253 4807 28555506 83 Linux /dev/sda6 4808 4870 506016 83 Linux Disk /dev/sdb: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0d1ed32f Device Boot Start End Blocks Id System /dev/sdb1 * 1 3315 26624000 7 HPFS/NTFS /dev/sdb2 3315 19458 129664000 f W95 Ext'd (LBA) /dev/sdb5 3315 19458 129662976 7 HPFS/NTFS
I have all my music and movies in the partition /dev/sdb5 it is ntfs.
Step 2:
Now lets find my user id and group id. We'll use a nifty utility grep to search the /etc/passwd.Replace nikhil with your own username in the example below.
[nikhil@linux ~]$ grep nikhil /etc/passwd nikhil:x:1000:100:nikhil bhardwaj,,,:/home/nikhil:/bin/bash
You can see that my uid is 1000 and gid is 100. Make a note of these values, these are different for different distros.
Step 3:
Modify the fstab file (You'll need to edit it as root).Now your fstab should look like this.
# # /etc/fstab: static file system information # # <file system> <dir> <type> <options> <dump> <pass> devpts /dev/pts devpts defaults 0 0 shm /dev/shm tmpfs nodev,nosuid 0 0 #/dev/cdrom /media/cd auto ro,user,noauto,unhide 0 0 #/dev/dvd /media/dvd auto ro,user,noauto,unhide 0 0 #/dev/fd0 /media/fl auto user,noauto 0 0 /dev/sda1 / ext4 defaults 0 1 /dev/sda5 /home ext4 defaults 0 1 /dev/sda6 swap swap defaults 0 0 #Entry for the Data Partition /dev/sdb5 /mnt/Data ntfs-3g uid=1000,gid=100,fmask=0111,dmask=0000 0 0
Step 4:
Let us check if we did it all correctly. Make sure you have the destination directory created before hand in this case /mnt/Data.You'll also need ntfs-3g most distributions ship it by default.
[nikhil@linux ~]$ sudo mkdir /mnt/Data [nikhil@linux ~]$ sudo mount -a
That should mount your partition correctly.You can check this by trying to delete/rename files there.This way you can access this partition as an ordinary user and create/modify/delete files as well.
Step 5:
Chances are that your fstab file wont be like mine.It'll have UUID's instead of the device nodes. You can find the UUID's for your partitions with the following command
[nikhil@linux ~]$ sudo blkid Password: /dev/sda1: UUID="5b8fdb76-50b7-4b60-9851-46c5b77d4004" TYPE="ext4" /dev/sda5: UUID="1f13cda6-dd27-4bdf-b6cf-aa8ae8328dfe" TYPE="ext4" /dev/sda6: UUID="785c4a95-4ee1-4a01-8c56-a77d611a9fd7" TYPE="swap" /dev/sdb1: LABEL="Windows" UUID="80E063BBE063B5D6" TYPE="ntfs" /dev/sdb5: LABEL="Data" UUID="7A14D40C14D3C971" TYPE="ntfs"
All you have to do is replace your /dev/XXX with its UUID in the fstab.The lines will typically look like this.
#Entry for the Data Partition UUID=7A14D40C14D3C971 /mnt/Data ntfs-3g uid=1000,gid=100,fmask=0111,dmask=0000 0 0
Add entries in a similar manner for all partitions that you want to mount at boot.
Thats all you need to be able to mount your windows partitions on boot and access them as an ordinary user.
However you should be aware that if you get this wrong your computer may get stuck up at boot. Alwas check the changes that you make to the fstab by unmounting the partition and then "sudo mount -a".










