Man of Honour
- Joined
- 18 Oct 2002
- Posts
- 7,097
Mounting Drives in Linux
This is a basic guide briefly comparing and contrasting the linux file structure to the windows file structure and how to mount additional disks in linux.
The Linux File Structure
The linux file structure is very different to that of windows. The windows file structure can be described as 'many trees' where you'll have a 'tree' for each drive. In linux it's one big tree, where drives are nested within the tree. Example:
As you can see in the linux file structure the cdrom is 'nested' onto the directory 'cdrom'. This known as 'mounting' and the directory /mnt/cdrom is known as the 'mountpoint'. Again unlike windows, peripheral devices are also held within the linux 'tree' under the directory /dev.
The Mount Command
In order to mount a drive you must use the mount command:
Where:
$filesystem = filesystem type i.e ext2, reiser, vfat, ntfs etc.
$device = the device name under /dev i.e /dev/cdrom /dev/sda
$mountpoint = the directory where the device will be nested to i.e /mnt/cdrom
Learn by Example
If the peripheral device 'cdrom' was /dev/cdrom, was formatted in the ext2 filesystem and you wanted it to be accessed from the deirectory /mnt/cdrom you would mount it by
If you have a second hard drive whose device name was /dev/sda, was formatted in fat32 and wanted it to be accessed from the directory /mnt/external_drive you'll type
The red 1 in /dev/sda1 refers to the partition number on the hard drive. If the drive has 3 primary partitions and you wanted to mount the second partition you'd use /dev/sda2. As you may have noticed the mountpoint can be anywhere in the file structure and be called anything you like as long as the directory exists.
Mounting in a Hurry
Typing the whole of the mounting syntax isn't always necessary as linux can often automatically detect files system this is especially the case with linux filesystem types, so it may be possible to just type
If the volume is often required, even this slightly shorter command might be too long. This is where the filesystem table (fstab) comes into the picture.
The /etc/fstab
The filesystem table file is found in /etc and holds a table of your partitions and it's filesystems. Heres what it looks like:
As you can see you have the device name on the left followed by the mount point, filesystem type and then two columns of options. If I regularly accessed the drive /dev/sda1 (as in the above example) I can add it to the table, with the relevent infomation into the relevent columns.
The advantage of adding the drives into fstab is that you can mount the volume simply by typing
for example
will mount /dev/sda1 since linux is able to tell which device is 'linked' to that mountpoint from the fstab. Adding drives to the table also allows you to automatically mount the volumes during bootup as well as add desktop for mounting / unmounting the drive on your windows manager.
This is a basic guide briefly comparing and contrasting the linux file structure to the windows file structure and how to mount additional disks in linux.
The Linux File Structure
The linux file structure is very different to that of windows. The windows file structure can be described as 'many trees' where you'll have a 'tree' for each drive. In linux it's one big tree, where drives are nested within the tree. Example:
As you can see in the linux file structure the cdrom is 'nested' onto the directory 'cdrom'. This known as 'mounting' and the directory /mnt/cdrom is known as the 'mountpoint'. Again unlike windows, peripheral devices are also held within the linux 'tree' under the directory /dev.
The Mount Command
In order to mount a drive you must use the mount command:
Code:
mount -t $filesystem $device $mountpoint
$filesystem = filesystem type i.e ext2, reiser, vfat, ntfs etc.
$device = the device name under /dev i.e /dev/cdrom /dev/sda
$mountpoint = the directory where the device will be nested to i.e /mnt/cdrom
Learn by Example
If the peripheral device 'cdrom' was /dev/cdrom, was formatted in the ext2 filesystem and you wanted it to be accessed from the deirectory /mnt/cdrom you would mount it by
Code:
mount -t ext2 /dev/cdrom /mnt/cdrom
Code:
mount -t vfat /dev/sda[color=yellow]1[/color] /mnt/external_drive
Mounting in a Hurry
Typing the whole of the mounting syntax isn't always necessary as linux can often automatically detect files system this is especially the case with linux filesystem types, so it may be possible to just type
Code:
mount /dev/cdrom /mnt/cdrom
The /etc/fstab
The filesystem table file is found in /etc and holds a table of your partitions and it's filesystems. Heres what it looks like:
Code:
# <fs> <mountpoint> <type> <opts> <dump/pass>
# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
/dev/hda1 /boot ext2 noauto,noatime 1 1
/dev/hda3 / reiserfs noatime,notail 0 0
/dev/hda2 none swap sw 0 0
/dev/hda4 /net reiserfs noatime,notail 0 0
/dev/hdc1 /net/ftp reiserfs noatime,notail 0 0
/dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0
proc /proc proc defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
Code:
# <fs> <mountpoint> <type> <opts> <dump/pass>
# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
/dev/hda1 /boot ext2 noauto,noatime 1 1
/dev/hda3 / reiserfs noatime,notail 0 0
/dev/hda2 none swap sw 0 0
/dev/hda4 /net reiserfs noatime,notail 0 0
/dev/hdc1 /net/ftp reiserfs noatime,notail 0 0
[color=yellow]/dev/sda1 /mnt/external_drive vfat user,umask=0 0 0[/color]
/dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0
proc /proc proc defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
Code:
mount $mountpoint
Code:
mount /mnt/external_drive
Last edited: