Linux file system and disks

Saturday, 13 August 2005, michuk

The file system organization in GNU/Linux (and other Unices) differs a lot from what you may be familiar with (the Windows way of doing things). First of all, in Linux we don’t have virtual drives C:, D:, etc. All of the available drives and resources are located in the folder tree under the magical /, which is called the root folder (not to be mistaken with the root user — it’s a completely different thing).

Basic stuff – where are my Program Files??

So, if we have a few partitions on our disk, we mount them as a chosen folder in the tree. For example, if we want a specific partition to be our home folder, we mount it as /home. And so on. Moreover, the same applies to the external resources like floppy disks, CD-ROMs or USB sticks. According to the FHS standards, they should mounted under the /media folder. Np. /media/cdrom0, /media/fd0, etc. In older systems, these devices often used to be mounted directly under the root directory or under the /mnt folder. Soft links (shortcuts) are usually still created in those places.

There is also another difference concerning the localization of the installed application. Because of the high modularity of the Linux packages (lots of apps are not independent and require other programs for proper functioning), the programs are not usually installed in separate folders (like the Program Files folder and its children). Instead, files are put into predefined places in the directory tree, so that they could be easily located by other apps. This concerns the dynamic libraries andthe executable files the most. So, instead of the well-known Program Files we have separate folders: bin for binaries, lib for libraries, doc for documentation, and lots of others used for specific purposes.
A detailed description of the FHS specifiction which specifies the standards in located here: Filesystem Hierarchy Standard.

That’s it about the theory. Now, let’s get to the practice. The table below presents the popular Windows file system locations and their Linux counterparts.

Main folders location in the file system
MS Windows GNU/Linux
Root C:\ /
Home folder C:\Documents and settings\USER\My documents (XP) or C:\Users\USER (Vista) /home/USER (np. /home/zdzisiek)
Configuration files Hidden, accessible by the regedit command /etc
System files C:\Windows Binaries: /bin, /sbin
Libraries: /lib
Installed apps C:\Program Files Binaries: /usr/bin, /usr/local/bin, etc
Libraries: /usr/lib, /usr/local/lib, /usr/share/lib, etc
Documentation: /usr/share/doc/, /usr/doc, etc
CDROM D:\ (or another virtual drive) /media/cdrom (or alternatively /mnt/cdrom or /cdrom)
Floppy drive A:\ /media/fd0 (or alternatively /mnt/fd0 or /floppy)

Managing partitions and drives (/etc/fstab)

In the article How to edit and understand /etc/fstab this key Linux files has been described in detail. Here we’ll try to provide the basics only.

In general, in /etc/fstab we tell the system which resources (drives, partitions, external devices and shared file systems) we want to use. The resources can be mounted during the system startup or manually (option auto/nonauto).

Mounting disks – why do I need to do it?

You don’t have to do it – you want to :)
All the resources in Linux system need to be mounted before they are used and unmounted before ejecting (if possible). In Windows it’s no different (it only does it automatically in the background). Linux can also do it automatically but you have a choice. In the newbie-friendly distros, most of the popular resources like CD-ROMs and USB sticks are mounted by the system. Still, we should understand how to do things manually in case of a failure.

The key command is mount. When used together with a folder defined in /etc/fstab), e.g.

mount /media/cdrom

, it mounts this resource. Similarily,

umount /media/cdrom

will unmount this share or device.

How to mount a Windows partition?

Windows supports two file system types: FAT – older, more primitive but better supported under Linux (read and write access without problems), and NTFS which had problemis in the past under Linux but now it’s as simple as in FAT thanks to ntfs-3g. Still in some distros NTFS is supported read-only by default so it such case you should follow some ntfs-3g guide like this one: Windows NTFS Partitions Read/write support made easy in Ubuntu Feisty

In order to mount a Windows partition we first have to know how the Linux system sees it. We can use fdisk, program for that:

# fdisk -l /dev/hda

