473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,395 developers and data experts.

How to mount partitions under Linux / Unix

Nepomuk
3,112 Expert 2GB
In most modern distributions of Linux and Unix (at least ones with graphical environments like KDE, Gnome or XFCE), you get to mount your partitions easily from the desktop. In some cases however, it isn't that easy.

Note, that all of these commands have to be run in a terminal as root user. To open a terminal (sometimes called a console), either press ALT+F2 and type xterm (alternatives could be konsole or terminal) or press CRTL+ALT+F1 to change to a terminal.
However the latter will take you away from your graphical environment (or your desktop), so to get back to that, use CRTL+ALT+F7 or CRTL+ALT+F5, depending on your system.

To switch to root user once a terminal window is open, type
Expand|Select|Wrap|Line Numbers
  1. su
and enter the root password. To "log out" root after you've finished, enter
Expand|Select|Wrap|Line Numbers
  1. exit
Alternatively (if installed), you can use
Expand|Select|Wrap|Line Numbers
  1. sudo
before every command.

First of all, you can check what partitions your system recognises with
Expand|Select|Wrap|Line Numbers
  1. fdisk -l
(That is a small 'L', not the number '1'.)
The output will look something like this:
Expand|Select|Wrap|Line Numbers
  1. Disk /dev/hda: 40.0 GB, 40060403712 bytes
  2. 255 heads, 63 sectors/track, 4870 cylinders
  3. Units = cylinders of 16065 * 512 = 8225280 bytes
  4.  
  5. Device Boot      Start         End      Blocks   Id  System
  6. /dev/hda1               1          64      514048+  82  Linux swap / Solaris
  7. /dev/hda2   *          65        1402    10747485   83  W95 FAT32
  8. /dev/hda3            1403        3978    20691720   83  Linux
  9. /dev/hda4            3979        4870     7164990   83  Linux
or
Expand|Select|Wrap|Line Numbers
  1. Disk /dev/sda: 40.0 GB, 40060403712 bytes
  2. 255 heads, 63 sectors/track, 4870 cylinders
  3. Units = cylinders of 16065 * 512 = 8225280 bytes
  4.  
  5. Device Boot      Start         End      Blocks   Id  System
  6. /dev/sda1               1          64      514048+  82  Linux swap / Solaris
  7. /dev/sda2   *          65        1402    10747485   83  W95 FAT32
  8. /dev/sda3            1403        3978    20691720   83  Linux
  9. /dev/sda4            3979        4870     7164990   83  Linux
The devices called hdx (or sdx, x being something or the other; here found in line 1) in the directory /dev are your harddrives, the devices called hdx1, hdx2, etc (or sdx1, sdx2, etc) are your partitions.

As you can see, in my case the partition hda1 or sda1 is a SWAP-Partition, hda3 and hda4 (sda3 and sda4) are Linux partitions of some kind (like ext2, ext3, reiserfs or xfs) and hda2 (sda2) is FAT32 (a windows filesystem). If you have an NTFS drive, make sure the correct drivers are installed!

Next, check which partitions are already mounted with
Expand|Select|Wrap|Line Numbers
  1. mount
The output will look something like this:
Expand|Select|Wrap|Line Numbers
  1. /dev/hda4 on / type ext3 (rw,errors=remount-ro)
  2. proc on /proc type proc (rw,noexec,nosuid,nodev)
  3. /sys on /sys type sysfs (rw,noexec,nosuid,nodev)
  4. varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
  5. varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
  6. procbususb on /proc/bus/usb type usbfs (rw)
  7. udev on /dev type tmpfs (rw,mode=0755)
  8. devshm on /dev/shm type tmpfs (rw)
  9. devpts on /dev/pts type devpts (rw,gid=5,mode=620)
  10. lrm on /lib/modules/2.6.17-12-generic/volatile type tmpfs (rw)
  11. /dev/hda3 on /home type ext2 (rw)
In this case, hda4 and hda3 are mounted, but hda2 isn't.

Now, choose where the device is going to be mounted to. Normally, it's in a subdirectory of either /mnt or /media. Check, that the subdirectory exists (e.g. /mnt/c or /media/hdb2). If it doesn't, create it by using
Expand|Select|Wrap|Line Numbers
  1. cd /media
  2. mkdir hdb2
(or appropriate).

With the above information, you should be able to choose the right partition and use something like
Expand|Select|Wrap|Line Numbers
  1. mount /dev/hdb2 -t vfat /media/hdb2
if you're mounting hdb2 and it's a FAT16 or FAT32 partition.

The most commonly used partition formats are:
  • autofs (automatically try to determine format)
  • ext2
  • ext3
  • iso9660 (for CD-ROMs)
  • ntfs
  • reiserfs
  • smbfs (for SAMBA drives)
  • udf (for DVD-ROMs)
  • usbfs (for some USB devices)
  • vfat (for FAT16 and FAT32)
  • xfs
