CHAPTER 3:
DISK MANAGEMENT
Outline
3.1Revision of device management
3.2 Disk as a Drive
3.3 Disk Geometry
3.4 Disk Interfaces and Controllers
3.5 Partitions
3.6 Volumes
3.7 Filesystems
3.8 Files
2
3.1 Hardware revision
Device management: the OS component
that manages hardware devices
Provides a uniform interface to access devices
with different physical characteristics
Optimize the performance of individual devices
3
3.1 I/O hardware
I/O device hardware
Many varieties
Device controller
Conversion a block of bytes and I/O operations
Performs error correction if necessary
Expose hardware registers to control the device
Typically have four registers:
Data-in register to be read to get input
Data-out register to be written to send output
Status register (allows the status of the device to be checked)
Control register (controls the command the device performs)
4
3.1 Device Addressing
How the CPU addresses the device registers?
Two approaches
Dedicated range of device addresses in the physical
memory
Requires special hardware instructions associated with
individual devices
Memory-mapped I/O: makes no distinction between
device addresses and memory addresses
Devices can be accessed the same way as normal memory,
with the same set of hardware instructions
5
3.1 Ways to Access a Device
How to input and output data to and from
an I/O device?
Polling: a CPU repeatedly checks the
status of a device for exchanging data
+ Simple
- Busy-waiting
6
3.1 Ways to Access a Device
Interrupt-driven I/Os: A device controller
notifies the corresponding device driver
when the device is available
+ More efficient use of CPU cycles
- Data copying and movements
- Slow for character devices (i.e., one interrupt
per keyboard input)
7
3.1 Ways to Access a Device
Direct memory access (DMA): uses an
additional controller to perform data
movements
+ CPU is not involved in copying data
- I/O device is much more complicated (need to
have the ability to access memory).
- A process cannot access in-transit data
8
3.1 Ways to Access a Device
Double buffering: uses two buffers.
While one is being used, the other is being
filled.
Analogy: pipelining
Extensively used for graphics and animation
So a viewer does not see the line-by-line scanning
9
3.1 Device Driver
An OS component that is responsible for
hiding the complexity of an I/O device
So that the OS can access various
devices in a uniform manner
10
3.1 Types of IO devices
Two categories
A block device stores information in fixed-size blocks, each one with its own address
e.g., disks
A character device delivers or accepts a stream of characters, and individual characters are
not addressable
e.g., keyboards, printers, network cards
Device driver provides interface for these two types of devices
Other OS components see block devices and character devices, but not the details of the
devices.
How to effectively utilize the device is the responsibility of the device driver
11
3.1 Device Driver Illustrated
User applications
User level Various OS components
OS level Device drivers
Hardware level Device controllers
I/O devices
12
Disk as An Example Device
30-year-old storage technology
Incredibly complicated
A modern drive
250,000 lines of micro code
13
3.2 DISK GEOMETRY
Disk platters: coated with magnetic
materials for recording
Disk
platters
14
3.2 Disk Characteristics
Disk arm: moves a comb of disk heads
Only one disk head is active for reading/writing
Disk heads
Disk
platters
Disk arm
15
3.2 Hard Disk Trivia…
Aerodynamically designed to fly
As close to the surface as possible
No room for air molecules
Therefore, hard drives are filled with
special inert gas
If head touches the surface
Head crash
Scrapes off magnetic information
16
3.2 Disk Characteristics
Each disk platter is divided into concentric
tracks
Disk heads
Disk
platters
Disk arm
Track
17
3.2 Disk Characteristics
A track is further divided into sectors. A
sector is the smallest unit of disk storage
Disk heads
Disk
platters
Sector
Disk arm
Track
18
3.2 Disk Characteristics
A cylinder consists of all tracks with a
given disk arm position
Disk heads
Disk
platters
Sector
Disk arm
Cylinder
Track
19
3.2 Disk Characteristics
Cylinders are further divided into zones
Disk heads
Disk
platters
Sector
Disk arm
Cylinder
Track
Zones 20
3.2 Disk Characteristics
Zone-bit recording: zones near the edge
of a disk store more information (higher
bandwidth)
Disk heads
Disk
platters
Sector
Disk arm
Cylinder
Track
Zones 21
More About Hard Drives Than You Ever
Want to Know
Track skew: starting position of each track is
slightly skewed
Minimize rotational delay when sequentially transferring
bytes across tracks
Thermo-calibrations: periodically performed to
account for changes of disk radius due to
temperature changes
Typically 100 to 1,000 bits are inserted between
sectors to account for minor inaccuracies
22
Disk Performance Metrics
Latency
Seek time + rotational delay
Bandwidth
Bytes transferred / disk access time
23
3.3 Disk Controllers and Interfaces
Few popular standards
IDE (integrated device electronics)
ATA (AT attachment interface)
SCSI (small computer systems interface)
Fibre Channel
Differences
Performance
Parallelism
24
Disk Device Driver
Major goal: reduce seek time for disk
accesses
Schedule disk request to minimize disk arm
movements
25
3.3.1 SCSCI
Many versions
SCSI-1 (1986) 8-bits, 5MB/s
SCSI-2 (1990) added command
queuing, DMA, more
Fast SCSI-2 8-bits, 10MB/s
Fast/wide SCSI-2 16-bits, 20MB/s
Ultra SCSI 8 bits, 20MB/s
Wide Ultra SCSI 16bits,40MB/s
Wide Ultra2 SCSI 16bits, 80MB/s
Wide Ultra3 SCSI 16bits, 160MB/s
Ultra-320, Ultra-640 SCSI
26
3.3.2 IDE a.k.a ATA
Integrated Drive Electronics / AT Attachment
Very short cable lengths (18in!)
ATA-2 added DMA and LBA
(get beyond BIOS 504MB limit)
ATA-3 added power management, self-
monitoring (16MB/s)
Ultra-ATA added Ultra DMA/33, /66, and /133
modes (33- 133MB/s)
Hard disks with this interface were last produced
in 2013
ATAPI interface allows non-ATA devices to
connect like CD-ROMS 27
3.3.2 SATA
Now standard equipment
Fast: 150-600MB/s (16GBit/s now
available)
Software compatible with parallel ATA
One drive per controller
Thin cables
28
3.3.3 SCSCI vs SATA
SCSI traditionally beats SATA technically, but
may not be worth the price premium
In single-user systems, SATA will provide 85%, cheaply
For best possible performance, SCSI is often
better
e.g., in servers and multi-user systems
handles multiple simultaneous reqs + more devices
better
higher-end equipment (faster, better warranty, etc.)
SATA technology is quite good
Usually better price/performance than SCSI
Still subject to much debate
29
3.3.4 Controller cards
A controller card is a device that sits between a host
system and the storage network and allows the two to
communicate with each other. Host adapters can be
integrated in the motherboard or be on a
separate expansion card
There are two types of controller cards: Host bus
Adapters and RAID Controller Cards.
HBA is an expansion card that plugs into a slot (PCI-e)
and provides fast reliable non-RAID I/O between the
host and storage devices.
HBA is low cost, high connectivity, limited functionality,
best performance
RAID is similar to HBA but adds redundancy, optimize
performance reduce latency. 30
3.3.4 Controller cards (RAID)
RAID (Redundant Array of Independent Disks) is a data
storage structure that allows a system to combine two or
more physical storage devices into a logical unit that is
seen by the attached system as a single drive.
RAID can be hardware based or software implemented.
Hardware RAID resides on PCI-X or PCI-e, or on a
motherborad – integrated RAID-on-Chip (ROC).
Better performance than software RAID, RAID cards can easily be
swapped out for replacement and upgrades. Data can be backed up
to prevent loss in a power failure.
More expensive than software Raid
Software Raid runs entirely on the CPU of the host
system
Lower cost
Lower RAID performance as CPU also powers the OS and Apps,
31
no data backup
3.3.5 RAID
Different levels of RAID implementation.
RAID 0 also known as stripe set striped
volume. Its spreads data over multiple drives
to enhance performance There is no reduncy
and hence no data protection. It provides
highest performance
32
3.3.5 RAID
RAID 1 creates an exact copy (mirror) of some
data or a disk.
This layout is useful when read performance or
reliability is more important than write
performance or the resulting data storage
capacity.
33
3.3.5 RAID
RAID 2 stripes data at the bit level (rather than
block level) and uses Hamming codes for error
correction.
A separate disk is used for parity.
It is rarely used in practice
34
3.3.5 RAID
RAID 3 stripes data at the byte level with a
dedicated parity disk.
It is rarely used in practice
35
3.3.5 RAID
RAID 4 stripes data at the byte level with a
dedicated parity disk.
It is rarely used in practice
36
3.3.5 RAID
RAID5 Combines data striping for enhanced
performance with distributed parity for data
protectionto provide a recovery path in case of
failure.
Best cost/performance balance for multi-drive
environment.
37
3.3.5 RAID
RAID 6 Provides double redundancy and the
ability to sustain two drive failures. Data is
striped across at least 4 physical drives. A
second parity scheme is used to store and
recover data.
38
3.3.5 RAID Combinations
RAID 10 Combines RAID 0 (data striping) and
RAID 1 (disk mirroring). It has the highest
performance with highest data protection.
RAID 50 combines multiple RAID 5 sets with
data striping (RAID 0) to increase capacity and
performance without adding disks to each RAID
5 array. Increased capacity and performance for
multi array RAID5 environments.
RAID 60 Combines multiple RAID 6 sets with
data striping (RAID 0) to increase capacity and
performance without adding disks to each RAID
6 array. It has the highest Fault tolerance and the
highest data protection. 39
3.4 Adding a disk to Linux
Install new hardware
verify that hardware is recognized by BIOS or controller
– Boot, make certain device files already exist in /dev
e.g., /dev/sdc
Use fdisk/parted (or similar) to partition the drive
Verify the system type on each partition
Use mke2fs (-t ext4) on each regular partition
To create (an ext4) filesystem
Use mkswap to initialize swap partitions
Add entries to /etc/fstab
Mount by hand, then reboot to verify everything
40
hdparm: test/set hd params
hdparm will do simple performance tests
sudo /sbin/hdparm –Tt /dev/sda
Read man hdparm
41
3.4 Disk partitions
Drives are divided into one or more partitions that are
treated independently
Partitions make backups easier, confine damage
Typically have at least two or three
root partition (one)
everything needed to bring system up in single-user mode
(often copied onto another disk for emergencies)
swap partition (at least one)
stores virtual memory when physical memory is insufficient
user partition(s)
home directories, data files, etc.
boot partition - boot loader, kernel, etc.
42
3.6 Logical Volumes
Partitions are static and sometimes you would
want to change them
LVM (Linux Logical Volume Manager) lets you
combine partitions and drives to present an
aggregate volume as a regular block device (just
like a disk or partition)
Use and allocate storage more efficiently
Move logical volumes among different physical devices
Grow and shrink logical volume sizes dynamically
Take “snapshots” of whole filesystems
Replace on-line drives without interrupting service
Similar systems are available for other OSes
43
3.6 Logical Volumes
Tools for manipulating partitions are:
fdisk and its derivatives like cfdisk, sfdisk
parted and its variants like qtparted and
gparted
44
3.6 LVM
Sample Organization
sda1 sdc2 Physical volume
diskvg volume group
usrlv rootlv varlv logical volumes
45
3.6 LVM
The configuration file of LVM is found in the
directory /etc/lvm. The file /etc/lvm/[Link]
contains the global parameters.
The configuration of different volumes (physical,
groups and logical) are not found in a file but in a
structure present in the device itself.
The fdsik command displays the partition table
of a disk
# fdisk -l sda
46
3.6 LVM
The command to view the set of physical volumes
accessible to your system is
# pvdisplay (/dev/sdb)
Other commands
#vgdisplay : to display logical volumes
# pvcreate: to create a physical volume with
the following options:
–l max number of logical volumes
-p max number of physical volumes
-s size of physical extents
# lvcreate : to create a logical volume
#
47
Linux File Systems
Linux filesystems are created in partitions or volumes
ext2 (2nd Extended File System) is the native Linux file
system. File sizes can attain 2TB (2048 GB) and a
partition can 32 TB or even 128TB based on the size of
blocks and architecture.
ext3(3rd Extended File System) is common and most
widely used FS on Linux. Max file size can attain 2TB and
a partition 32 TB
Augments ext2fs to incorporate journaling
Journals contain filesystem updates
Journal log can reconstruct consistent filesystem
Journal speeds filesystem consistency checks
48
Linux File Systems
ext4 (Fourth Extended File System) is modern and
default FS on some distributions since 2010. Max
file size can attain 16TB and a partition can attain
1EB
Speeds large directories
Compatible with ext2 and ext3
Other filesystems also supported
– ReiserFS, IBM's JFS, SGI's XFS
Can read foreign filesystems (e.g., FAT, NTFS, ISO 9660)
Command to create a file system
49
Mounting a file system
Filesystem must be mounted before use
Must be made part of root filesystem
Can be mounted on (top of) any directory
# mount /dev/sda1 /usr/local
# df /usr/local
Use /mnt for temporary mounts
Want to set up automatic mounting
50
fsck: check and repair a file system
fsck is generally used to check and repair
a file system
51
File System Hierarchy
/bin : Essential user command binaries (for use by all
users)
/boot : Static files of the boot loader (e.g., kernel)
/dev : Device files (terminals, disks, modems, etc.)
/etc : Host-specific system configuration
/home : User home directories (optional)
/lib : Essential shared libraries and kernel modules
/media : Filesystems on removable media
/opt : Add-on application software packages
/proc : Kernel and process information virtual filesystem
52
File System Hierarchy
/root : Home directory for the root user (optional)
/sbin : Static system binaries for repairing, booting, & recovering OS
/usr
/usr/bin : Most commands and executables
/usr/include : Header files for C programs
/usr/lib : Libraries and support files for standard programs
/usr/local : Local software (stuff you install)
/usr/man : Manual pages
/usr/sbin : Less essential sysadmin commands
/usr/share : Content that is common to multiple systems (RO)
/usr/src : Source code for (nonlocal) software packages
/var
/var/adm : Various logs, system setup records
/var/log : System log files
/var/spool : Spooling directories for printers, mail, dns
/var/tmp : More temporary space (preserved between reboots)
53
3.7 Files
Linux recognizes the following file types
[-] - Regular files
[d] - Directories
[c] - Character device files
[b] - Block device files
[s] - Local domain sockets
[p] - Named pipes (FIFO)
[l] - Symbolic links
● ls -ld shows the filetype of a file
54
3.7 Files
Linux recognizes the following file types
[-] - Regular files
[d] - Directories
[c] - Character device files
[b] - Block device files
[s] - Local domain sockets
[p] - Named pipes (FIFO)
[l] - Symbolic links
● ls -ld shows the filetype of a file
55
File attributes
Can be modified by chmod
Attributes defined for user, group and
others.
File ownership can be modified using
chown
56
File occupation statistics
df allows to obtain occupational statistics
for a mounted file system or directory
du gives info on occupied space used by a
directory
57