-->
Previous Table of Contents Next


Changing the Partition Type

The next thing that you need to do is change the partition type for each partition. To change the partition type, use the t command at the fdisk command prompt. The most common choice for a standard Linux file system partition is to set it to partition type 83, Linux native. Swap partitions should be set to partition type 82, Linux swap.


Command (m for help): t

Partition number (1-4): 1

Hex code (type L to list codes): 83

Command (m for help): t

Partition number (1-4): 2

Hex code (type L to list codes): 82

When you use the t command, you’re prompted for the partition number that you want to change. You’re then prompted for the hex code for the file system ID that you want to set the partition to. Typically, Linux file systems are set to type 83 for normal file systems, and type 82 for swap partitions. You can type l at this point to see a list of file systems, if you want.

Finishing Up

Now that you’ve created the partitions and labeled them, you should take one last look at the partition table before you exit just to make sure that everything is okay.


Command (m for help): p

Disk /dev/hda: 14 heads, 17 sectors, 1024 cylinders

Units = cylinders of 238 * 512 bytes

Device       Boot    Begin    Start     End     Blocks    Id  System

/dev/hda1               1      1       861      102400    83  Linux native

/dev/hda2               862    862     1023     19159     82  Linux swap

Command (m for help):

As you can see, the partitions are in the right place, they’re the right size, and the file system types are set correctly. The last thing that you need to do is use the w command to write the partition table to disk and exit:


Command (m for help):  w



#

None of the changes that you make during an fdisk session take effect until you write them to disk with the w command. You can always quit with the q command and not save any changes. This said, you should still always have a backup of any disk that you want to modify with fdisk.

After you make changes to a disk with fdisk, you should reboot the system just to make sure that Linux has the updated partition information in the kernel.

Using mkfs to Build a File System

After you create a file system partition with fdisk, you must build a file system on it before you can use it for storing data. This is done with the mkfs command. Think of building a parking lot. If you think of fdisk as physically building the parking lot, mkfs is the part of the process that paints the lines so that the drivers know where to park.

Just like fsck is a “front-end” program for checking different types of file systems, mkfs actually calls different programs to create the file system, depending on what file system type you want to create. The syntax of the mkfs command is this


mkfs  [-V] [-t fs-type] [fs-options] filesys [blocks]

where filesys is the device of the file system that you want to build, such as /dev/hda1.


CAUTION:  
The mkfs command also accepts the name of a mount point, such as /home, as the file system name. You should be extremely careful about using a mount point. If you run mkfs on a mounted “live” file system, you might very well corrupt all the data on that file system.

Table 14.10 lists the various command-line parameters that you can specify with mkfs.

Table 14.10 Command-Line Parameters for the mkfs Command

Option Description

-V Causes mkfs to produce verbose output, including all file system-specific commands that are executed. Specifying this option more than once inhibits execution of any file system-specific commands.
-t fs-type Specifies the type of file system to be built. If the file system type isn’t specified, mkfs tries to figure it out by searching for filesys in /etc/fstab and using the corresponding entry. If the type can’t be deduced, a MINIX file system is created.
fs-options Specifies file system–specific options that are to be passed to the actual file system–builder program. Although not guaranteed, the following options are supported by most file system builders:
-c Checks the device for bad blocks before building the file system
-l file-name Reads a list of the bad blocks on the disk from file-name
-v Tells the actual file system builder program to produce verbose output
filesys Specifies the device on which the file system resides. This parameter is required.
blocks Specifies the number of blocks to be used for the file system.

Although -t fs-type is an optional argument, you should get in the habit of specifying the file system type. Just like fsck, mkfs tries to figure out the type of the file system from the /etc/fstab file. If it can’t figure it out, it creates a MINIX file system by default. For a normal Linux file system, you probably want an ext2 partition instead.

Using Swap Files and Partitions

Swap space on your Linux system is used for virtual memory. A complete discussion of all the issues involved with virtual memory is beyond the scope of this book. Any good general computer operating system text book discusses the issue in detail.

Linux supports two types of swap space: swap partition and swap files. A swap partition is a physical disk partition with its file system ID set to type 82, Linux swap, and is dedicated for use as a swap area. A swap file is a large file on a normal file system that’s used for swap space.


Previous Table of Contents Next