Gnuritas

dec 05, 2014

On Filesystems

This article was originally written in 2011, and was slightly updated in 2014.

Filesystem types and (lack of) compatibility

Despite the fact that we’re no longer living in the 1980s, filesystem-compatibility between operating systems seems to remain an issue in computer-land. The filesystem basically defines the way in which files are organised on a disk. In the 1980s, the popularity of MS-DOS led to widespread adoption of the FAT filesystem, which was also used in earlier Windows versions (½/3/95/98/ME). As NT-based Windows versions (NT/2000/XP/Vista/7) started becoming the mainstream consumer-versions, more and more computers started using Microsoft’s proprietary NTFS.

Nowadays, most external USB harddisks are sold pre-formatted with an NTFS-filesystem, while camera flash-cards and USB thumb-drives tend to still use a FAT32 filesystem. NTFS can be read (but not written by default) on Mac OS X, and can be read and written (but not properly repaired) by most modern Linux distributions. The default filesystem on Apple devices is HFS+, which cannot be accessed (by default) on Windows systems, but can be read (and written without journalling) on most Linux systems. Linux in turn mostly uses the ext2, ext3 or ext4 filesystem, which (by default) cannot be read on either Windows or Mac.

So actually, FAT -though ancient- is still the only filesystem that can (by default) can be accessed on all mainstream operating systems. Moreover, Linux is the only operating system that has out-of-the-box read (and mostly write) access to FAT, NTFS, HFS+ and ext⅔/4, as well as a load of other filesystems. Therefore, if I need a disk to be accessible on any computer, I format it as FAT32. Conversely, when I need to salvage data from a Windows/Mac/Linux system that won’t boot or is infected with malware, a Linux live-CD or bootable USB-stick with Knoppix or Ubuntu Rescue Remix tends to be my tool of choice…

Access to NTFS and ext⅔/4 on MacOS X

MacOS X can read NTFS volumes out of the box, but cannot write them. If you work with NTFS or ext⅔/4 volumes on a frequent basis, have a look at Tuxera NTFS for Mac, Paragon NTFS for Mac or Paragon ExtFS for Mac. There are also free alternatives, based on MacFUSE. First install MacFUSE. For NTFS, install the ntfs-3g driver. For ext2/ext3, use the fuse-ext2 driver. Follow this guide: http://www.ericwingate.com/2009/09/27/mounting-ext3-in-snow-leopard/

Access to Mac HFS+ disks and DMG images on Windows

Have a look at these:
http://www.catacombae.org/hfsx.html (free, read-only)
http://www.mediafour.com/products/macdrive/ (commercial)
http://www.paragon-software.com/home/hfs-windows/ (commercial)

Access to Linux ext⅔/4 on Windows

Have a look at these:
http://ext2read.blogspot.com/
http://www.fs-driver.org/ http://code.google.com/p/winflux/ (experimental?)
http://www.chrysocome.net/explore2fs
http://www.diskinternals.com/linux-reader/
http://www.soluvas.com/read-browse-explore-open-ext2-ext3-ext4-partition-filesystem-from-windows-7/

Renaming a FAT filesystem in Linux

In modern Linux distributions and on MacOS X, the volume label determines the mount-point of a filesystem. For instance, an USB disk which has a partition called MyDisk will be mounted under /media/MyDisk in Ubuntu. Sometimes the current volume label is not practical, so you want to be able to change it. By far the easiest way to change the volume label of most filesystem types in Linux is to use either the Gnome Disk Utility (System->Administration->Disk Utility) or the excellent GParted partition editor (in Ubuntu: install the gparted package and look under System->Administration). However, for some reason this will always result in an upper-case label on existing FAT filesystems. This is odd, because lower-case or mixed-case labels seem no problem when creating a new FAT filesystem. Luckily there is a workaround. First, clear the existing label (e.g. using Gparted or Disk Utility), and write down which device corresponds to the partition you want to change (e.g. /dev/sdf1). Then set the label using the dosfslabel tools from the dosfstools package. For instance: sudo dosfslabel /dev/sdf1 MixedCaseLabel

To check the result, run sudo blkid

After having done that, it’s wise to run a filesystem-check and fix any errors you encounter. Filesystem-checks can be run from Disk Utility, Gparted or from the commandline (e.g. sudo fsck -r /dev/sdf1).

Working with HFS+ in Ubuntu

If you want to be able to create and check HFS+ filesystems (e.g. in Gparted), you’ll need to install the hfsprogs package first. Unfortunately it currently does not seem possible to change the HFS+ volume label in Linux after creating the filesystem, so be sure to get it right the first time! Of course you can always use a Mac to rename it afterwards, just right-click on the disk-icon and choose rename, or use a terminal-command such as: diskutil rename "Old Label" "New Label"

Also, not that apparently Linux currently is incapable of writing to HFS+ filesystems that have journaling enabled, so you’ll need to disable journaling in Mac OS X before being able to write to a HFS+ volume in Linux. Reading a HFS+ filesystem with journaling anabled is of course no problem.

Access to DMG or ISO images

DMG and ISO files are disk-images, which means that they are essentially files formatted as if they were disks, with respectively a HFS+ (for DMG) or ISO9660 filesystem. Accessing the files inside such a “virual disk” is easy in Mac OS X (just open the file), but requires a bit more work on other systems:

For Ubuntu/Linux, see: https://help.ubuntu.com/community/ManageDiscImages

To mount ISO-files in Windows, try Daemon Tools Lite.

To access DMG files in Windows, try HFSExplorer.

Recovering files from broken filesystems

PhotoRec and TestDisk are two tools I’ve found particularly useful on occasions where filesystems were damaged. Both were written by Christophe Grenier, and can be installed on Ubuntu through the testdisk package. Before trying to repair a badly damaged filesystem, it’s always a good idea to make a disk-image backup of the damaged partition, e.g. with CloneZilla (if the disk has bad sectors, select Expert mode and use the “-rescue” option, and optionally “-g auto” and “-v”), Mondo Rescue or Clonezilla-SysRescCD. If the disk is really badly damaged, you may want to try GNU ddrescue, which is included on the above live-CDs (as well as on most other Linux live CDs).

The easiest network filesystem: SSHFS

Both at home and at University, most of my files are stored on a Linux desktop. If I want to access those files over the network, I can transfer them using a scp/sftp client such as FileZilla, or I can set up file-sharing over the network through Samba. However, a much easier solution is to use SSHFS, which allows you to mount a remote SSH server as if it were a local filesystem.

For Ubuntu: https://help.ubuntu.com/community/SSHFS

For Windows: http://dokan-dev.net/en/

For Mac OS X:
http://systems.cs.uoregon.edu/wiki/index.php?n=Help.AppsSSHMacSSHFS or http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS

Note that Gnome supports connecting to SSH servers out-of-the-box, e.g. by typing ssh://username@ssh.server.com in the location bar of the file-manager. However, this only works well for Gnome-applications. On my Ubuntu laptop, I therefore combine SSHFS with key-based SSH login and a launch-button on the Gnome-panel that uses sshfs to mount my desktop’s root directory at a mount-point in /media (which is owned by my user). This way, I only need one click in order to access all the files on my desktop, which is very handy (as long as my laptop isn’t stolen ;).