Annvix
Personal tools



/User Guide/Disks and Partitions

From Annvix

Disks and Partitions

Contents

Disks

Linux supports a variety of media as disks including hard drives, floppy drives, zip drives, and USB thumb drives. Each of those drives is referenced by a filename. Typically IDE drives are referenced as /dev/hda and SATA and SCSI drives are referenced as /dev/sda. In a machine with two IDE drives and one SATA drive, they would (most likely) be listed as:

/dev/hda
/dev/hdb
/dev/sda

Hard drives are ordered in the order that they are seen by the BUS and given a two letter designation for their type and a third letter for their order, so hd is an IDE drive and hda is the first IDE drive with hdb the second. The third device could be SATA or SCSI (maybe SAS) but is listed as the only one of this type in this example. CDROM and DVD drives may appear in the same list with a similar designation, but are often also shown with an alias like /dev/cdrom for convenience.

Partitions

Partitions within a drive are also listed in the /dev directory. Typical designations will append a number for each partition within the drive. For instance:

/dev/hda1
/dev/hda2
/dev/hda3
/dev/hda5
/dev/hda6

In this example, the drive has three partitions. Note that they will be displayed this way whether they contain a file system or not. Extended partitions will have a similar designation and so may also appear in the same list, which might lead to confusion for someone who hadn't read this introduction.

Please note that grub doesn't show drives the same way.1

In the example above, it is likely that /dev/hda1 and /dev/hda2 are normal partitions, while /dev/hda3 is an extended partition that allows the creation and use of /dev/hda5 and /dev/hda6. As an extended partition, it cannot be formatted or mounted, but is still necessary to exist. It is also possible that they are all normal partitions and the slot for {file|/dev/hda4}} is somehow removed.

The tool for managing partitions is fdisk. This tool allows users to create, delete, relabel and otherwise manipulate their partition table. For most users there are only a couple uses that they need to know. Typically, {prog|fdisk}} should not be used on an installed system while it is booted as you may remove or modify partitions that are currently mounted and in use. It is possible, however, to manipulate a drive that is not currently in use or to manipulate drives when booted from the Annvix installation CD.

WARNING: Using fdisk incorrectly can render your system unusable and un-bootable until it is rebuilt. Do not experiment with fdisk without reading beyond the information presented in this document.

# fdisk -l

Disk /dev/hda: 10.2 GB, 10239860736 bytes
16 heads, 63 sectors/track, 19841 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1       13563     6835720+   b  W95 FAT32
/dev/hda2           13579       14934      682762+   c  W95 FAT32 (LBA)
/dev/hda3           14935       19841     2473128   83  Linux
/dev/hda4           13564       13578        7560    5  Extended
/dev/hda5           13564       13578        7528+  83  Linux

Partition table entries are not in disk order

Disk /dev/hdb: 20.0 GB, 20020396032 bytes
255 heads, 63 sectors/track, 2434 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1               1          13      104391   83  Linux
/dev/hdb2   *          14        2434    19446682+  8e  Linux LVM

In the example above, the command fdisk -l is given from the shell and shows the partition tables on all accessible drives. In this example, the first two partitions of the first IDE drive are FAT32 partitions such as those used by some Windows systems. The third partition is a typical Linux partition, the fourth is an extended partition (which is necessary if you want to have more than four partitions) and the fifth is another typical Linux partition. Notice that it warns you that the entries are not in disk order, which is atypical for most systems, but can happen if you rearrange partitions. Notice also the asterisk next to /dev/hda1 and /dev/hdb2. The asterisk indicates that a partition is the default boot partition, which means it will be used to start the boot process.

On the second IDE drive the first partition is a typical Linux partition and the second one is one labeled for use by LVM.

LVM is not typically used for Annvix systems.2

Additionally you can see the starting and ending sectors used for the partitions as well as the number of blocks each contains.

# fdisk /dev/hda

The number of cylinders for this disk is set to 19841.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)

Command (m for help): p

