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.
|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
Binaries: /bin, /sbin
|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
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
, it mounts this resource. Similarily,
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
/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
- Linux Filesystem Hierarchy — article from www.tldp.org
- Linux Directory Structure — a quick introduction
- Mount your Widows partitions and make it read/writable in Ubuntu — including NTFS write support (a guide from debianadmin.com)
- The Linux filesystem explained from freeos.com
- The Linux filesystem hierarchy: a short description from linuxnovice.org
Warning: include(0php’): failed to open stream: No such file or directory in /sites/polishlinux.org/wp-content/themes/jakilinuxorg/page.php on line 70
Warning: include(): Failed opening '0php’' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /sites/polishlinux.org/wp-content/themes/jakilinuxorg/page.php on line 70