Linux-Windows file access
Anyone who uses both Linux and Windows knows the problem. You need a couple of files that are on the Windows partition, but you forgot to copy them to a floppy or to the server before rebooting to Linux. Wouldn't it be great if you could just access those files from Linux, you think, as you prepare yourself for two more reboots.
As it turns out, there are a number of ways to solve that problem. You can mount your Windows partitions under Linux and you can access your ext2 filesystems under Windows. You can also access Linux (and Unix) servers from Windows via Samba and you can even mount Windows filesystems under Linux using smbmount. We will look at each of these methods below.
But there are more solutions on the horizon. The folks at Caldera have funded me to write a Samba client library. Please see the Resources section for more details. That library allows Linux and Unix systems to access Windows resources from within programs. Parts of the library already are available in the Samba CVS tree, and once the library becomes more generally used, programs like Midnight Commander and others should be able to browse the Windows systems on your network.
Accessing Windows files from Linux
There are plenty of Windows filesystems to worry about. There is the plain old DOS system with its 8,3 filenames. There is the long filename support introduced with Windows 95. There is the FAT32 file system introduced with the latter versions of Windows 95 and Windows 98 (known as VFAT filesystems). Finally, there is the NT filesystem, or NTFS.
Linux has been able to access MS-DOS and VFAT filesystems for quite some time. Read-only access to NTFS partitions has also been available for a while. In the past, you got NTFS support by downloading a driver that provided read-only access to NTFS partitions. Since Linux 2.2.x, however, read-only and read-write NTFS support has been a standard part of the kernel (albeit still considered experimental).
Unfortunately, that means it is not as easy to access Windows partitions under Linux as it is under Windows: You must first mount the partitions in order to access them. For example, if your hard disk is partitioned in the following way:
/dev/hda1 -- Windows 9x filesystem
/dev/hda2 -- Linux swap partition
/dev/hda3 -- Linux root filesystem
and you want to mount the Windows partition under /mnt/windows, use the command mount /dev/hda1 /mnt/windows.
Note that there is no need to specify a filesystem type (such as mount -t vfat /dev/hda1 /mnt/windows) because the mount command tries to mount the filesystem as VFAT before it tries MS-DOS.
After executing the above command, you can explore your Windows partition using any Linux command you want. You can read or write files on your Windows partition, and you can edit them using editors like vi and Emacs. Listing 1 shows an example of listing the files on your Windows partition.
However, if you get a detailed listing on your Windows partition, you may notice that the files in the partition have some interesting properties. For one thing, the user and group of the person who mounted the filesystem owns all of them. That person may be root. That happens because Windows 9x has no concept of user and group owners of files.
Linux can mount both MS-DOS and VFAT filesystems. When you issue the mount command, simply use msdos rather than vfat:
mount -t msdos /dev/hda1 /mnt/win98
That will mount the partition, but you will see only MS-DOS-style filenames. Listing 2 shows an example of listing files on a Windows 98 partition after it has been mounted as an MS-DOS filesystem.
You can mount an NTFS partition in a similar fashion. Assuming that your NTFS partition is located on /dev/hda1, simply enter the following command:
mount -t ntfs /dev/hda1 /mnt/win98
Of course, manually entering those mount commands can get a bit tiresome if you swap between Windows and Linux frequently, so you might like to add an entry in the file /etc/fstab to automate the process. Simply add a line like the following to /etc/fstab to automatically mount your Windows 9x partition at boot time:
/dev/hda1 /mnt/windows vfat defaults 00
Listing 3 shows an example of what your fstab file might look like with this new entry added.
You also might want to access VFAT devices to use floppies. Floppies are quite convenient for moving files between systems, and they are almost always in DOS format, rather than say, ext2 format. You can mount floppies in just the same way as you might a Windows partition on your hard disk:
mount -t vfat /dev/fd0 /mnt/floppy
Indeed, with modern Linux distributions, you can leave out the -t vfat and Linux will figure out the correct type. Another useful shortcut is to simply type mount /dev/fd0, because the Linux mount command can retrieve the rest of the information needed to mount the floppy from /etc/fstab. For more information about the mount and umount commands see man mount and man umount, respectively.
I don't know about you, but I get very tired of having to mount floppies just to access the files on them. You also have to remember to umount the floppy when you have finished using it and want to use another floppy.
Fortunately, the mtools package, which installs with many Linux distributions these days, contains a series of commands that eliminates all this mounting and umounting of floppies. It contains a series of commands for dealing with MS-DOS formatted floppies including mdir to list the files on a floppy, mcopy to copy files to or from floppies, mdel, and so forth. Those commands are the same as the MS-DOS commands to manipulate floppies with an "m" added to the front of each command. You may have to install the mtools package from your installation CD. Under Red Hat 7.0, the package to install is mtools-3.9.7-3.i386.rpm.
Listing 4 shows an example of using commands from the mtools package to list the contents of a floppy and copy files from the floppy to the user's current directory. For more information about the mtools package, try man mtools.
If you have a mixed network of Windows and Linux systems, you may want to mount file systems from your Windows systems on your Linux machine. You can do that with the smbmount command, but since smbmount command is called from the mount command, it is just as easy to use mount.
Listing 5 shows an example of mounting the C drive from my Windows 95 system running under VMware as /mnt/win9x. For more information on smbmount, see man smbmount.
Accessing Linux files from Windows
I have no doubt that most of us need access to Windows filesystems from Linux, but many of us also need access to our Linux filesystems under Windows from time to time. There are a couple of ways to do that depending on your circumstances.
If you are on a network and want to access files on a Linux server from your Windows machine, Samba is the ideal solution. It looks very much like the Windows NT server and provides access to files on your Linux server from Windows systems. See Resources for more information on Samba.
You might also want to access a Linux ext2 partition on your machine from Windows if you have a dual-boot setup. Fear not, as there are also ways to do that. There are a number of approaches to access your ext2 filesystems from Windows. Those include LTools (for DOS and Windows 3.x, 9x, and NT), explore2fs (for Windows 95 and Windows NT), FSDext2 (for Windows 9x) and ext2fsnt (for NT). All of them are discussed in the Filesystems HOWTO (see Resources), which contains links to download each of the tools.
Each of those operates in different ways. For example, FSDext2 and ext2fsnt provide device drivers that access ext2 partitions on the Windows machine with standard Windows commands and tools. LTools and explore2fs provide commands that explore your ext2 partitions from Windows. Unfortunately, FSDext2 provides read-only access to your ext2 partitions, though the all the others provide read-write access.
FSDext2 is very easy to install under Windows 9x. Simply extract the files, run the install batch file, reboot (yes, Windows requires many reboots), and then mount your filesystem as a drive letter. Figure 1 shows an example of listing the files on an ext2 partition, while Figure 2 shows how to use the mount command to unmount and then mount an ext2 partition to drive L:.
For more information on that subject, see the Filesystems HOWTO (see Resources for a link).
The future
Some people will always need to access filesystems from different operating systems, whether MS-DOS or VFAT from Linux, or ext2 from Windows. So the tools we discussed will prove useful to those people. However, more and more people live in a networked world where they have a mixture of Linux and Windows systems available, and they would like to browse resources on all systems in the network.
While smbclient from Samba can provide that ability, it is a command line-oriented tool, and many people would like a GUI tool for browsing the network and looking at files on Windows systems. The KDE package Konqueror can do that, but it is based on a C++ library for accessing Windows and Samba systems. The library is no longer supported, which makes it hard for non-C++ programs to access Windows systems.
However, as I mentioned above, Caldera has funded the development of a new Samba client library, to be written in C. Once that library is released in final form (some code has already been released), developers should find it much easier to integrate access to Windows systems into their applications. The library will include a GTK+ test program that could serve as a starting point for developers who want access to Windows systems.
Finally, while it promises to get easier and easier to access Windows systems from Linux, and you can already access Linux systems from Windows, there will always be a need, by some people, to use the tools mentioned in this article.
http://www.penguin.cz/~mhi/fs/Filesystems-HOWTO/Filesystems-HOWTO.html
http://www.chat.ru/~ashedel/ext2fsnt/
http://www.yipton.demon.co.uk/
http://ir.caldera.com/wc/form/P1?template=ir/CALD/view_article&Symbol=CALD&first=&ArticleID=SM-CALD-20001219
Listing 1: listing the files on your Windows partition
[root@testy /root]# ls /mnt/windows/
$ldr$ boot.bak config.sys msdos.dos recycled v
$win_nt$.~bt boot.ini config.win msdos.sys scandisk.log windows
Image2.psp bootlog.prv detlog.old netlog.txt scanjet winnt
Program Files bootlog.txt detlog.txt nm setuplog.old winntws
Untitled.tif bootsect.dos i386 nm.zip setuplog.txt
arcldr.exe command.com io.dos ntdetect.com suhdlog.dat
arcsetup.exe config.001 io.sys ntldr system.1st
autoexec.bat config.dos logo.sys osr2 temp
boot.--- config.pol msdos.--- pagefile.sys txtsetup.sif
[root@testy /root]# ls -al /mnt/windows/
total 56417
-r-xr-xr-x 1 root root 229264 Dec 7 1999 $ldr$
drwxr-xr-x 3 root root 16384 Apr 25 2000 $win_nt$.~bt
drwxr-xr-x 13 root root 16384 Jan 1 1970 .
drwxr-xr-x 13 root root 1024 Jan 10 16:39 ..
-rwxr-xr-x 1 root root 1081834 Jul 19 2000 Image2.psp
dr-xr-xr-x 17 root root 16384 Oct 12 1998 Program Files
-rwxr-xr-x 1 root root 884874 Jul 19 2000 Untitled.tif
-r-xr-xr-x 1 root root 148992 Sep 9 1999 arcldr.exe
-r-xr-xr-x 1 root root 161792 Sep 9 1999 arcsetup.exe
-rwxr-xr-x 1 root root 0 May 17 2000 autoexec.bat
-rwxr-xr-x 1 root root 295 Oct 12 1998 boot.---
-r-xr-xr-x 1 root root 651 Nov 15 1999 boot.bak
-r-xr-xr-x 1 root root 649 Apr 25 2000 boot.ini
-rwxr-xr-x 1 root root 16481 Jan 15 2000 bootlog.prv
-rwxr-xr-x 1 root root 99924 Jan 15 2000 bootlog.txt
-rwxr-xr-x 1 root root 512 Sep 27 1999 bootsect.dos
-rwxr-xr-x 1 root root 93812 Aug 24 1996 command.com
-rwxr-xr-x 1 root root 0 Feb 19 2000 config.001
-rwxr-xr-x 1 root root 0 Oct 12 1998 config.dos
-rwxr-xr-x 1 root root 8192 Jan 15 2000 config.pol
-rwxr-xr-x 1 root root 0 Feb 19 2000 config.sys
-rwxr-xr-x 1 root root 0 Jan 16 2000 config.win
-rwxr-xr-x 1 root root 37452 Sep 26 1999 detlog.old
-rwxr-xr-x 1 root root 68525 Feb 19 2000 detlog.txt
dr-xr-xr-x 5 root root 81920 Nov 16 1998 i386
-rwxr-xr-x 1 root root 0 Oct 12 1998 io.dos
-r-xr-xr-x 1 root root 214836 Aug 24 1996 io.sys
-rwxr-xr-x 1 root root 129078 Aug 24 1996 logo.sys
-rwxr-xr-x 1 root root 22 Sep 26 1999 msdos.---
-rwxr-xr-x 1 root root 0 Oct 12 1998 msdos.dos
-r-xr-xr-x 1 root root 1657 Mar 15 2000 msdos.sys
-rwxr-xr-x 1 root root 1923 Sep 26 1999 netlog.txt
drwxr-xr-x 4 root root 16384 Nov 3 1999 nm
-rwxr-xr-x 1 root root 2180118 Nov 16 1998 nm.zip
-r-xr-xr-x 1 root root 34468 Dec 7 1999 ntdetect.com
-r-xr-xr-x 1 root root 214416 Dec 7 1999 ntldr
dr-xr-xr-x 4 root root 16384 Sep 26 1999 osr2
-rwxr-xr-x 1 root root 50331648 Nov 15 1999 pagefile.sys
drwxr-xr-x 2 root root 16384 Oct 12 1998 recycled
-rwxr-xr-x 1 root root 1052 Mar 4 2000 scandisk.log
drwxr-xr-x 3 root root 16384 Feb 19 2000 scanjet
-rwxr-xr-x 1 root root 55521 Sep 26 1999 setuplog.old
-rwxr-xr-x 1 root root 1209 Jan 16 2000 setuplog.txt
-rwxr-xr-x 1 root root 7738 Sep 26 1999 suhdlog.dat
-rwxr-xr-x 1 root root 431488 Sep 26 1999 system.1st
drwxr-xr-x 6 root root 16384 Oct 12 1998 temp
-r-xr-xr-x 1 root root 356925 Dec 7 1999 txtsetup.sif
-rwxr-xr-x 1 root root 360448 Sep 22 1999 v
drwxr-xr-x 29 root root 16384 Sep 26 1999 windows
drwxr-xr-x 13 root root 16384 Sep 27 1999 winnt
drwxr-xr-x 17 root root 16384 Oct 12 1998 winntws
Listing 2: listing files on a Win98 partition mounted as MS-DOS
Script started on Tue Jan 16 13:33:20 2001
[root@testy /root]# ls /mnt/windows
$ldr$ bootlog.txt detlog.txt netlog.txt scandisk.log v
$win_nt$.~bt bootsect.dos i386 nm scanjet windows
arcldr.exe command.com image2.psp nm.zip setuplog.old winnt
arcsetup.exe config.001 io.dos ntdetect.com setuplog.txt winntws
autoexec.bat config.dos io.sys ntldr suhdlog.dat
boot.--- config.pol logo.sys osr2 system.1st
boot.bak config.sys msdos.--- pagefile.sys temp
boot.ini config.win msdos.dos progra~1 txtsetup.sif
bootlog.prv detlog.old msdos.sys recycled untitled.tif
[root@testy /root]# ls -al /mnt/windows/
total 56417
-r-xr-xr-x 1 root root 229264 Dec 7 1999 $ldr$
drwxr-xr-x 3 root root 16384 Apr 25 2000 $win_nt$.~bt
drwxr-xr-x 13 root root 16384 Jan 1 1970 .
drwxr-xr-x 13 root root 1024 Jan 10 16:39 ..
-r-xr-xr-x 1 root root 148992 Sep 9 1999 arcldr.exe
-r-xr-xr-x 1 root root 161792 Sep 9 1999 arcsetup.exe
-rwxr-xr-x 1 root root 0 May 17 2000 autoexec.bat
-rwxr-xr-x 1 root root 295 Oct 12 1998 boot.---
-r-xr-xr-x 1 root root 651 Nov 15 1999 boot.bak
-r-xr-xr-x 1 root root 649 Apr 25 2000 boot.ini
-rwxr-xr-x 1 root root 16481 Jan 15 2000 bootlog.prv
-rwxr-xr-x 1 root root 99924 Jan 15 2000 bootlog.txt
-rwxr-xr-x 1 root root 512 Sep 27 1999 bootsect.dos
-rwxr-xr-x 1 root root 93812 Aug 24 1996 command.com
-rwxr-xr-x 1 root root 0 Feb 19 2000 config.001
-rwxr-xr-x 1 root root 0 Oct 12 1998 config.dos
-rwxr-xr-x 1 root root 8192 Jan 15 2000 config.pol
-rwxr-xr-x 1 root root 0 Feb 19 2000 config.sys
-rwxr-xr-x 1 root root 0 Jan 16 2000 config.win
-rwxr-xr-x 1 root root 37452 Sep 26 1999 detlog.old
-rwxr-xr-x 1 root root 68525 Feb 19 2000 detlog.txt
dr-xr-xr-x 5 root root 81920 Nov 16 1998 i386
-rwxr-xr-x 1 root root 1081834 Jul 19 2000 image2.psp
-rwxr-xr-x 1 root root 0 Oct 12 1998 io.dos
-r-xr-xr-x 1 root root 214836 Aug 24 1996 io.sys
-rwxr-xr-x 1 root root 129078 Aug 24 1996 logo.sys
-rwxr-xr-x 1 root root 22 Sep 26 1999 msdos.---
-rwxr-xr-x 1 root root 0 Oct 12 1998 msdos.dos
-r-xr-xr-x 1 root root 1657 Mar 15 2000 msdos.sys
-rwxr-xr-x 1 root root 1923 Sep 26 1999 netlog.txt
drwxr-xr-x 4 root root 16384 Nov 3 1999 nm
-rwxr-xr-x 1 root root 2180118 Nov 16 1998 nm.zip
-r-xr-xr-x 1 root root 34468 Dec 7 1999 ntdetect.com
-r-xr-xr-x 1 root root 214416 Dec 7 1999 ntldr
dr-xr-xr-x 4 root root 16384 Sep 26 1999 osr2
-rwxr-xr-x 1 root root 50331648 Nov 15 1999 pagefile.sys
dr-xr-xr-x 17 root root 16384 Oct 12 1998 progra~1
drwxr-xr-x 2 root root 16384 Oct 12 1998 recycled
-rwxr-xr-x 1 root root 1052 Mar 4 2000 scandisk.log
drwxr-xr-x 3 root root 16384 Feb 19 2000 scanjet
-rwxr-xr-x 1 root root 55521 Sep 26 1999 setuplog.old
-rwxr-xr-x 1 root root 1209 Jan 16 2000 setuplog.txt
-rwxr-xr-x 1 root root 7738 Sep 26 1999 suhdlog.dat
-rwxr-xr-x 1 root root 431488 Sep 26 1999 system.1st
drwxr-xr-x 6 root root 16384 Oct 12 1998 temp
-r-xr-xr-x 1 root root 356925 Dec 7 1999 txtsetup.sif
-rwxr-xr-x 1 root root 884874 Jul 19 2000 untitled.tif
-rwxr-xr-x 1 root root 360448 Sep 22 1999 v
drwxr-xr-x 29 root root 16384 Sep 26 1999 windows
drwxr-xr-x 13 root root 16384 Sep 27 1999 winnt
drwxr-xr-x 17 root root 16384 Oct 12 1998 winntws
Listing 3: a modified fstab file
/dev/hda3 / ext2 defaults 1 1
/dev/hda2 swap swap defaults 0 0
/dev/hda1 /mnt/windows vfat defaults 0 0
/dev/fd0 /mnt/floppy auto sync,user,noauto,nosuid,nodev,unhide 0 0
/dev/cdrom /mnt/cdrom auto user,noauto,nosuid,exec,nodev,ro 0 0
none /proc proc defaults 0 0
none /dev/pts devpts mode=0622 0 0
Listing 4: using mtools commands
[root@testy /root]# mdir
Volume in drive A has no label
Directory for A:/
TESTLCD LST 40821 08-22-2003 11:52
YELLOW~1 PPT 54272 12-11-2000 12:15 Yellow River1.ppt
TUTOR DOC 36864 12-19-2000 0:08 tutor.doc
CHRIS00 DOC 11264 12-18-2000 2:26
017 ZIP 84206 01-10-2001 14:53 017.zip
TESTLCD ASM 11531 08-22-2003 11:48 testlcd.asm
ULTRAS~1 DOC 50688 08-22-2000 12:27 Ultrasonic Proximity Detector.doc
MULTIP~1 DOC 109568 08-24-2000 15:26 Multiplexing.doc
TOO_CL~1 DOC 61440 08-24-2000 15:38 too_close.doc
9 files 460 654 bytes
996 352 bytes free
[root@testy /root]# mcopy a:017.zip ./017-v1.zip
[root@testy /root]# ls -al 017-v1.zip
-rw-r--r-- 1 root root 84206 Jan 16 13:47 017-v1.zip
Listing 5: mounting C: from VMware
[root@nemesis /root]# mount -t smbfs //w95vmware/c /mnt/windows>
Password:
[root@nemesis /root]# ls /mnt/windows
319026r.doc Eudora NETLOG.TXT docs nicole
AUTOEXEC.BAT F-SECURE NM ethereal rjs-res-train.doc
BOOTBLOC.DD IO.SYS Program Files ffastun.ffa story
BOOTLOG.PRV LPD_Que RECYCLED ffastun.ffl tcp.txt
BOOTLOG.TXT MSDOS.--- SCANDISK.LOG ffastun.ffo temp
CMS MSDOS.SYS SETUPLOG.TXT ffastun0.ffx winzip.log
COMMAND.COM Multimedia Files SUHDLOG.DAT home-proj xinstall
CONFIG.SYS My Documents SYSTEM.1ST logo.sys
DETLOG.TXT My Music WINDOWS nat
[root@nemesis /root]# ls -al /mnt/windows
total 3720
drwxr-xr-x 1 root root 512 Jan 16 12:25 .
drwxr-xr-x 10 root root 4096 Jan 16 11:54 ..
-rwxr-xr-x 1 root root 45568 Feb 15 2000 319026r.doc
-rwxr-xr-x 1 root root 0 Aug 10 1999 AUTOEXEC.BAT
-rwxr-xr-x 1 root root 512 Sep 30 1999 BOOTBLOC.DD
-rwxr-xr-x 1 root root 24948 Jun 24 2000 BOOTLOG.PRV
-rwxr-xr-x 1 root root 24948 Jun 24 2000 BOOTLOG.TXT
drwxr-xr-x 1 root root 512 Jan 16 12:25 CMS
-rwxr-xr-x 1 root root 93812 Aug 24 1996 COMMAND.COM
-rwxr-xr-x 1 root root 0 Aug 10 1999 CONFIG.SYS
-rwxr-xr-x 1 root root 28143 Jul 7 1999 DETLOG.TXT
drwxr-xr-x 1 root root 512 Jan 16 12:25 Eudora
drwxr-xr-x 1 root root 512 Jan 16 12:25 F-SECURE
-r-xr-xr-x 1 root root 214836 Aug 24 1996 IO.SYS
drwxr-xr-x 1 root root 512 Jan 16 12:25 LPD_Que
-rwxr-xr-x 1 root root 22 Jul 7 1999 MSDOS.---
-r-xr-xr-x 1 root root 1641 Apr 5 2000 MSDOS.SYS
drwxr-xr-x 1 root root 512 Jan 16 12:25 Multimedia Files
drwxr-xr-x 1 root root 512 Jan 16 12:25 My Documents
drwxr-xr-x 1 root root 512 Jan 16 12:25 My Music
-rwxr-xr-x 1 root root 489 Jul 7 1999 NETLOG.TXT
drwxr-xr-x 1 root root 512 Jan 16 12:25 NM
dr-xr-xr-x 1 root root 512 Jan 16 12:25 Program Files
drwxr-xr-x 1 root root 512 Jan 16 12:25 RECYCLED
-rwxr-xr-x 1 root root 513 Dec 15 22:10 SCANDISK.LOG
-rwxr-xr-x 1 root root 53236 Jul 7 1999 SETUPLOG.TXT
-r-xr-xr-x 1 root root 5166 Jul 7 1999 SUHDLOG.DAT
-r-xr-xr-x 1 root root 406984 Jul 7 1999 SYSTEM.1ST
drwxr-xr-x 1 root root 512 Jan 16 12:25 WINDOWS
drwxr-xr-x 1 root root 512 Jan 16 12:25 docs
drwxr-xr-x 1 root root 512 Jan 16 12:25 ethereal
-rwxr-xr-x 1 root root 5490 Jan 16 11:27 ffastun.ffa
-rwxr-xr-x 1 root root 483328 Jan 16 11:27 ffastun.ffl
-rwxr-xr-x 1 root root 233472 Jan 16 11:27 ffastun.ffo
-rwxr-xr-x 1 root root 1925120 Jan 16 11:27 ffastun0.ffx
drwxr-xr-x 1 root root 512 Jan 16 12:25 home-proj
-rwxr-xr-x 1 root root 129078 Aug 24 1996 logo.sys
drwxr-xr-x 1 root root 512 Jan 16 12:25 nat
drwxr-xr-x 1 root root 512 Jan 16 12:25 nicole
-rwxr-xr-x 1 root root 99840 Oct 30 21:58 rjs-res-train.doc
drwxr-xr-x 1 root root 512 Jan 16 12:25 story
-rwxr-xr-x 1 root root 2024 Nov 3 1999 tcp.txt
drwxr-xr-x 1 root root 512 Jan 16 12:25 temp
-rwxr-xr-x 1 root root 11294 Jan 9 19:28 winzip.log
drwxr-xr-x 1 root root 512 Jan 16 12:25 xinstall