Skip to main content

Under Linux and UNIX each and every hardware device treated as a file. A device file allows to accesses hardware devices so that end users do not need to get technical details about hardware.

In short, a device file (also called as a special file) is an interface for a device driver that appears in a file system as if it were an ordinary file. This allows software to interact with the device driver using standard input/output system calls, which simplifies many tasks.

# -----------------------------------------------------------------------------
# All device files are stored in the /dev directory
# -----------------------------------------------------------------------------
# List device details
ls -l /dev
# c | character device: Talks to devices 1 byte/character at a time.
#     ex: Virtual terminals, terminals and serial modems etc
# b | block device: Talks to devices 1 block at a time. (1 block = 512 bytes to 32KB)
#     ex: Hard disk, DVD/CD ROM, and memory regions etc.

# -----------------------------------------------------------------------------
# mount
# -----------------------------------------------------------------------------

# use fdisk to get an idea of what kind of partitions you have available.
fdisk -l
# Device Boot      Start      End         Blocks      Id  System
# /dev/sda1   *          63   204796619   102398278+   7  HPFS/NTFS
# /dev/sda2       204797952   205821951      512000   83  Linux
# /dev/sda3       205821952   976773119   385475584   8e  Linux LVM
# That way you know that you have sda1/2/3 partitions. The -t option is the
# file system type. ex: NTFS, FAT, EXT. In the example above, sda1 is ntfs.
# USB devices are usually vfat and Linux are usually ext
# Mount the attached device named sda1 as an NTFS file system:
mount -t ntfs /dev/sda1 /new/subdir

# List all mounted file systems

# To remount a partition with specific options:
mount -o remount,rw /dev/hda2

# mount an ISO file (Linux):
mount -o loop ~/disks/dvd-image.iso /media/dvd

# mount all filesystems listed in fstab.
mount -a
# This command will mount all (not-yet-mounted) filesystems mentioned in fstab
# and is used in system script startup during booting. Note that this command
# will ignore all those entries containing "noauto" in the options section.

# unmount
umount /dev/hda2
# or
umount /new/subdir