While running your Linux system, you may want to access data on a Windows hard drive partition, USB disk or similar device. Most modern Linux systems will automatically find ('mount') any disks, so you may find that you only turn on, or plug in your drive, USB stick etc. for it to be recognised by your Linux system.
However, there are occasions where you may need to manually configure your system to mount other partitions or hard drives. Fortunately, this is fairly straightforward.
This article describes how to mount Windows partitions (and similar) using the 'mount' command. It also describes how to allow non-root users access to the drive.
Preparation
Before mounting a new drive, you'll need to know it's Linux device name. (This is the name Linux uses internally to reference your devices.) Use the following table to find the first part of the device name
First SATA or SCSI hard drive - /dev/sda
Second SATA/SCSI hard drive - /dev/sdb
Fourth SATA/SCSI hard drive - /dev/sdd
First (master) PATA hard drive - /dev/hda
Second (slave) PATA hard drive - /dev/hdb
First SATA/SCSI CD-ROM drive - /dev/scd0
Second SATA/SCSI CD-ROM drive - /dev/scd1
If you are trying to mound a hard drive, you will need to add a partition number to the hard drive device name. For example, I want to mount my Windows drive, which is the second (SATA) disk inside the computer. The device name would be: /dev/sdb. The drive has only one partition, which is used by Windows. Therefore, my whole device name is /dev/sdb1. However, if you want to access the third partition on the second disk, the device name would be /dev/sdb3. Here a table with more example:
First SATA disk, Fourth Partition: /dev/sda2
Second SATA disk, First Partition: /dev/sdb1
Second SATA disk, Second Partition: /dev/sdb2
Third SATA disk, Third Partition: /dev/sdc1
First PATA disk, Second Partition: /dev/hda2
Second PARA disk, First Partition: /dev/hdb1
Now that you know the device name of your drive, you can go ahead and select the appropriate directory to mount the drive.
Open a terminal and type: 'ls /mnt'. The 'mnt' (mount) directory is the usual place where drives will be mounted. You may already be able to see other folders under /mnt that are being used be different drives and devices.
With the terminal still open, change to the root user using 'su'. (Alternatively, you can use sudo.) Then issue the following command: 'mkdir /mnt/windows/'. You have now created a sub-folder under /mnt, which you will use as a directory to mount the Windows partition.
Using the mount command
With all the preparation complete, you'll now be able to mount your drive. As root, issue the following command: mount /dev/hda2 /mnt/windows
You will need to change '/dev/hda2' to the appropriate device name.
Your drive should now be mounted and accessible be root. Still as root, type 'ls /mnt/windows'. If all is successful, you should be able to see files from your Windows files system.
Allowing all users to have access
In the previous example, the mount command was issued and the Windows partition was mounted under /mnt/windows. You may have noticed two problems, however:
- Non-root users are unable to access the drive at /mnt/windows
- The drive is not mounted automatically
To solve these problems, you can use the file /etc/fstab. The 'fstab' file tells the mount command which drives it should mount on system start and to use and special options (such as mounting 'read only').
An entry can be added to /etc/fstab to tell the mount command that the windows partition should be mounted automatically on boot, and that any user is allowed to access it. The /etc/fstab file has a certain style of formatting (syntax), which means such an entry will need to be added on a separate line and will look like the following.
/dev/hda1 /mnt/windows vfat user 0 0
This entry in /etc/fstab tells mount to mount the Windows partition (/dev/hda1/), to a directory (/mnt/windows), as a Windows (vfat file system and allow any user to mount the partition. The two zeros at the end need to also be added to the /etc/fstab entry, but are not relevant to what we want to to do. (For more information, see the fstab(5) man page).
Once there is an appropriate entry in /etc/fstab, any user will be able to mount and access the Windows partition by issuing a command like mount /mnt/windows. (The command does not now need to be given a device/partition name like /dev/hda1.)
To make set the Windows partition to be mounted every time the system starts, the /etc/fstab entry would be like the following:
/dev/hda1 /mnt/windows vfat auto,user 0 0
This fstab entry is identical to the previous example, except that the word 'auto' has been added to the fourth field. (Make sure that there is no space between the words auto and user.)
If you want to make sure that the partition is not mounted automatically, the word 'auto' can be substituted for 'noauto'.
/dev/hda1 /mnt/windows vfat noauto,user 0 0
Further Information
The alt.os.linux.slackware FAQ mentions ways to mount a Windows partition so that only certain users have access.
See also the mount(8) and fstab(5) man pages on your system.
Comments
Was this page useful to you? Did it make sense? Feel free to send me a message with your feedback.
Page written by Mark Hill
- Article created: 2004-09-01
- Last updated: 2008-10-04