Candidates should be able to configure kernel options to support various drives. This objective includes software tools to view and modify hard disk settings.
This objective has a weight of 1 point.
Revision: $Revision: 949 $ ($Date: 2012-07-19 16:20:17 +0200 (Thu, 19 Jul 2012) $)
Candidates should be able to configure kernel options to support various drives. This objective includes software tools to view and modify hard disk settings.
Key Knowledge Areas:
The following is a partial list of used files, terms, and utilities:
/dev/hd* and /dev/sd*Resources: LinuxRef02; Robbins01.2; LinuxRef03; USBRef01; LinuxRef04; LinuxRef05; Will00; the man pages for the various commands.
To install a new disk in your system, you will need to physically
install the hard drive and configure it in your computer's BIOS. Linux will
detect the new drive automatically in most cases. You could type
dmesg | more to find out what the drive is called. The
second IDE drive in your system will be named /dev/hdb.
We will assume that the new drive is /dev/hdb.
On older kernels IDE devices are named as /dev/hd[a-d],
where a is used for the primary master IDE device, b is the primary slave, c the secondary
master and d is the secondary slave IDE device. Since IDE devices are getting replaced by
SATA (Serial ATA) devices, modern devices are named /dev/sd*
You must now partition your new disk. As root in
a shell type:
fdisk /dev/hdb
This will take you to a prompt that says Command (m for help):.
At the prompt, type p to display the existing partitions. If you have
partitions that you need to delete, type d, then at the prompt, type
the number of the partition that you wish to delete. Next, type n to
create the new partition. Type 1 (assuming that this will be the first
partition on the new drive), and hit enter. Then you will be prompted for
the cylinder that you want to start with on the drive. Next, you will be asked for the
ending cylinder for the partition. Repeat these steps until all partitions are created.
To put a clean filesystem on the first partition of your newly partitioned drive, type:
mkfs /dev/hdb1
Repeat this step for all partitions. You can use the -t
parameter to define the filesystem type to build, e.g. ext2,
ext3, xfs,
minix etc. (the section called “Creating Filesystems”).
You will now need to decide the mount point for each new partition on your drive.
We will assume /new. Type:
mkdir /new
to create the mount point for your drive. Now you will need to edit
/etc/fstab. You will want to make an entry at the
end of the file similar to this:
/dev/hdb1 /new ext2 defaults 1 1
After you have created a similar entry for each partition, write the file.
mount -a
will mount the partitions in the directory that you specified in
/etc/fstab.
When a kernel interacts with ext2 or ext3 filesystems the tune2fs command can be used to configure the interaction. Noteworthy options of this command are:
This option defines how the kernel should react in case of errors on the filesystem to which this command is applied. Possible behaviours are:
Ignore the error on the filesystem. Report the read or write error to the application that tries to access that part of the filesystem.
Remount the filesystem as read-only. This secures data that is already on disc. Applications that try to write to this filesystem will result in error.
This causes a kernel panic and the system will halt.
Full filesystems have very bad performance due to fragmentation. To prevent regular users from filling up the whole filesystem a percentage of the blocks will be reserved. This reserved part cannot be used by regular users. Only the root user can make use this part of the filesystem.
The default percentage of the reserved blocks is 5%. With disks becoming ever larger, setting aside 5% would result in a large number of reserved blocks. For large disks 1% reserved blocks should be sufficient for most filesystems.
This sets the mount options of the filesystem. Command line options
or options in /etc/fstab take precedence. The ^-sign
clears the specified option.
This option is supported by kernel 2.4.20 and above.
Enable or disable the sparse superblock feature. Enabling this feature on large filesystems saves space, because less superblocks are used.
After enabling or disabling this feature the filesystem must be made valid again by running the e2fsck command.
The hdparm command is used to set/get SATA/IDE device parameters. It provides a command line interface to various kernel interfaces supported by the Linux SATA/PATA/SAS "libata" subsystem and the older IDE driver subsystem. Newer (from 2008) USB disk enclosures now support "SAT" (SCSI-ATA Command Translation) so they might also work with hdparm.
The syntax for this command is:
hdparm [options] [device]
Frequently used options are:
Get or set the sector count for filesystem read-ahead.
Get or set the using_dma flag.
Display drive geometry.
Display identification information.
Get (1) or set (0) the read-only flag.
Perform device read for benchmarking.
Perform device cache read for benchmarking.
Display all settings, except -i.
See also man hdparm for more information.
The sdparm command is used to access SCSI mode pages, read VPD (Vital Product Data) pages and send simple SCSI commands.
The utility fetches and can change SCSI device mode pages. Inquiry data including Vital Product Data pages can also be displayed. Commands associated with starting and stopping the medium; loading and unloading the medium; and other housekeeping functionality may also be issued by this utility.
In the section called “Kernel Components (201.1)” and on, the process to configure and debug
kernels is described. Additional kernel options may be configured by patching
the kernel source code. Normally the kernel's tunable parameters are listed
in the various header files in the source code tree. There is no golden rule
to apply here - you need to read the kernel documentation or may even need to
crawl through the kernel-code to find the information you need. Additionally,
a running kernel can be configured by either using the /proc
filesystem or by using the sysctl command.
Current kernels also support dynamic setting of kernel parameters. The
easiest method to set kernel parameters is by modifying the /proc
filesystem. You can use the echo command to set parameters,
in the format:
echo "value" > /proc/kernel/parameter
e.g. to activate IP-forwarding:
echo 1 >/proc/sys/net/ipv4/ip_forward
The changes take effect immediately but are lost during reboot.
The /proc/ filesystem can also be queried. To see which
interrupts a system uses, for example you could issue
# cat /proc/interrupts
which generates output that may look like this:
CPU0
0: 16313284 XT-PIC timer
1: 334558 XT-PIC keyboard
2: 0 XT-PIC cascade
7: 26565 XT-PIC 3c589_cs
8: 2 XT-PIC rtc
9: 0 XT-PIC OPL3-SA (MPU401)
10: 4 XT-PIC MSS audio codec
11: 0 XT-PIC usb-uhci
12: 714357 XT-PIC PS/2 Mouse
13: 1 XT-PIC fpu
14: 123824 XT-PIC ide0
15: 7 XT-PIC ide1
NMI: 0
Kernel tuning can be automated by putting the echo commands in
the startup scripts (e.g. /etc/rc.d/rc.local. Some distributions
support the sysctl command. The sysctl command
is used to modify kernel parameters at runtime. The parameters that can be modified
by this command are listed in the /proc/sys directory tree.
Procfs is required
for sysctl support under Linux. sysctl can be
used to read as well as write kernel parameters.
Frequently used options of the sysctl command are:
Display all values currently available.
Use this option to ignore errors about unknown keys.
Use this option to disable printing of the key name when printing values.
Load sysctl settings from the file specified, or /etc/sysctl.conf if none given. Specifying "-" as filename means reading data from standard input.
Use this option to change a sysctl setting.