Header Shadow Image

Windows / Linux: Mutually accessing various filesystems on the same PC.

Especially true with dual boot systems, sharing files between two different operating systems on a single PC can become a time consuming task.  One thing many new users do when they install a Linux on a different partition of the same machine, is to try to connect to the other operating systems and files they have on the native OS.  At least do so without actually having to boot into windows OR linux again or having to resort to other combersome means of getting copies of your files between the two operating systems.  Fortunately latest versions of Linux come with an entire zoo of functions to do this with.  And the best part is, it's not that difficult at all:


Linux makes this easy.  There, the best way to get access to those files is to have them mounted on your linux filesystem so all you'll need to do is to run something like:

$ cd /mnt/c


$ cd /mnt/d

to access those Window (Or any other operating system) partitions and read / write or even execute from the newly connected windows partition. The command we'll use for this is the mount command and also the default built in Linux automounter daemon which runs when your box boots. To make mounting / unmounting simpler and have automounter handle this for you when you boot your box, the first thing you'll probably want to do is to define the partitions in /etc/fstab (This is the text config file the automounter and mount uses when you try to mount a drive without specifically telling mount what type of FS (filesystem) you're actually trying to mount. Let's suppose you have three windows partitions such as C:\> , D:\> and E:\>. Here's what your /etc/fstab might look like in this case:

$ cat /etc/fstab|grep vfat

/dev/hda1 /mnt/c vfat defaults 0 0

/dev/hda5 /mnt/d vfat defaults 0 0

/dev/hda6 /mnt/e vfat defaults 0 0 $ First column is the device. Unix devices reside in /dev. Here's what the letters in hda1 mean: hdHard Drive. This is your standard disk drive that comes with PC's. Typically h stands for IDE interface in systems. a – The physical disk. If you have more then one hard disk installed on your pc, the first will be a, the second b, the third c etc. On my system this is a. 1 – The partition on the physical disk. In my case I have three. C:\> = 1, D:\> = 5 and E:\> = 6 hence:

/dev/hda1 C:\>

/dev/hda5 D:\>

/dev/hda6 E:\>

On latest systems such as Fedora 9 you will see a slight change:

$ cat /etc/fstab|grep vfat

/dev/sda1 /mnt/c vfat defaults 0 0

/dev/sda5 /mnt/d vfat defaults 0 0

/dev/sda6 /mnt/e vfat defaults 0 0 $ In this case s stands for Serial Device which may be SATA / IDE or SCSI interface and newer Unix / Linux configurations use sda. Great. But how do you know on your system which are yours. You'll need to run

$ fdisk -l

(NOTE: More on fdisk later. For the moment we need it just to get some information on what partitions exist on our system.)

$ fdisk -l

will list hard disk information and their partitions similar to this:

$ fdisk -l Disk /dev/hda: 40.0 GB, 40020664320 bytes 255 heads, 63 sectors/track, 4865 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/hda1 * 1 1217 9775521 c W95 FAT32 (LBA)

/dev/hda2 1218 4865 29302560 f W95 Ext'd (LBA)

/dev/hda5 1218 2421 9671098+ b W95 FAT32

/dev/hda6 2422 4865 19631398+ b W95 FAT32

Disk /dev/hdb: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/hdb1 * 1 255 2048256 83 Linux

/dev/hdb2 256 4079 30716280 83 Linux

/dev/hdb3 4080 10453 51199155 83 Linux . . . . . Notice the information on /dev/hda. It tells you amongst other things, partition type, size, start and end cylinder etc. In our case we just need to know where our windows partitions are. Your values may differ. Once you've edited your /etc/fstab config file (NOTE: Some Linux editors available to you: vi, pico, nano. Type which <COMMAND> to find the paths they are located in. For GUI based editors, a couple of good ones are kate, kedit and kwrite. ) and saved it, it's time to create the mount points you defined above. In my case I'll use /mnt/c for C:\> etc. You can use any path you want. Traditionally the paths for mounting have been /mnt and more recently with new distributions /media but you can use any paths you want. Time to mount your partitions. All we need to do now is to issue the following command:

$ mount /mnt/c

mount will now look into your /etc/fstab to see how it should mount based on the parameter you passed to it. In fact you could also type:

$ mount /dev/hda1

and it would know what you're talking about since the entry has been devined in /etc/fstab. Without defining entries in /mnt/fstab your command line would be something like this:

$ mount -t vfat /dev/hda1 /mnt/c

which would also do the trick but you would loose the benefit of having the partition automounted at boot time and reducing extra parameter when mounting / unmounting. To unmount a partition type:

$ umount /mnt/c

to unmount the /mnt/c partition. Once you mount your windows partitions, all you need now is to go into the folder /mnt/c as you would into any other directory and browse, copy and edit files on it (provided you have 'w'rite access as well). Because you have the path defined in /etc/fstab the built in Linux automounter should also be able to mount these drives for you automatically on your next boot into your Linux installation. A cool feature of the mount utility is that mounting floppy disks and cdrom's is done in a similar manner. In fact, you can also do the same for ISO images in this manner:

$ mount -o loop /PATH/my_cd_image.iso /mnt/iso

Here's how your /etc/fstab might appear different if you also include your floppy disk and CD-ROM:

/dev/cdrom /mnt/cdrom auto noauto,unhide 0 0 # CD-ROM DRIVE

/dev/fd0 /mnt/floppy auto noauto 0 0 # Floppy disk.

In the case of the floppy disk, you'll need to mount/unmount as you swap floppies in the drive.



Leave a Reply


  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License