Filesystems and Swapping
Devices
Devices in Linux are represented as special files. These files are
either character special files or block special files.
Character special files are used for devices that can work with one byte
at a time. Examples include
-
/dev/ttyS* -- the serial ports (waiting for a connection)
-
/dev/cua* -- the serial ports (dialing out)
-
/dev/console -- the keyboard/monitor
-
/dev/tty -- Your current input and output
-
/dev/audio -- the soundcard
-
/dev/ps2 -- a ps2 mouse
-
/dev/atimouse -- an ati mouse
-
/dev/mouse -- normally a link to whatever mouse is active
There are also lots of block special files. Examples include
-
/dev/hda -- The first ide hard drive
-
/dev/sda -- The first scsi hard drive
-
/dev/fd0H1440 -- the a: floppy disk
-
/dev/fd0H720 -- the a: floppy disk, formatted to 720K
-
/dev/rst0 -- the first scsi tape drive
-
/dev/cdrom -- the cdrom device
You may create a filesystem on almost any block special file. Making
a filesystem on a tape drive or a writeable cdrom is a known-bad-idea.
What matters for devices are the major number, which describes
the type of device, and minor number, which describes the instance
of the device. Devices also have a standard name, which is
the name they are most often called. For example, the first ide drive
is normally /dev/hda, major =3, minor =0. The second ide drive is
normally /dev/hdb, major=3, minor=64.
To make a device file, use the mknod command. For example, mknod
/dev/mydisk b 3 64 would make a file called /dev/mydisk which would
access the second ide harddrive.
To make many device files, use the MAKEDEV command.
To find out the major and minor numbers for a device, look in the kernel
source or (much better) the MAKEDEV command, which can be found in
/dev of all places.
Stupidly, there are no device files for network cards.
There are also lots of psuedo-device files. Examples include
-
/dev/random -- a bunch of random numbers
-
/dev/zero -- an infinite supply of zeros
-
/dev/null -- the great bit bucket
-
/dev/ram[0-9] -- ram used as a ramdisk
-
/dev/ram -- the physical ram in the system
Hard Drives
Hard drive get a device file for entire hard drive. You also get
a device file for every partition on the drive.
/dev/hda is the entire first hard drive
/dev/hda3 is the third partition of the first hard drive
Filesystems
Filesystems are stored on either partitions or disks.
-
If the filesystem is to be on a hard drive
-
If the hard drive is bootable
-
then the hard drive needs a partition table
-
then the filesystem must be on a partition
-
If the hard drive is not bootable
-
You may place the filesystem on a partition (the partition table costs
a few K)
-
You may place the filesystem on the draw device (other operating systems
will think the disk unpartitioned)
-
If the filesystem is to be on a floppy disk
-
No partition table ... use the raw device
-
If the filesystem is to be on a ramdisk
-
No partition table .. use the raw device
Filesystem Types
There are many different kinds of filesystem
-
EXT2 is the standard Linux filesystem
-
RiserFS is a new filesystem that requires a kernel patch. It has
journalling, which means it is must more restant to suddenly loosing power.
-
ISO9660 is the filesystem normally found on CD-ROMS
-
Win95 is a the filesystem found on Windows Machines. It's not as
fast as EXT2, and has limitations on the names that files can have.
There are no hard links.
-
To use a filesystem you must have support for that filesystem compiled
into the kernel.
Making a Filesystem
The basic command is
mkfs -t type place.
For example,
mkfs -t ext2 /dev/ram0
For ext2 filesystem, you can also type mke2fs /dev/ram0.
To see the *many* options, read man mke2fs.
Mounting a Filesystem
You cannot access the contents of a filesystem until it is mounted.
The place where it is mounted is called mount point.
To temporaritly mount a filesystem, type
mount /dev/ram0 /mount-point
To set things up so that the filesystem is permenantly mounted, edit
the file /etc/fstab.
Unmounting a Filesystem
To remove a filesystem temporarily, type
umount /mount-point
This will fail if any process is using the filesystem, or even has
it as