Creating File Systems: mkfs, mke2fs, mkswap, parted, and fdisk

 < Day Day Up > 



Linux provides a variety of tools for creating and managing file systems, letting you add new hard disk partitions, create CD images, and format floppies. To use a new hard drive, you will first have to partition it and then create a file system on it. You can use either parted or fdisk to partition your hard drive. To create the file system on the partitions, you use the mkfs command, which is a front end for various file system builders. For swap partitions, you use a special tool, mkswap, and to create file systems on a CD-ROM, you use the mkisofs tool. Linux partition and file system tools are listed in Table 30-10.

fdisk

To start fdisk, enter fdisk on the command line with the device name of the hard disk you are partitioning. This brings up an interactive program you can use to create your Linux partition. Be careful using Linux fdisk. It can literally erase entire hard disk partitions and all the data on those partitions if you are not careful. The following command invokes fdisk for creating partitions on the hdb hard drive.

fdisk   /dev/hdb 
Table 30-10: Linux Partition and File System Creation Tools

Tool

Description

fdisk

Menu-driven program to create and delete partitions.

cfdisk

Screen-based interface for fdisk.

parted

GNU partition management tool.

mkfs

Creates a file system on a partition or floppy disk using the specified file system type. Front end to formatting utilities.

mke2fs

Creates an ext2 file system on a Linux partition; use the -j option to create an ext3 file system.

mkfs.ext3

Creates an ext3 file system on a Linux partition.

mkfs.ext2

Creates an ext2 file system on a Linux partition.

mkfs.reiserfs

Creates a Reiser journaling file system on a Linux partition (links to mkreiserfs).

mkfs.jfs

Creates a JFS journaling file system on a Linux partition.

mkfs.dos

Creates a DOS file system on a given partition.

mkfs.vfat

Creates a Windows 16-bit file system on a given partition (Windows 95, 98, and ME).

mkswap

Tool to set up a Linux swap area on a device or in a file.

mkdosfs

Creates an MS-DOS file system under Linux.

mkisofs

Creates an ISO CD-ROM disk image.

Gfloppy

GNOME tool to format a floppy disk (Floppy Formatter entry on the System Tools menu).

The partitions have different types that you need to specify. Linux fdisk is a line-oriented program. It has a set of one-character commands that you simply press. Then you may be prompted to type in certain information and press ENTER. If you run into trouble during the fdisk procedure, you can press Q at any time, and you will return to the previous screen without any changes having been made. No changes are actually made to your hard disk until you press W. This should be your very last command; it makes the actual changes to your hard disk and then quits fdisk, returning you to the installation program. Table 30-11 lists the commonly used fdisk commands. Perform the following steps to create a Linux partition.

Table 30-11: Commonly Used fdisk Commands

Command

Action

a

Toggle a bootable flag

l

List known partition types

m

List commands

n

Add a new partition

p

Print the partition table

q

Quit without saving changes

t

Change a partition's system ID

w

Write table to disk and exit

When you press N to define a new partition, you will be asked if it is a primary partition. Press P to indicate that it is a primary partition. Linux supports up to four primary partitions. Enter the partition number for the partition you are creating. Enter the beginning cylinder for the partition. This is the first number in parentheses at the end of the prompt. You are then prompted to enter the last cylinder number. You can either enter the last cylinder you want for this partition or enter a size. You can enter the size as +1000M for 1GB, preceding the amount with a + sign. Bear in mind that the size cannot exceed your free space. You then specify the partition type. The default type for a Linux partition is 83. If you are creating a different type of partition, such as a swap partition, press T to indicate the type you want. Enter the partition number, such as 82 for a swap partition. When you are finished, press W to write out the changes to the hard disk, and then press ENTER to continue.

parted

As an alternative to fdisk, you can use parted (www.gnu.org/software/parted). parted lets you manage hard disk partitions, create new ones, and delete old ones. Unlike fdisk, it also lets you resize partitions. For you to use parted on the partitions in a given hard drive, none of the partitions on that drive can be in use. This means that if you wish to use parted on partitions located on that same hard drive as your kernel, you have to boot your system in rescue mode and choose not to mount your system files. For any other hard drives, you only need to unmount their partitions and turn your swap space off with the swapoff command. You can then start parted with the parted command and the device name of the hard disk you want to work on. The following example starts parted for the hard disk /dev/hda.

