Mounting Devices


/etc/fstab: Automating the mount process

The file /etc/fstab (it stands for "file system table") contains descriptions of filesystems that you mount often. These filesystems can then be mounted with a shorter command, such as mount /cdrom. You can also configure filesystems to mount automatically when the system boots. You'll probably want to mount all of your hard disk filesystems when you boot.

Look at this file now, by typing more /etc/fstab. It will have two or more entries that were configured automatically when you installed the system. It probably looks something like this:

     # /etc/fstab: static file system information.
#
#
/dev/hda1 / ext2 defaults 0 1
/dev/hda3 none swap sw 0 0
proc /proc proc defaults 0 0

/dev/hda5 /tmp ext2 defaults 0 2
/dev/hda6 /home ext2 defaults 0 2
/dev/hda7 /usr ext2 defaults 0 2

/dev/hdc /cdrom iso9660 ro 0 0
/dev/fd0 /floppy auto noauto,sync 0 0


The first column lists the device the filesystem resides on. The second lists the mount point, the third the filesystem type. The line beginning proc is a special filesystem explained in The proc filesystem, Section 4.8.3. Notice that the swap partition (/dev/hda3 in the example) has no mount point, so the mount point column contains none.

The last three columns may require some explanation.

The fifth column is used by the dump utility to decide when to back up the filesystem. FIXME: cross ref to dump

The sixth column is used by fsck to decide in what order to check filesystems when you boot the system. The root filesystem should have a 1 in this field, filesystems which don't need to be checked (such as the swap partition) should have a 0, and all other filesystems should have a 2. FIXME: cross ref to fsck, also, is the swap partition really a filesystem?

Column four contains one or more options to use when mounting the filesystem. Here's a brief summary (some of these probably won't make much sense yet - they're here for future reference):

async and sync
Do I/O synchronously or asynchronously. Synchronous I/O writes changes to files immediately, while asynchronous I/O may keep data in buffers and write it later, for efficiency reasons. FIXME: cross ref to section on sync for full explanation. Also, should recommend when to choose one or the other.
ro and rw
Mount the filesystem read-only or read-write. If you don't need to make any changes to the filesystem, it's a good idea to mount it read-only so you don't accidentally mess something up. Also, read-only devices (such as CD-ROM drives and floppy disks with write protection tabs) should be mounted read-only.
auto and noauto
When the system boots, or whenever you type mount -a, mount tries to mount all the filesystems listed in /etc/fstab. If you don't want it to automatically mount a filesystem, you should use the noauto option. It's probably a good idea to use noauto with removable media such as floppy disks, because there may or may not be a disk in the drive. You'll want to mount these filesystems manually after you put in a disk.
dev and nodev
Use or ignore device files on this filesystem. You might use nodev if you mount the root directory of another system on your system - you don't want your system to try to use the devices on the other system.
user and nouser
Permit or forbid ordinary users to mount the filesystem. nouser means that only root can mount the filesystem. This is the normal arrangement. You might use the user option to access the floppy drive without having to be root.
exec and noexec
Allow or do not allow the execution of files on this filesystem. Probably you won't need these options.
suid and nosuid
Allow or do not allow the suid bit to take effect. Probably you won't need these options. See Making files suid/sgid, Section 4.8.4.2.
defaults
Equivalent to: rw, dev, suid, exec, auto, nouser, async. You can specify defaults followed by other options to override specific aspects of defaults.
fstab Syntax
Quote:
[Device] [Mount Point] [File_system] [Options] [dump] [fsck order]
Device = Physical location.
/dev/hdxy or /dev/sdxy.
x will be a letter starting with a, then b,c,....
y will be a number starting with 1, then 2,3,....
Thus hda1 = First partition on the master HD.
See Basic partitioning for more information
Note: zip discs are always numbered "4".
Example: USB Zip = /dev/sda4.

Note: You can also identify a device by udev, volume label (AKA LABEL), or uuid.

These fstab techniques are helpful for removable media because the device (/dev/sdxy) may change. For example, sometimes the USB device will be assigned /dev/sda1, other times /dev/sdb1. This depends on what order you connect USB devices, and where (which USB slot) you use to connect. This can be a major aggravation as you must identify the device before you can mount it. fstab does not work well if the device name keeps changing.

To list your devices, first put connect your USB device (it does not need to be mounted).
By volume label:
Code:
ls /dev/disk/by-label -lah
By id:
Code:
ls /dev/disk/by-id -lah
By uuid:
Code:
ls /dev/disk/by-uuid -lah
IMO, LABEL is easiest to use as you can set a label and it is human readable.

The format to use instead of the device name in the fstab file is:
LABEL=
  1. /mnt Typically used for fixed hard drives HD/SCSI.
  2. /media Typically used for removable media (CD/DVD/USB/Zip).
Examples:
  1. /mnt/windows
  2. /mnt/data
  3. /media/usb
To make a mount point:
Code:
sudo mkdir /media/usb
File types:
Linux file systems: ext2, ext3, jfs, reiserfs, reiser4, xfs, swap.

Windows:
vfat = FAT 32, FAT 16
ntfs= NTFS

Note: For NTFS rw ntfs-3g

CD/DVD/iso: iso9660
To mount an iso image (*.iso NOT CD/DVD device):
Code:
sudo mount -t iso9660 -o ro,loop=/dev/loop0
Network file systems:
nfs Example:
Quote:
server:/shared_directory /mnt/nfs nfs 0 0

Make a directory for each device to mount it

makedir /floppy
makedir /cdrom
makedir /usb

Mounting a filesystem