Disk /dev/hda: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot     Start         End      Blocks   Id  System
/dev/hda1           1        1211     9727326    7  HPFS/NTFS
/dev/hda2        1216        7296    48845632+   5  Extended
/dev/hda5   *    1216        3040    14648224+  83  Linux
/dev/hda6        3041        3679     5132736    b  W95 FAT32
/dev/hda7        3680        4049     2971993+  83  Linux
/dev/hda8        4050        4319     2168743+  82  Linux swap
/dev/hda9        4320        7296    23908216+  83  Linux

This shows us the whole primary master hard drive (/dev/hda) with all the partitions and the device names. We can notice two Windows partitions on this disk. One is hda1 (NTFS), and second is hda6 (FAT32). So now, in order to mount them, it’s enough to type:

# mount -t ntfs /dev/hda1 /mnt/C
# mount -t vfat /dev/hda1 /mnt/D

Since now, we’ll have access to those two partitions in /mnt folder. Notice that we have to create the /mnt/C and /mnt/D folders before mounting any resource under them.

Ok, but mounting partitions this way has at least two weaknesses: we have to do it manually, and only root user has access to the partitions. So, we can go step further and define those partitions in our magic /etc/fstab file, so that the system mounts them automatically, taking care of the permissions as well. The entries may look like this:

/dev/hda1       /mnt/hda1       ntfs    \ 
ro,uid=1000,gid=1000 0 2
/dev/hda6       /mnt/hda6       vfat    \ 
rw,codepage=852,uid=1000,gid=1000, iocharset=iso8859-2 0 2

Options rw and ro mean respectively read/write and read-only. Options uid and gid specify that only the user with uid=100 or a mamber of the specific grup (identified by the gid=1000) will have full access to the partition (those numbers can be found ou in the /etc/group file). For FAT32 partition we also specified a custom encoding since its file names consist of Eastern European characters (this is of course not mandatory).

How to mount a pendrive (USB stick)?

It’s quite easy, actually. In most distros this is done automatically thanks to HAL and udev. The USB icon should appear on the desktop and we could instantly copy files here and fotrh. If nothing happens however, you shouldn’t worry :)

USB sticks are usually visible as virtual devices under /dev/sda1 or /dev/sdb1 (historically SCSI devices). It is then enough to type in the terminal:

mount -t vfat /dev/sda1 /mnt/pendrive

and the pendrive will be mounted under /mnt/pendrive (if the folder exists). We can automate this process by adding the followinf line to our /etc/fstab::

/dev/sda1  /mnt/pendrive vfat uid=1000,gid=1000,exec,rw, \ 
codepage=852,iocharset=iso8859-2 0 0

Now, in order to mount the USB stick, it is enough to type mount /mnt/pendrive or click on the drive icon under our favorite file manager (i.e. nautilus or konqueror). Encoding specification is necessary if we have non-ASCII characters on our pendrive (i.e. for Eastern European languages). Here, we assumed that the file system type used on the pendrive is FAT32 (this is the default for most of the sticks). Of course we can use any supported filesystsem on the pendrives, including reiserfs or xfs.

More about the file system and mounting devices in GNU/Linux

Subscribe to RSS feed for this article! | Trackback URI


fold this thread Ty Miles  Friday, 20 April 2007 o godz. 6:38 pm #  Add karma Subtract karma  +0

MS has since changed their file system for Vista.

Now Users files are in C:\Users\Username (Like the Mac OS)

(Comments wont nest below this level)
fold this thread Berduchwal  Saturday, 21 April 2007 o godz. 12:46 am #  Add karma Subtract karma  +0

Witam w zdaniu poniżej zamiasz wschodnia eupropa jest wielkanocna europa.
“For FAT32 partition we also specified a custom encoding since its file names consist of Easter European”

(Comments wont nest below this level)
fold this thread t_ziel  Sunday, 22 April 2007 o godz. 3:26 pm #  Add karma Subtract karma  +0