parted  /dev/hda

You use the print command to list all your partitions. The partition number for each partition will be listed in the first column under the Minor heading. The Start and End columns list the beginning and end positions that the partition uses on the hard drive. The numbers are in megabytes, starting from the first megabyte to the total available. To create a new partition, use the mkpart command with either primary or extended, the file system type, and the beginning and end positions. You can create up to three primary partitions and one extended partition (or four primary partitions if there is no extended partition). The extended partition can, in turn, have several logical partitions. Once you have created the partition, you can later use mkfs to format it with a file system. To remove a partition, use the rm command and the partition number. To resize a partition, use the resize command with the partition number and the beginning and end positions. You can even move a partition using the move command. The help command lists all commands.

mkfs

Once you create your partition, you have to create a file system on it. To do this, use the mkfs command to build the Linux file system and pass the name of the hard disk partition as a parameter. You must specify its full pathname with the mkfs command. Table 30-12 lists the options for the mkfs command. For example, the second partition on the first hard drive has the device name /dev/hdb1. You can now mount your new hard disk partition, attaching it to your file structure. The next example formats that partition:

# mkfs -t ext3 /dev/hdb1

The mkfs command is really just a front end for several different file system builders. A file system builder performs the actual task of creating a file system. Red Hat supports various file system builders, including several journaling file systems and Windows file systems. The name of a file system builder has the prefix mkfs and a suffix for the name of the type of file system. For example, the file system builder for the ext3 file system is mkfs.ext3. For Reiser file systems, it is mkfs.reiserfs, and for Windows 16-bit file systems (95, 98, ME), it is mkfs.vfat. Some of these file builders are just other names for traditional file system creation tools. For example, the mkfs.ext2 file builder it just another name for the mke2fs ext2 file system creation tool, and mkfs.msdos is the mkdosfs command. As ext3 is an extension of ext2, mkfs.ext3 simply invokes mke2fs, the tool for creating ext2 and ext3 file systems, and directs it to create an ext3 file system (using the -j option). Any of the file builders can be used directly to create a file system of that type. Options are listed before the device name. The next example is equivalent to the preceding one, creating an ext3 file system on the hdb1 device.

mkfs.ext3 /dev/hdb1 
Table 30-12: The mkfs Options

Options

Description

Blocks

Number of blocks for the file system. There are 1,440 blocks for a 1.44MB floppy disk.

-t file-system-type

Specifies the type of file system to format. The default is the standard Linux file system type, ext3.

file-system-options

Options for the type of file system specified. Listed before the device name, but after the file system type.

-V

Verbose mode. Displays description of each action mkfs takes.

-v

Instructs the file system builder program that mkfs invokes to show actions it takes.

-c

Checks a partition for bad blocks before formatting it (may take some time).

-l file-name

Reads a list of bad blocks.

The syntax for the mkfs command is as follows. You can add options for a particular file system after the type and before the device. The block size is used for file builders that do not detect the disk size.

mkfs options [-t type] file-sysoptions device size 
Tip 

Once you have formatted your disk, you can label it with the e2label command as described earlier in the chapter.

The same procedure works for floppy disk. In this case, the mkfs command takes as its argument the device name. It uses the ext2 file system (the default for mkfs), because a floppy is too small to support a journaling file system.

# mkfs /dev/fd0
Tip 

On the desktop, you can use the Floppy Formatter tool listed in the System Tools menu to format your floppy disks. The formatter enables you to choose an MS-DOS or Linux file system type.

mkswap

If you want to create a swap partition, you first use fdisk or parted to create the partition, if it does not already exist, and then you use the mkswap command to format it as a swap partition. mkswap formats the entire partition unless otherwise instructed. It takes as its argument the device name for the swap partition.

mkswap /dev/hdb2

You then need to create an entry for it in the /etc/fstab file so that it will be automatically mounted when your system boots.



 < Day Day Up > 



Red Hat(c) The Complete Reference
Red Hat Enterprise Linux & Fedora Edition (DVD): The Complete Reference
ISBN: 0072230754
EAN: 2147483647
Year: 2004
Pages: 328

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net