(More information about various file systems are to be found beneath the main article.)
Now, the drive will be accessible, however only root will have full access.

To make things easier, if you want to mount that drive more often, you can put it into /etc/fstab. Just open it in an editor (as root!) and add the following lines at the bottom:
Expand|Select|Wrap|Line Numbers
  1. # added manually
  2. /dev/hdb2 /media/hdb2 vfat defaults,users,noauto 0 0
(Of course, you'll have to change the device, type and mount directory to what you need.) This will allow anyone to mount that partition.
If you want the drive to be mounted automatically on startup, change noauto to auto.

Then save the file and in future you'll just have to do
Expand|Select|Wrap|Line Numbers
  1. mount /dev/hdb2
or
Expand|Select|Wrap|Line Numbers
  1. mount /media/hdb2
from any account to mount the drive.

More information about mounting can be found in the mount help
Expand|Select|Wrap|Line Numbers
  1. mount -h
or on the manpage of mount, which you can find by entering
Expand|Select|Wrap|Line Numbers
  1. man mount
or alternatively
Expand|Select|Wrap|Line Numbers
  1. info mount
into a terminal window.


Various File Systems
Here are some short descriptions of the most common file systems:
  • ext2 is a file system, which was very common on linux systems for a long time. Nowadays, it is mostly replaced by ext3.
    Use the format type ext2 to mount.
  • ext3 is a so called journaling file system. Other than that, there are very few differences to ext2.
    Use the format type ext3 to mount.
  • ext4 is a file system, which is currently under development. It is supposed to replace ext3. As it is unfinished, I'll not go into any detail.
    In future, you'll probably use the format type ext4 to mount.
  • XFS is one of the oldest journaling file systems available for UNIX and almost all Linux distributions, one of the few exceptions being Red Hat Enterprise Linux.
    Use the format type xfs to mount.
  • JFS is a 64-bit journaling filesystem created by IBM. There are two generations of JFS filesystem that are called JFS (JFS1) and JFS2, however under most operating systems, such as OS/2 and Linux, only the second generation exists and is called simply JFS.
    Use the format type jfs to mount.
  • ReiserFS (occasionally referred to as Reiser3) is a general-purpose, journaled computer file system and the first journaling file system to be included in the standard linux kernel.
    Use the format type reiserfs to mount.
  • FAT12 / FAT16 / FAT32 are relatively straightforward file systems and are supported by virtually all existing operating systems for personal computers. They are no journaling filesystems and therefore affected by fragmentation at a much higher rate than those.
    Use the format type vfat to mount.
  • NTFS is the standard file system of many newer Windows versions. It has several improvements over FAT, like the use of advanced data structures or it being a journaling filesystem. The support under Linux UNIX is good but not perfect, as the file system specification is a trade secret and the non-microsoft implementations are reverse engineered.
    Use the format type ntfs to mount. You have to have NTFS-3G installed!
All of these descriptions are based on the wikipedia articles.
Jul 10 '08 #1
1 27730
Niheel
2,460 Expert Mod 2GB
Hah, perfect timing.
Just about to setup a new backup system on a nix box.
Jul 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roumen Semov | last post by:
Hi, everyone! I was just wondering if any of you knows of a linux/unix client (preferably on the command line) that would connect to ms sql server? Any hints would be appreciated! Roumen.
5
by: Mr. S | last post by:
Hi! How can I retrive system infos under linux/unix? I want to know CPU frequency, CPU usage, RAM, RAM usage. THX Mr. S
3
by: WantedToBeDBA | last post by:
Hi friend, I want to do "DB2 UDB V8.1 for Linux, UNIX and Windows Advanced Database Administration(704)" certification. Can i write this exam directly or will have to write preceders such as 701...
16
by: kinane3 | last post by:
I'm been using dev environments like Dreamweaver with ASP for years and recently got a php job that requires SSH to access the server. Command line is really new to me and I need to learn this. ...
0
by: Rainer Lehrig | last post by:
Hello, we have build a library for our Open Source SCADA project http://pvbrowser.org The library supports Linux/Unix, Windows and OpenVMS. The doxygen documentation of the library can be...
3
by: m.smith_1999 | last post by:
Hello, I'm a student software developer. As a part of an excerise I'm doing I'm trying to build a program to create "mount files" and mount them. Something like Sarah Dean's OTFE but really...
3
by: sekhar.mekala | last post by:
Hello, I am a DB2 DBA on IBM Mainframe environment. I recently started learning DB2 on Unix/Windows environment. Can any one answer the following questions: 1. What is the qualifier that is...
1
AmberJain
by: AmberJain | last post by:
Is it possible to have multiple accounts in Linux/unix with privileges equal to 'root' account? If yes, how to do that (i.e. how to provide an account in linux with ROOT privileges)? THANKS in...
4
by: stuntgoat | last post by:
Hi, I want to start using Python 2.6 and 3000. I have several questions. What, in your experiences, is a functionally elegant solution to installing 2.6 and 3 from source without breaking...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.