Now that the file system has been created, you can mount the partition. Initially, it will be empty, since the system hasn't had access to the file system to add files to it. The command to mount file systems is mount, and its syntax is as follows:
mount [options] <-t type> [-o mount options] <device> <mounting point>
In this case we want to temporarily
mount our partition on /mnt/new
(or any other mount point
you have chosen: remember that the mount point must exist). The command
for mounting our newly created partition is:
$ mount -t ext3 /dev/hdb1 /mnt/new
The -t
option is used to specify what type of file system the partition is
supposed to host. The file systems you will most frequently encounter are
ext2FS (the GNU/Linux file system) or ext3FS (an improved
version of ext2FS with journaling capabilities), VFAT (for
almost all DOS/Windows® partitions: FAT 12, 16 or 32),
NTFS (for newer versions of Windows®) and
ISO9660 (CD-ROM file system). If you don't specify any type,
mount will try guessing which file system is hosted by the
partition by reading the superblock.
The -o
option is used to specify one or more mounting options. The
options appropriate for a particular file system will depend on
the file system being used. Refer to the
mount(8) man
page for more details.
Now that you've mounted your new
partition, it's time to copy the entire /usr
directory onto it:
$ (cd /usr && tar cf - .) | (cd /mnt/new && tar xpvf -)
Now that the files are copied, we can unmount our partition. To do this, use the umount command. The syntax is simple:
umount <mount point|device>
So to unmount our new partition we can type:
$ umount /mnt/new
$ umount /dev/hdb1
Since this partition is going to
“become” our /usr
directory, we need to
tell the system. To do this, we edit the
/etc/fstab
file. It makes it possible to automate the
mounting of certain file systems, especially at system start-up. It
contains a series of lines describing the file systems, their mount points
and other options. Here's an example of such a file:
/dev/hda2 / ext3 defaults 1 1 /dev/hdd /mnt/cdrom auto umask=0022,user,iocharset=utf8,noauto,ro,exec,users 0 0 /dev/fd0 /mnt/floppy supermount dev=/dev/fd0,fs=ext2:vfat,--,umask=0022,iocharset=utf8,sync 0 0 /dev/hda1 /mnt/windows ntfs umask=0,nls=utf8,ro 0 0 none /proc proc defaults 0 0 /dev/hda3 swap swap defaults 0 0
the dump utility backup flag;
There is always
an entry for the root file system. The Swap
partitions are
special since they're not visible in the tree structure, and the mount
point field for those partitions contains the swap
keyword. As for the /proc
file system, it will be
described in more detail in Chapter 5, The /proc File System. Another special
file system is /dev/pts
.
Also note that your system
might have entries added and removed automatically from this file.
This is done by fstab-sync, a command which
receives special events from the Hardware Abstraction Layer
(HAL) system, and manipulates the
/etc/fstab
file. Take a look at the
fstab-sync(8) man page for more details.
Coming back to
our file-system change, at this point we have moved the
entire /usr
hierarchy to
/dev/hdb1
and we want this partition to be mounted as
/usr
at boot time. To accomplish this, add the
following entry anywhere in the /etc/fstab
file:
/dev/hdb1 /usr ext3 defaults 1 2
Now the partition will be mounted every time your system boots, and will be checked for errors if necessary.
There are two
special options: noauto
and
users
. The noauto
option
specifies that the file system should not be mounted at start-up,
and is mounted only when you tell it to. The
users
option specifies that any user can mount
and unmount the file system. These two options are typically used
for the CD-ROM and floppy drives. There are other options, and
/etc/fstab
has a man
page
(fstab(5)) you
can read for more information.
One advantage of using
/etc/fstab
is that it simplifies the
mount command syntax. To mount a file system described
in the file, you can either reference the mount point or the device. To
mount a floppy disk, you can type:
$ mount /mnt/floppy
$ mount /dev/fd0
To finish our
partition moving example, let's review what we have already
done. We copied the /usr
hierarchy and
modified /etc/fstab
so that the new partition
will be mounted at start-up. But for the moment, the old
/usr
files are still in their original place
on the drive, so we need to delete them to free up space (which
was, after all, our initial goal).
To do so, you first need to switch to single user mode by issuing the telinit 1 command on the command line. It will stop all services and prevent users from connecting to the machine.
Next, we delete all files in the
/usr
directory. Remember that we are still
referring to the “old” directory, since the newer, larger
one, is not yet mounted. rm -Rf /usr/*.
And that's
it. Now, go back to multi-user mode (telinit 3
for standard text mode or telinit 5 for the
graphical mode), and if there's no further administrative work
left, you should now log off from the root
account.