Before mounting a filesystem, or to actually create a filesystem on a disk that doesn't have one yet, it's necessary to refer to the devices themselves. All devices have names, and these are located in the /dev directory. If you type ls /dev now, you'll see a pretty lengthy list of every possible device you could have on your Debian system.

Possible devices include:

  • /dev/hda is IDE drive A, usually called C:\ on a DOS or Windows system. In general, this will be a hard drive. IDE refers to the type of drive - if you don't know what it means, you probably have this kind of drive, because it's the most common.
  • /dev/hdb is IDE drive B, as you might guess. This could be a second hard drive, or perhaps a CD-ROM drive. Drives A and B are the first and second (master and slave) drives on the primary IDE controller. Drives C and D are the first and second drives on the secondary controller.
  • /dev/hda1 is the first partition of IDE drive A. Notice that different drives are lettered, while specific partitions of those drives are numbered as well.
  • /dev/sda is SCSI disk A. SCSI is like IDE, only if you don't know what it is you probably don't have one. They're not very common in home Intel PC's, though they're often used in servers and Macintoshes often have SCSI disks.
  • /dev/fd0 is the first floppy drive, generally A:\ under DOS. Since floppy disks don't have partitions, they only have numbers, rather than the letter-number scheme used for hard drives. However, for floppy drives the numbers refer to the drive, and for hard drives the numbers refer to the partitions.
  • /dev/ttyS0 is one of your serial ports. /dev contains the names of many devices, not just disk drives.

To mount a filesystem, tell Linux to associate whatever filesystem it finds on a particular device with a particular mount point.

  1. su

    If you haven't already, you need to either log in as root or gain root privileges with the su (super user) command. If you use su, enter the root password when prompted.

  1. ls /cdrom

    See what's in the /cdrom directory before you start. If you don't have a /cdrom directory, you may have to make one using mkdir /cdrom.

  1. mount

    Typing simply mount with no arguments lists the currently mounted filesystems.

  1. mount -t iso9660 CD device /cdrom

    For this command, you should substitute the name of your CD-ROM device for CD device in the above command line. If you aren't sure, /dev/hdc is a good guess. If that fails, try the different IDE devices: /dev/hda, etc. You should see a message like:

         mount: block device /dev/hdc is write-protected, mounting read-only

    The -t option specifies the type of the filesystem, in this case iso9660. Most CDs are iso9660. The next argument is the name of the device to mount, and the final argument is the mount point. There are many other arguments to mount; see the man page for details. (For example, you could avoid the above message by specifying read-only on the command line.)

    Once a CD is mounted, you may find that your drive tray will not open. You must unmount the CD before removing it.

  1. ls /cdrom

    Confirm that /cdrom now contains whatever is on the CD in your drive.

  1. mount

    Look at the list of filesystems again, noticing that your CD drive is now mounted.

  1. umount /cdrom

    This unmounts the CD. It's now safe to remove the CD from the drive. Notice that the command is umount with no "n", even though it's used to unmount the filesystem.


Rights and installing

Apt-Get

The apt-get command is a powerful command-line tool used to work with Ubuntu's Advanced Packaging Tool (APT) performing such functions as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire Ubuntu system.

Being a simple command-line tool, apt-get has numerous advantages over other package management tools available in Ubuntu for server administrators. Some of these advantages include ease of use over simple terminal connections (SSH) and the ability to be used in system administration scripts, which can in turn be automated by the cron scheduling utility.

Some examples of popular uses for the apt-get utility:

  • Install a Package: Installation of packages using the apt-get tool is quite simple. For example, to install the network scanner nmap, type the following:

    sudo apt-get install nmap 
  • Remove a Package: Removal of a package or packages is also a straightforward and simple process. To remove the nmap package installed in the previous example, type the following:

    sudo apt-get remove nmap 

Ubuntu command line package install

Installing downloaded packages

Sometimes you might want to install a package which you have downloaded from a website, rather than from a software repository. These packages are called .deb files. Because they may have been created for a different Linux distribution, they may have unmet dependencies on Ubuntu and so may not be installable.

Using GDebi to install packages

GDebi is a graphical application used to install packages. It automatically checks packages for their dependencies and will try to download them from the Ubuntu software repositories if possible. You may first need to install GDebi - simply install the gdebi package using one of the package managers listed above, or open a Terminal and type sudo apt-get install gdebi.

Once you have installed GDebi, use the File Browser to find the package you wish to install. Package files will look similar to this:

deb_package.png

Double-click the package to open it with GDebi. If all dependencies have been met for the selected package, simply click the 'Install package' button to install it. GDebi will warn you if there are unmet dependencies.

Using the Kubuntu Package Management Utility

To install a .deb file in Kubuntu, right-click on the .deb file, and choose Kubuntu Package Menu->Install Package.

Using dpkg to install packages

dpkg is a command-line tool used to install packages. To install a package with dpkg, open a Terminal and type the following:

cd directory
sudo dpkg -i package_name.deb

Note: replace directory with the directory in which the package is stored and package_name with the filename of the package.

It is recommended that you read the dpkg manual page before using dpkg, as improper use may break the package management database. To view the manual page for dpkg, open a Terminal and type man dpkg.

Can't login after installing Gnome, KDE

  • NEVER use sudo to start graphical programs. You should always use gksudo or kdesu to run such programs, otherwise new login attempts may fail. If this happens and at login an error message reports: "Unable to read ICE authority file", log in using the failsafe terminal and execute the command below substituting user for your username.

rm /home/user/.{ICE,X}authority
  • To start a root shell (i.e. a command window where you can run root commands) use:

sudo -i
  • To login as another user (on the command line, use something like gdmflexiserver for a graphical login)

sudo -i -u username