Disk /dev/hda: 10.2 GB, 10239860736 bytes
16 heads, 63 sectors/track, 19841 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1       13563     6835720+   b  W95 FAT32
/dev/hda2           13579       14934      682762+   c  W95 FAT32 (LBA)
/dev/hda3           14935       19841     2473128   83  Linux
/dev/hda4           13564       13578        7560    5  Extended


Partition table entries are not in disk order

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help):  _

Typically you need to tell fdisk which disk you want to access as the first argument. This will take you into a command shell where you can issue commands to display and manipulate the system. In this example the first command issued was p, which simply displays the existing partition table information. When the command completes, the user is returned to a prompt where another command can be entered.

The second command entered in this example is m, which as indicated by the helpful tip, shows more commands that are available. Normal use of fdisk is to create new partitions, label partitions and remove them.

Creating a partition is initiated with the n command. When a user presses n at the prompt, they are given an additional prompt for where to start the first cylinder. The allowable range is displayed along with the default, typically the first cylinder not already in use by another partition as shown here:

Command (m for help): n
First cylinder (13564-13578, default 13564): 

If a user needs to leave space between partitions for other allocation or due to damage to the disks then they might use something other than the default, but most users can just hit Enter to accept the default. The next prompt will give the option of how to size the partition:

Using default value 13564
Last cylinder or +size or +sizeM or +sizeK (13564-13578, default 13578): 

At this prompt the user can specify the cylinder to end the partition or specify a size and have fdisk approximate the location to accommodate the desired content. Examples of allowable entries for this prompt would be: 13570 for "end the partition on cylinder 13570" or +30M for a 30MB partition (approximately), or +500K for a very small partition. Gigabytes can be specified as G on most systems as well. The default is to use all contiguous cylinders for the new partition, so pressing Enter will use the rest of the available space on the drive.

After the partition table is created to the desired specifications, the user must use w to save the partition table to the drive. q will leave fdisk without saving changes. d will give prompts to delete a partition. When someone is partitioning a new system, the command to make a partition bootable is b.

Editor's notes

There are some scenarios that are not covered by these examples that bear mentioning. RAID can occur in hardware which will present multiple disks as a single drive, and it can also occur in software which will present all the drives as independent letters. There may be drives that are not visible to fdisk as well, and those may need additional configuration of the operating system before use.3 There are also special partitions that can be created which are actually files accessed as partitions. These include loopback devices and crypto devices, both of which fall outside the scope of this discussion but might be encountered on various systems.

It is worth examining cfdisk as an alternative to using fdisk. The cfdisk tool offers all or nearly all the functionality of fdisk in a more user friendly format. It is not included in this guide as it is not as common to all Linux systems and is not typically considered as essential a tool as fdisk.

Foot Notes

1. Grub labels all drives as hd something, but uses numbers, starting with 0 instead of letters. For a system with two IDE hard drives and one SATA drive, the drives would be hd0, hd1 and hd2 respectively. Partitions are displayed similarly, so the first partition on the first drive would be hd0,0. Note that grub may not be able to access information within LVM or BSD style partitions at all, limiting the ability to use those types of systems as a boot partition for grub.

2. LVM - Logical Volume Management is a relatively new system of managing partitions within a Linux system. It allows for an abstraction layer between the operating system and physical partitions. Partitions designated for LVM are then made into "physical volumes" which can then be assigned to "volume groups". In this way multiple partitions, contiguous (or not), on the same drive (or not), even on different types of drives can be used to create a single partition as used by the OS. This abstraction makes it easier to expand and shrink partitions on a live system and also allows for snapshots to be created. Snapshots are small segments that contain all the differences that a regular partition has undergone since the snapshot was displayed and may be accessed to show the state the partition was in at the time of the snapshot and in current versions may even be manipulated. LVM capabilities depend on options included in the current stable Linux kernel and userspace tools and as such might be added to Annvix or already be available, but at the time of this writing probably fall outside normal use.

3. The ability to find and communicate with a drive depends on the drivers built into or loaded into the kernel. Most drives are automatically located and accessible without any extra effort.

References

Here are some external links that might be helpful in getting more detail about how disks and partitions work in Linux:

<< Return to User Guide





Sponsors: Bankruptcy - Debt Consolidation - Credit Card Consolidation - Loans