(Comments wont nest below this level)
fold this thread Zach  Tuesday, 24 April 2007 o godz. 10:18 pm #  Add karma Subtract karma  +0

I just want to let you guys know that you make some great Linux articles. Keep up the great work :)

(Comments wont nest below this level)
fold this thread realk  Sunday, 20 May 2007 o godz. 2:49 am #  Add karma Subtract karma  +0

You have maybe the simple, so the best Linux tutorials on the Web; Just keep on this way.

(Comments wont nest below this level)
fold this thread Andy  Wednesday, 20 June 2007 o godz. 1:16 pm #  Add karma Subtract karma  +0

Zach + realk: how many automatically generated posts are still there?

(Comments wont nest below this level)
fold this thread Allen  Sunday, 22 July 2007 o godz. 6:05 am #  Add karma Subtract karma  +0

thank you for the great articles. In this information age can some one make a heap of Screen recording Video Tutorials and youtube them, please.

(Comments wont nest below this level)
fold this thread Kevin  Wednesday, 29 August 2007 o godz. 11:51 am #  Add karma Subtract karma  +0

Good tutorial. But you could also compare how to format disk under linux and windows.

(Comments wont nest below this level)
fold this thread misko  Monday, 26 November 2007 o godz. 4:36 pm #  Add karma Subtract karma  +0

from article:
# mount -t ntfs /dev/hda1 /mnt/C
# mount -t vfat /dev/hda1 /mnt/D

to my understanding second line should be
# mount -t vfat /dev/hda6 /mnt/D

Am I correct ???

(Comments wont nest below this level)
fold this thread Ron  Wednesday, 19 March 2008 o godz. 1:31 pm #  Add karma Subtract karma  +0

How would I mount a remote NTFS file system on a LINUX system?

(Comments wont nest below this level)
fold this thread Tech, How to, Software Reviews, Linux, Dog, Make Money Online with AhTim  Saturday, 10 May 2008 o godz. 5:09 pm #  Add karma Subtract karma  +0

Linux Basic Filesystem…

Recently my brother asked me about Ubuntu Linux installation step. He was stuck at filesystem selection part. I know as a Windows user, we might not understand well on linux filesystem. So, I have found a nice Linux Basic Filesystem diagram to share wi…

(Comments wont nest below this level)
fold this thread Olivia’s Private Page » Blog Archive » Using Cedega to play Windows games  Thursday, 15 May 2008 o godz. 6:34 pm #  Add karma Subtract karma  +0

[...] into your CDROM or mount the image of an installation CD. In case the CD/DVD ROM isn’t mounted, mount it in a way you usually do it. Then press the “Install” button. A new window should appear (like [...]

(Comments wont nest below this level)
fold this thread drzac  Saturday, 3 January 2009 o godz. 3:37 pm #  Add karma Subtract karma  +0

[...] According to the FHS standards, they should mounted under the /media folder. Np. /media/cdrom0, /media/fd0, etc [...]

Użyłeś polskiego np. (na przykład) zamiast eg.

Poza tym artykuł bardzo dobry :)

(Comments wont nest below this level)
fold this thread  Wednesday, 17 September 2014 o godz. 12:27 am #  Add karma Subtract karma  +0

It’s going to be end of mine day, however before end I am reading
this wonderful piece of writing to increase
my knowledge.

(Comments wont nest below this level)
Name (required)
E-mail (required - never shown publicly)

Adjust field size: shrink | enlarge)

You can use simple HTML in your comments. Some examples are as follows:
  • A hyperlink: <a href="">GNU/Linux for everyone!</a>,
  • Strong text: <strong>Strong text</strong>,
  • Italic text: <em>italic text</em>,
  • Strike: <strike>strike</strike>,
  • Code: <code>printf("hello world");</code>,
  • Block quote: <blockquote>Block quote</blockquote>