Created Tuesday 22/8/2006
Adding a new phyiscal disk to a linux environment is pretty straight forward. This document describes partitioning and formatting.
The simplest way to determine where the new device is attached is to run hwbrowser(1), which can be installed via yum hwbrowser.noarch). This is a graphical tool that lists the devices attached to the current booted environment. As might be expected, physical disks appear under the Hard Disks entry. This command needs to run as root:
bash# hwbrowser
Note: Serial ATA harddisks are mounted as scci so appear (e.g.,) on /dev/sda
Typically harddisk entries appear as /dev/hda (hdb, hdc and so on). A disk with no paritions will have no partition entries. The USB/IDE 3.5" disk devices appear as SCSI device under, e.g., /dev/sda (because the usb interface attaches devices using the scsi driver).
If the device already has a filesystem, then mount(8) can be used (see mount).
There are heaps of tools for partitioning, such as Disk Druid, PartEd, fdisk and so on. Fdisk is a command line tool and is pretty straight forward. The following continues the same example of the USB 3.5". Fdisk needs to run as root:
bash# fdisk /dev/sda Command (m for help): n ◀― 'n' for new partition Command action e extended p primary partition (1-4) p ◀― 'p' for primary Partition number (1-4): 1 ◀― '1' for the 1st partition First cylinder (1-10011, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-10011, default 10011): Using default value 10011
Note: The cynlinder selection above consumes the whole disk from cylinder 1 to the end. To add multiple partitions enter either the amount in MB or KB or the appropriate cylinder numbers. E.g., Last cylinder: +100MB
Command (m for help): p ◀― 'p' to show changes
Disk /dev/sdd: 82.3 GB, 82348277760 bytes 255 heads, 63 sectors/track, 10011 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdd1 1 10011 80413326 83 Linux
Command (m for help): w ◀― 'w' to commit the changes
Use one of the mkfs variants to format a partition. E.g., to add an ext3 partition, use mkfs.ext3, which must run as root. The -c option can optionally be specified, which will check for bad blocks during the format process.
bash# mkfs.ext3 /dev/sdd1
mke2fs 1.36 (05-Feb-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
10059776 inodes, 20103331 blocks
1005166 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=20971520
614 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
In Linux, there can be only one swap partition, which is a primary partition which has it's partition type specified as Linux swap (type 82). To make the swap partition usable, the partition must be formatted using the mkswap command. If no swap partition exists, then a new primary partition must be created and it's partition type must be 82.
The size of the partition should be the size intended to allocated to the kernel for swap. I.e., If 2GB of swap is to be used, then the size of the parition should be 2GB. The calculation for determining the optimal size of the swap parition is x.
The mkswap(8) command is used to format an existing swap partition so that it is usuable by the kernel. The partition must already exist before mkswap(8) is issued. The fdisk(8) program is used to determine if a swap parition exists and is also used to create a swap partition if it doesn't.
The (-l) option of fdisk(8) will list the partition table. Use this option to determine if a swap partition exists, by scanning the listed entries for device with ID 82 (System type is Linux swap). If no swap partition exists, then one must be created, which is done by building a new primary partition of the required (swap space) size and then changing the partition type to swap (type 82). The partition type is changed by the t menu option of disk. This should be done before the partition table is written (which is done by the w menu option).
Tip: Use fdisk -l to determine which device is the the swap partition
Note: A swap parition must already exist before mkswap can be issued
Formatting a swap partition is a little different to formatting a normal (non-swap) partition, in that mkfs(8) is not used. Instead use mkswap(8), which can also take the -c option and must run as root. The argument to mkswap(8) is the device pathname to format and this must be an existing device. A swap device is a device with a partition type of Linux swap (which is type 82). If no such parition exists, then one must be created (see #4.A):
bash $ mkswap /dev/sdd2
Note: Serial ATA devices are /dev/sd* (e.g., /dev/sda6), whereas IDE devices are /dev/hd* (e.g., /dev/hda4)
This section is a discussion of the Self-Monitoring, Analysis and Reporting Technology System (S.M.A.R.T) tool suite. The S.M.A.R.T tools are mainted at smartmontools.sourceforge.net, which package Smartmontools which basically contain two utility programs smartctl and smartd to control and monitor storage systems using the SMART api. Both ATA and SCSI. The following sections are a discussion of running and analysing the smart tools diagnostics.
The smartmontools can be used to monitor the health status of a disk (ata or scsi) and give an indication of likely failure. The smartd daemon must be running (see configuration, for Fedora Core, in /etc/smartd.conf and /etc/sysconfig/smartmontools)
bash# /etc/init.d/smartd start
Once running, smartctl(1) can be used to query the health status and failure indicators:
bash# smartctl -a /dev/hda
The configuration for smartd (/etc/smartd.conf) has one entry per device. Each entry can define a whole bunch of activities, like which device and what type (/dev/hda as ata), the type of monitoring to do (-a for all, or selective like -H for health only, -l error for errors only. These options, except -a of course, can be combined) In addition, an entry can define mail notificiations and what application or script to run when the mail notification fires. Also, polling tests can be performed which do long and/or short offline tests. For example, consider an entry in /etc/smartd.conf such as:
/dev/hda -a -d ata -S on -o on -s (L/../../7/03|S/../.././02) -m foo -M smartdnotify
The previous entry says: Monitor /dev/hda, an ata disk (-d ata) reporting on all attributes (-a). Turn on Attribute Autosave (-S on) and turn on Automatic Offline Testing (-o on). Run 2 types of polling tests, -s (xxx|xxx), the first of which is a long test (L/) on Sundays between 3:00 am and 4:00 am. The second polling test is specified as a short test (S/) and is to run between 2:00 am and 3:00 am daily. Notifications of failures are to be sent via mail to use "foo" (-m foo). The mail program is specified to be a program called "smartdnotify" (-M smartdnotify) instead of mail(1). As the stdin contains the message that should to send, so any program specified by the -M option should be able to read stdin to obtain the message itself. In addition to the mail content being available on the stdin, several environent variables are made available, most notably:
The smartctl(1) program can be used to query disk health and error logs. The simplest form of report is the give-me-all report, which is indicated by giving the -a option. The particular report is divided into 3 sections:
Section one is an overview of the physcial disk
An attribute summary is provided in section two. The ATA-5 (and others) standard provides for an attribute id with threshold values, current raw value and other information. For example, the temp attribute might of section 2 of a -a report is id 9, and might be:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 9 Power_On_Minutes 0x0032 097 097 000 Old_age Always - 1993h+15m
Where VALUE is the normalized value of the RAW_VALUE and is used to determine if this attribute triggers a failure. For example, the RAW_VALUE says the disk has a power-on-minutes of 1,993 hours and 15 minutes. The VALUE of 97 used compared to THRESH and if it's less than or equal to THRESH then the attribute fails. The TYPE column is used to determine the failure for example, if this particular attribute does fail according to THRESH, then it's because it's exceeded the manufactures life time specs (old age). This is not too worrysome, but a TYPE of prefail indicates that catastrophic failure is likely within 24 hours. The WHEN_FAILED column is the time at when the attribute failed. The UPDATED column indicates if this attribute is update via an offline test offline or automatically with always.
Section three, the final section lists a summary of the tests run (offline extended and offline short). If the disk supports automatic Attribute update (which can be determined by section 1 of a -a report, then smartctrl can turn on a cyclic check to update these attributes every few hours. E.g.,
bash# smartctl -a /dev/hda ◀― determine if auto update is supported bash# smartctl -o on /dev/hda ◀― turn it on
The specs for the hitachi 40GB in the Sony VAIO PC-GRT25 can be found here.
Note: It may be worth downloading a copy of the Hitatchi 23EA40 spec as these types of documents are often taken offline
The program e2label(1) can be used to label an ext2/ext3 partition and mlabel(1) to label an msdos/vfat partition. Running e2label(8) without a label argument will print the current label for the device, which may be empty.
bash# e2label /dev/sdc1
To set a devices label value, simply provide a labelname an argument to e2label(8):
bash# e2label /dev/sdc1 largedisk
For xfs filesystems use xfs_admin(8) to label the partition:
bash# xfs_admin -L xfslabel /dev/sdd1
For vfat/msdos partitions, use mlabel(1):
bash# mlabel
The Hardware Abstraction Layer (HAL) daemon is responsible for managing entires in fstab(5). The HAL daemon posts notification of events (i.e., add and remove) specifically for devices of type storage and volume.
When the HAL daemon starts, the fstab-sync program runs and modifies entries in fstab(5) and creates mount points in /media.
After a new storage device is added, the simplest way mount it is to simply restart the HAL daemon. This must be done as root:
bash# /etc/init.d/hal restart
The new device should now appear in /media, under a mount point of the name of the device's label.
Devices can be mounted manually via the mount(8) command. Run without any arguments, mount(8) will show the currently mounted devices. To mount a device, the program must be run as root. The mount program will try to automatically detect the type of the device (ext3, vfat, and etc), but this may be specified with the -t option. To mount an ext3 device attached to /dev/sda1 to the mount point /mnt/tmp:
bash# mount -t ext3 /dev/sda1 /mnt/tmp
The umount(8) program is used to remove mount points. To remove a mounted device, simply provide it's current mount point. Continuing from the previous example:
bash# umount /mnt/tmp
Note: Manual mounting is typically not recomended for devices that are permenantly attached (or that are part of the systems usual configuration, such as external devices).
The fstab(5) table defines a mapping between devices and mount points and specifies options for each device such as mount on boot and similar. In Fedora Core, the hal(8) daemon is the preferred model of managing fstab(5) entries. Refer to comments in mount.
Another option for managing devices and mount points is the automounter, autofs(8). Again, in Fedora Core, autofs(8) is not recommended for devices attached as part of the usual system configuration. The automounter is useful for mounting smb, ntfs and remote partitions. See for example the auto.misc and auto.net files. A more complete discussion of the automounter is available in mount.txt and example automounter configuration in autofs.
Mounting a formatted usb storage device such as a memory stick, compact flash or externally attached usb harddisk is simple. First ensure that both the usb_storage and ohci_hcd modules are loaded:
bash $ lsmod | grep "usb_storage|ohci_hcd"
If a vanilla kernel, theses modules should automatically be loaded via /etc/modprobe.conf and /etc/modprobe.d. If they're not loaded, then load them via modprobe(1) as root:
bash $ modprobe usb_storage ohci_hcd
Once the relevant modules are loaded, determine the device location using either lsusb(1) or hwbrowser(1) (see #1) and then use mount(1) with the appropriate file system time. For example, if a vfat formatted usb compact flash is attached to /dev/sdc1:
bash $ mount -t vfat /dev/sdc1 /mnt/cflash
Stuart Moorfoot © 22 Aug 2006 foo@bund.com.au