View
229
Download
4
Category
Tags:
Preview:
Citation preview
Week 5Linux Filesystem Administration
Objectives Identify the structure and types of device
files in the /dev directory Understand common filesystem types and
their features Mount and unmount filesystems to and
from the Linux directory tree Create and manage filesystems on floppy
disks, CDs, DVDs, USB storage devices, FireWire storage devices, and hard disk partitions
Create and use ISO images
Linux+ Guide to Linux Certification, 3e 2
Objectives (continued)
Use the LVM to create and manage logical volumes
Monitor free space on mounted filesystems
Check filesystems for errors Use hard disk quotas to limit user space
usage
Linux+ Guide to Linux Certification, 3e 3
The /dev Directory Device file: file representing a system
deviceTypically found in /dev directorySpecifies how to transfer data to and from the
device Character devices: transfer data to and
from system character by character Block devices: transfer chunks or blocks of
data using physical memory as a bufferFast data transferFloppy disks, CD-ROMs, DVDs, USB flash
drives, hard disk drives
Linux+ Guide to Linux Certification, 3e 4
The /dev Directory (continued)
Linux+ Guide to Linux Certification, 3e 5
Table 5-1: Common device files
http://linux.about.com/od/lsa_guide/a/gdelsa18.htm
The /dev Directory (continued) Major number: points to the device’s
driver in the Linux kernel Minor number: indicates the particular
device Device file type (block or character),
major number, and minor number make up the unique characteristics of a device file
Linux+ Guide to Linux Certification, 3e 6
The /dev Directory (continued) mknod command: can be used to re-
create a corrupted device fileMust know file type, major, and minor
numbers
/dev/MAKEDEV command: can be used to re-create a device file based on its common nameUseful if don’t know some of the information
required for the mknod command
Linux+ Guide to Linux Certification, 3e 7
Filesystems
Filesystem: organization and management imposed on physical storage media
Formatting: creating a filesystem on a device
Linux+ Guide to Linux Certification, 3e 8
Filesystem Types
Linux+ Guide to Linux Certification, 3e 9
Table 5-2: Common Linux filesystems
http://www.basicconfig.com/linux-basics/filesystem-types
Mounting Mounting: making a device accessible to
users via the logical directory tree Mount point: directory to which a device
is attachedThe mounted device temporarily covers up
the contents of the mount pointAny existing directory can be a mount point
In order to prevent making files inaccessible, create empty directories used specifically for mounting devices
Linux+ Guide to Linux Certification, 3e 10
Mounting (continued)
Linux+ Guide to Linux Certification, 3e 11
Figure 5-1: The directory structure prior to mounting
Mounting (continued)
Linux+ Guide to Linux Certification, 3e 12
Figure 5-2: The directory structure after mounting a floppy device
Mounting (continued) Root filesystem: when Linux filesystem
is first turned on, a filesystem on the hard drive is mounted to the / directoryContains most OS files
mount command: used to mount devices to mount point directoriesWhen used with no options or arguments,
lists currently mounted filesystems umount command: used to unmount
devices from mount point directories
Linux+ Guide to Linux Certification, 3e 13
Working with Floppy Disks Disk devices must be prepared before use
Formatted with a filesystem mkfs (make filesystem) command: Used
to format a disk device with a filesystem–t option: Specifies filesystem typeDefault is ext2 filesystem
To mount or unmount floppies, must ensure that no user is currently using the mount point directoryUse mount command with no options or arguments
to get list of currently mounted filesystemsOnce mounted, use as any other directory
Linux+ Guide to Linux Certification, 3e 14
Working with Floppy Disks (continued)
Linux+ Guide to Linux Certification, 3e 15
Table 5-3: Commands used to create filesystems
mkfs -t ext3 /dev/hda1 mke2fs mkfs.ext3 mkfs.msdos mkfs.vfat
Working with Floppy Disks (continued)
○ <device to mount> ○ <mount point> ○ <type>
○ <mount options>○ <dump#>○ <fsck#>
Linux+ Guide to Linux Certification, 3e 16
• fuser command: With the –u option, lists users using a directory
• /etc/fstab file: Used to mount devices at boot time– Also consulted when users do not specify enough
mount command arguments– Six fields:
Working with Floppy Disks (continued)
Linux+ Guide to Linux Certification, 3e 17
Table 5-4: Useful commands when mounting and unmounting filesystems
mountMount <filesystem> <target>
umountumount <target>
Working with CDs, DVDs, and ISO Images Most software is packaged on CDs and
DVDs Can be mounted using the mount
command and unmounted using umount commandDifferent device file - depend on the technology
used by the drive itself. For PATA drives, use one of the following:
Primary master (/dev/hda)Primary slave (/dev/hdb)Secondary master (/dev/hdc)Secondary slave (/dev/hdd)
Linux+ Guide to Linux Certification, 3e 18
Working with CDs, DVDs, and ISO Images (continued) For SATA or SCSI drives, Linux may use
many different names, depending on the actual CD or DVD drive
To make identification of CD/DVD drive easier, Fedora Linux includes symbolic links within the /dev directory:/dev/cdrom – symbolic link to first CD-ROM
drive/dev/cdrw – symbolic link to first CD-RW drive/dev/dvd – symbolic link to first DVD-ROM drive/dev/dvdrw – symbolic link to first DVD-RW drive
Linux+ Guide to Linux Certification, 3e 19
Working with CDs, DVDs, and ISO Images (continued) CDs and DVDs Typically use iso9660
filesystem type and are read only when accessed using LinuxMount with –r (read-only) option
Cannot be ejected until properly unmounted
In GUI environment, CD or DVD automatically mounted to a directory underneath the /media directoryNamed for the label on the CD or DVDSystem places shortcut on desktop
Linux+ Guide to Linux Certification, 3e 20
Working with CDs, DVDs, and ISO Images (continued)
Figure 5-3: Accessing a DVD within the GNOME desktop environment
Linux+ Guide to Linux Certification, 3e 21
Working with CDs, DVDs, and ISO Images (continued) iso9660 filesystem can be used to
create ISO images that contain other filesCan be mounted as a loopback device using
the mount command mkisofs command: Used to create ISO
image from directoryReceives at least two arguments:
○ Filename to be created ○ Directory used to create the ISO image
Linux+ Guide to Linux Certification, 3e 22
Working with Hard Disks
Three types of hard disks: PATA, SATA, and SCSI
PATA HDDs must be configured in one of the following:Primary master (/dev/hda)Primary slave (/dev/hdb)Secondary master (/dev/hdc)Secondary slave (/dev/hdd)
Different device file for each
Linux+ Guide to Linux Certification, 3e 23
Working with Hard Disks (continued) SATA and SCSI hard disks are well-
suited to Linux serversFaster access speedMultiple hard drives can be attached to a
controller Associated with different device files
First SCSI HDD (/dev/sda)Second SCSI HDD (/dev/sdb)Third SCSI HDD (/dev/sdc)And so on
Linux+ Guide to Linux Certification, 3e 24
Standard Hard Disk Partitioning Partition: physical division of an HDD; can
have its own filesystem Linux requires at least two partitions; root
and swap Good practice to use more than two
partitions Segregate different types of dataAllow for use of multiple filesystem types on one
HDDReduce chance that filesystem corruption will
render a system unusableSpeed up access to stored data
Linux+ Guide to Linux Certification, 3e 25
Standard Hard Disk Partitioning (continued) Track: area on a hard disk that forms a
concentric circle Sector: portion of a track containing
information Block: combination of sectors Cylinder: series consisting of the same
concentric track on all of the metal platters inside a HDD
Partition definitions stored in first readable sector of the hard diskMaster Boot Record (MBR) or master boot block
(MBB)
Linux+ Guide to Linux Certification, 3e 26
Standard Hard Disk Partitioning (continued)
Linux+ Guide to Linux Certification, 3e 27
Figure 5-4: The physical areas of a hard disk
Standard Hard Disk Partitioning (continued)
Linux+ Guide to Linux Certification, 3e 28
Table 5-5: Common hard disk partition device files for /dev/hda and /dev/sda
Standard Hard Disk Partitioning (continued)
Linux+ Guide to Linux Certification, 3e 29
Table 5-5 (continued): Common hard disk partition device files for /dev/hda and /dev/sda
Standard Hard Disk Partitioning (continued)
Linux+ Guide to Linux Certification, 3e 30
Figure 5-5: A sample Linux partitioning strategy
Standard Hard Disk Partitioning (continued)
Linux+ Guide to Linux Certification, 3e 31
Figure 5-6: A sample dual-boot Linux partitioning strategy
Working with Standard Hard Disk Partitions fdisk command: Create partitions after
installationSpecify hard disk partition as an argumentVariety of options for fdisk prompt to achieve
different tasks cfdisk command: Interactive graphical
utility for creating, manipulating and deleting partitions
Reboot computer after using the fdisk and cfdisk commands to ensure proper reloading into memory
Linux+ Guide to Linux Certification, 3e 32
Working with Standard Hard Disk Partitions (continued) Edit /etc/fstab file to allow system to mount
new filesystems automatically at boot time mkswap command: Prepare the swap
partition swapon command: Activate the swap
partition swapoff command: Deactivate the swap
partition Edit /etc/fstab file to ensure that new swap
partition is activated as virtual memory
Linux+ Guide to Linux Certification, 3e 33
Working with the LVM Logical Volume Manager (LVM): Used to
create volumesVolumes can contain filesystems and can be
mounted to directoriesMore flexible than standard partitions – allows
use of free space across multiple hard disksHas error correction abilities
LVM components: physical volumes (PVs), volume group (VG), and logical volumes (LVs)
Linux+ Guide to Linux Certification, 3e 34
Working with the LVM (continued)
Linux+ Guide to Linux Certification, 3e 35
Figure 5-8: A sample LVM configuration
Working with the LVM (continued) pvcreate command: used to create PVs pvdisplay command: used to display
detailed information about each PV vgcreate command: used to create a VG
that uses the space in PVsArguments are name of the VG and PVs to be
used Physical Extent: block size for saving data
in a VGShould be set when creating a VGCan use vgcreate -s to set the PE
Linux+ Guide to Linux Certification, 3e 36
Working with the LVM (continued) vgdisplay command: used to display
detailed information about each VG lvcreate command: used to create LVs
from available space in a VG lvdisplay command: used to display
information about each LV Work with mount points of LVs as would
work with any other had disk partition device fileEdit /etc/fstab to ensure that LVs are
automatically mounted at system startup
Linux+ Guide to Linux Certification, 3e 37
Working with the LVM (continued) pvscan, vgscan, and lvscan
commands: Display information about PVs, VGs, and LVs, respectively
vgextend command: used to add a new PV to an existing VG
lvextend command: used to increase the size of an LV, e.g., to use space extended onto an existing VG
Linux+ Guide to Linux Certification, 3e 38
Working with USB and FireWire-Based Storage Devices Most removable storage devices
emulate SCSI protocol in the firmware of the device
Devices are automatically mounted to a new directory under the /media directory named for the label on the device
Easy to work with removable storage devices using a GUI interfaceIf you want to use commands, must know
the device file and mount point directory
Linux+ Guide to Linux Certification, 3e 39
Monitoring Filesystems
Check mounted filesystems periodicallyErrorsDisk Space usageInode usage
Minimizes problems that due to damaged filesystems
Linux+ Guide to Linux Certification, 3e 40
Disk Usage Using more filesystems typically results in
less hard disk space per filesystemErrors when filesystems fill up with dataPeriodically remove obsolete files such as old
log files to make room for new ones
df (disk free space) command: Monitor free space used by mounted filesystems–h option: More user friendlyTo get information about different filesystems,
you must mount them prior to using df command
Linux+ Guide to Linux Certification, 3e 41
Disk Usage (continued)
du (directory usage) command: view size of a directory and contents in Kilobytes–s option: Summarizes output–h option: More user friendly
dumpe2fs command: view total number of inodes and free inodes for ext2, ext3, or ext4 filesystemUse –h option
Linux+ Guide to Linux Certification, 3e 42
Checking Filesystems for Errors Filesystem corruption: errors in
filesystem structure preventing retrieval of dataCommonly occurs due to improper system
shutdown Syncing: process of writing data stored
in RAM to the HDD Bad blocks: unusable areas of a disk
Cannot hold a magnetic charge
Linux+ Guide to Linux Certification, 3e 43
Checking Filesystems for Errors (continued) fsck (filesystem check) command: check
a filesystem for errorsFilesystem must be unmounted–f option used to perform full check
e2fsck command: Check ext2, ext3, and ext4 filesystems-c option checks for bad blocks
tune2fs command: Used to change filesystem parameters-i option sets interval to forcing full system
check
Linux+ Guide to Linux Certification, 3e 44
Checking Filesystems for Errors (continued)
Linux+ Guide to Linux Certification, 3e 45
Table 5-6: Common options to the fsck command
Hard Disk Quotas
If several users on a system, must be enough hard disk space for each user’s files
Hard disk quotas: user limits on filesystem usageRestrict number of files/directories or total
disk space usage
Soft limit: user may exceed quota briefly Hard limit: limit cannot be exceeded
Linux+ Guide to Linux Certification, 3e 46
Hard Disk Quotas (continued) quotaon and quotaoff commands:
toggle quotas on and off edquota command: edit user quotas repquota command: report user
quotas quota command: allows regular users
to view their own quotas and current usage
Linux+ Guide to Linux Certification, 3e 47
Summary Disk devices are represented by device
files that reside in the /dev directory Each disk drive must contain a filesystem,
which is then mounted to the Linux directory tree for usage using the mount command
Hard disks must be partitioned into distinct sections before filesystems are created on those partitions
Many different filesystems available to Linux
Linux+ Guide to Linux Certification, 3e 48
Summary (continued) The LVM can be used to create logical
volumes from the free space within multiple partitions
USB and FireWire storage devices are recognized as SCSI disks by the Linux system
Important to monitor disk usage using the df, du, and dumpe2fs commands to avoid running out of storage space
If hard disk space is limited, you can use hard disk quotas to limit the space that each user has on filesystems
Linux+ Guide to Linux Certification, 3e 49
Recommended