Developer Forums | About Us | Site Map


Useful Lists

Web Host
site hosted by netplex

Online Manuals

Windows-to-Linux roadmap: Part 6 Working With Partitions
By Chris Walden - 2004-07-08 Page:  1 2 3 4


Partitions in Linux work essentially the same as they do in Windows. The fdisk console command is used to create and manipulate partitions. When you execute fdisk, you must point it toward a device. To see the available devices, use the command fdisk -l.

Listing 2. Using fdisk

[root@cmw-t30 root]# fdisk -l

Disk /dev/hda: 240 heads, 63 sectors, 7752 cylinders
Units = cylinders of 15120 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1         8     60448+  8e  Linux LVM
/dev/hda2             9        15     52920   83  Linux
/dev/hda3   *        16      1403  10493280    c  Win95 FAT32 (LBA)
/dev/hda4          1404      7751  47990880    f  Win95 Ext'd (LBA)
/dev/hda5          1404      5565  31464688+  83  Linux
/dev/hda6          5566      5635    529168+  82  Linux swap
/dev/hda7          5636      7751  15996928+   b  Win95 FAT32

The above list was generated from a laptop, so it shows a rather unorthodox structure for a server. It shows one IDE hard drive with several partitions. If there were other devices, they would be listed as well. For example, a second IDE hard drive might be shown as /dev/hdb.

Run fdisk again with a device, and you get a short prompt.

Listing 3. fdisk on a device

[root@cmw-t30 root]# fdisk /dev/hda

The number of cylinders for this disk is set to 7752.
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)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):

Entering "m" will give you a menu of commands. You can display the current partition table with "p." You can create, delete, and modify the type for existing partitions. "l" will show you the full list of partition types available. Write your changes to the partition table with "w", and exit the program, or quit without saving with "q." Some changes will take place immediately. Some types may require a system reboot.

Partition rules under Linux are the same as they are in Windows. You are allowed four primary partitions, any of which can be extended partitions.

File system types

Linux can handle any file system type that the kernel knows about. A generous number of them come compiled by default, and new ones can be added. Here are some interesting ones:

  • ext2: The standard Linux file system
  • ext3: The standard Linux file system with journaling added
  • vfat: Microsoft's Fat32 file system
  • jfs: IBM's journaled file system
  • reiserfs: Another popular journaled file system

Journaling saves time and data
Journaled file systems help protect data from unexpected shutdowns. If a volume is shut down without dismounting, there may be unfinished work and files left in an in-between state. With a typical file system, this requires a full check of the volume, which can take a long time for large volumes. A journaled file system keeps a transaction record of each write to the disk for a period of time, such as five seconds. When the volume is not cleanly unmounted, the file system simply rolls back to the last known good state. A volume that would take twenty minutes to come back up now comes up in seconds!

Formatting partitions

Once created, partitions are formatted with the correct version of the mkfs command. File systems will have their own version of the mkfs, such as the mkfs.ext2, or the mkfs.ext3. These helper scripts let you create a file system by simply pointing to the partition. Here are some examples:

Listing 4. Using mkfs

 # Create an ext2 file system on the third
 # parition of the first IDE hard drive
mkfs.ext2 /dev/hda3

 # Create an ext3 file system on the first
 # partition of the 2nd SCSI hard drivemkfs.ext2
mkfs.ext3 /dev/sdb1

 # Create a jfs file system in an extended
 # partition on the first IDE hard drive.
mkfs.jfs /dev/hda5

There are various advanced parameters to affect how the partition is formatted, but for general purposes, the defaults are fine. Once the partition has been formatted, it can be mounted into the / file system. A file system must be unmounted to be reformatted.

Other file system tools

Let's take a look at other useful tools.

Console tools

There are several tools for looking at the condition of disks and file systems.

df stands for "disk free." It reports the amount of disk space used and available on mounted file systems. Useful switches:

Checking disk space

df -hHuman readable; uses friendly k, M, and G indicators to show file size rather than listing them in bytes
df -lLimits the listing to local file systems; by default, remote file systems are also listed

du stands for "disk usage." It reports the amount of disk space used by the specified files and for each subdirectory (of directory arguments). Useful switches:

Checking disk usage

du -aShows counts for all files, not just directories
du -hHuman readable; uses friendly k, M, and G indicators to show file size rather than listing them in bytes
du -cPrints a grand total of all arguments after all arguments have been processed; can be used to find out the total disk usage of a given set of files or directories
du -sDisplays only a total for each argument

This is the program used to check and repair file systems, equivalent to chkdsk in Windows. It will have different versions for different file system types, just like mkfs. fsck must be run on unmounted volumes, though it is rarely needed unless the file system was not cleanly unmounted. man fsck and info fsck provide details, as do several of the Resources included at the end of this article.


Webmin has several tools to work with file systems and partitions.

Figure 1. Webmin partition tool
Figure 1. Webmin partition tool

Hardware, partitions on local disks

Each disk and partition is shown with current usage information. Click on a file system to see details. Unmounted partitions can have their type edited and file systems formatted.

System, disk, and network filesystems

Mount and unmount file systems listed in /etc/fstab. Common file system types have a wizard for creating entries. Unrecognized types can be mounted and unmounted from here, but must be hand-edited in /etc/fstab. Most server file systems can be handled well from here.

The whole is the sum of its partitions

Though there are many similarities in how Windows and Linux handle partitions and file systems, moving from drive letters to a completely hierarchical tree will probably take some adjustment. As always, there are robust console tools to work with these functions and configuration files in the /etc directory. Browser-based front ends like Webmin offer some helpful tools.

View Windows-to-Linux roadmap: Part 6 Working With Partitions Discussion

Page:  1 2 3 4 Next Page: Resources

First published by IBM developerWorks

Copyright 2004-2017 All rights reserved.
Article copyright and all rights retained by the author.