Linux Know-How provides a collection of introductory texts on often needed Linux skills.


Hard Drive/Floppy Disk Utilities

fdisk /dev/hda

(= "fixed disk". As root.) Linux hard drive partitioning utility (DOS has a utility with the same name). In the example above, I specified that I would like to partition the first harddrive on the first IDE interface, hence "hda". If I were you, I would backup any important data before using fdisk on any partition. I do not not know anybody who likes fdisk (either Linux or DOS edition)--I prefer easier to use cfdisk, see next command.

cfdisk /dev/hda

(as root) Hard drive partitioning utility, menu-based. Easier to use then the plain-vanilla fdisk (see the previous command). Physical drives can contain primary partitions (max 4 per disk), and logical partitions (no restriction on number). A primary partition can be made bootable. Logical partitions must be contained within "extended partitions"; extended partitions are not usable by themselves, they are just a container for logical partitions. When partitioning a disk, I typically: (1) create a primary partition (2) make the primary partition bootable (3) create an extended partition, (4) create logical partition(s) within the extended partition.

sfdisk -l -x |more

(as root) List the partition tables (including extended partitions) for all drives on my system.

parted /dev/hda

A partition manipulation utility for Linux (ext2), and DOS (FAT and FAT32) hard drive partition. It is for creation, destroying, moving, copying, shrinking, and extending partitions. You should really like to backup your data and carefully read info parted before using it.

fdformat /dev/fd0H1440

mkfs -c -t ext2 /dev/fd0

(=floppy disk format, two commands, as root) Perform a low-level formatting of a floppy in the first floppy drive (/dev/fd0), high density (1440 kB). Then make a Linux file system (-t ext2), checking/marking bad blocks (-c ). Making the file system is an equivalent to the high-level formatting. I can also format floppies to different (also non-standard) densities; try ls /dev/fd0<Tab><Tab> .I am also able to format to the default density (normally 1440k) using fdformat /dev/fd0.

badblocks /dev/fd01440 1440

(as root) Check a high-density floppy for bad blocks and display the results on the screen. The parameter "1440" specifies that 1440 blocks are to be checked. This command does not modify the floppy. badblocks can be also used to check the surface of a hard drive but I have to unmount the file system first to do a full read-write check:

[use mount to find out which device contains the disk partition I wish to check for bad blocks]

mount

[unoumnt the selected partition]

umount /dev/hda8

[check the selected partition in a non-destructive read-write mode, so that my data is not erased!]

badblocks -n /dev/hda8

[mount the partition back since no info on bad blocks was printed]

mount /dev/hda8

If bad blocks are found, they can be marked on the hard drive so that will not be used using:

e2fsck -c /dev/hda8


fsck -t ext2 /dev/hda2

(=file system check, as root) Check and repair a file system, e.g., after an "unclean" shutdown due to a power failure. The above example performs the check on the partition hda2, file system type ext2. You definitely want to unmount the partitions or boot Linux in the "single mode" to perform this (type "linux single" at the LILO prompt or use init 1 as root to enter the single user mode). If errors are found during the file system checkup, I accept the defaults for repair. The problems with "unclean shutdown" can be avoided if you use a journaling file system (e.g., ext3) on your system (highly recommended).

tune2fs -j /dev/hda2

(as root, only for kernel that support ext3--RH7.2) Adjust the tunable parameter of an ext2 file system. The example above shows how to add a journal to a disk partition (hda2 in this example), effectively converting the file system to ext3 (journaling) file system. To complete the transition, you must also edit the file /etc/fstab and change the file system type from ext2 to ext3, else you may run into problems--ext2 will not mount an uncleanly shut down journaled file system! To check what is the type of the file system use mount (with no arguments) or cat /etc/mtab. If you need more information on ext3 setup, try: http://www.symonds.net/~rajesh/howto/ext3/ext3-5.html.

Other options of tune2fs let you me add a volume label, adjust the number of mounts after which the file system check is performed (maximal mount count), or turn on time-based file system checks instead (less often used).

dd if=/dev/fd0H1440 of=floppy_image

dd if=floppy_image of=/dev/fd0H1440

(two commands, dd="data duplicator") Create an image of a floppy to the file called "floppy_image" in the current directory. Then copy floppy_image (file) to another floppy disk. Works like DOS "DISKCOPY".

mkbootdisk --device /dev/fd0 2.4.2-3

Make an emergency boot floppy. You are typically asked if you would like to make a boot disk during the system installation. The above command shows how to make it after install, on the first floppy drive (/dev/fd0). Your kernel name (needed in the command, here 2.4.2-3) can be determined either by running uname -a or ls /lib/modules.


Last Update: 2010-12-16