< Day Day Up > |
To create a file system on a disk that has never had a partition table on it or to change the partition table (called repartitioning the disk), you must first create the new partition table. In this section, you begin by learning about the basic structure and workings of the disk as a storage device. This information is fundamental to your understanding of the file system creation process. You then learn to create a partition table using the fdisk and GNUparted commands. As with all similar Linux commands, each has its own strengths and weaknesses and none is a perfect choice for all situations. In the end, the partition table you create will be the same no matter which command you use. You then learn to create the file system, using commands appropriate for the type of file system you want to create. NOTE The Microsoft version of fdisk creates both a partition table and the bootloader. In Linux, fdisk only creates the partition table. The bootloader is created later by LILO, GRUB, or another bootloader; no bootloader is necessary to create a file system and store data on a disk, just a partition table. In fact, IDE disks physically installed as something other than /dev/hda (such as /dev/hdc, the secondary master drive) will not have a bootloader written to them; the space where the bootloader code normally resides will likely be blank. For SCSI disks, the drive designated in the BIOS as the bootable drive will have the bootloader written to it. The Disk As a Storage DeviceBecause data storage devices are central to the file system, it is important to understand the workings of the most common data storage device the hard disk drive. Although they work with a different medium, the basic storage functions of floppy disks and removable disk drives are similar to those of the hard disk. Mechanically, the hard drive is a metal box that encloses disks, also known as platters, which have a magnetic coating on each side. Multiple disks are typically connected to the same spindle and rotated by a motor. The read and write heads for each side of the disk are moved by a second motor to position them over the area of the disk where the data you are looking for is stored. Each platter is organized into cylinders (the default size is 512 bytes) and sectors, and each platter has a head. Each drive has some electronics on a controller card that, along with the disk controller card on the motherboard of the computer, are capable of placing the heads at the correct space to retrieve the data. The three components, cylinders, heads, and sectors (CHS), are referred to as the drive geometry and are used to identify specific locations on the drive. The CHS information for the drive is detected by the system BIOS and passed on to the operating system. The first sector of the disk is called the MBR, or Master Boot Record. It is the most important sector on the disk because it contains the bootloader code and the partition table (the table containing pointers to beginning and end of the logical partitions on the disk). The BIOS gets the system's hardware ready, and then executes the bootloader code. The bootloader code and the bootloader program load the kernel and turn over control of the system to the kernel. Then, Linux is on its way to providing us with one of the best operating system experiences in the world. The MBR sector is 512 bytes long; the first 446 bytes contain the bootloader code. The next 64 bytes contain the partition table, and the final 2 bytes contain a special code (the hexadecimal values of 55 and AA, respectively) that identifies that sector as the MBR. More details about the MBR can be found Chapter 16, "Backing Up, Restoring, and Recovery." Creating the Partition TableFedora Core provides several tools to create, examine, and modify the partition table. Because not all the tools we review are likely to be installed on your system (or other system you might be working on for now), this chapter describes making a partition table using some command-line and graphical tools that Fedora Core Linux provides. The partition table only has enough room for four partitions. When the format was first created, it must have been assumed that four would be plenty. Complex, modern systems with very large hard drives make multiple partitions desirable for any number of unique reasons. To get around this problem, one of the four partitions typically, partition number four can be used as an extended partition. In other words, in the partition table, it looks like a big partition taking up the rest of the disk. Actually, it is a link to a table that contains the offsets to as many as 63 partitions for IDE disks and 15 for SCSI disks. One extended partition is chained to the next one in this manner. CAUTION Fedora and Red Hat have modified their supplied version of fdisk to limit the number of IDE partitions to 15 to match the limit for SCSI disks. That's a problem if you already have more than 15 IDE partitions as fdisk will simply delete those partitions without warning if you use it! If you have less than 15 partitions, there will be no problem. If this causes a problem for you, compile your own fdisk from pristine sources and file a bug report with Fedora/Red Hat. NOTE Zip disks are typically delivered with a single partition numbered 4. This has some arcane relevance to Apple computer users, but is of no importance to Linux users who are free to use any valid number they choose. The fdisk CommandThe Linux fdisk command edits the partition table. You must be the superuser (root) before you can run fdisk (also said in Linux shorthand as "run fdisk as root"). Only hard drives (IDE and SCSI) can be accessed with fdisk, and you must use the device name as an argument. USB hard drives are accessed under SCSI emulation and are treated just as if they were SCSI devices. For example, to open fdisk and use it on the first IDE hard drive on the system, you would type this # fdisk /dev/hda and you would see something like this: # fdisk /dev/hda The number of cylinders for this disk is set to 4982. There is nothing wrong with that, but this is larger than 1024, and in certain setups could cause problems with software that runs at boot time: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSes (e.g., DOS FDISK or the OS/2 FDISK) Pressing the m key displays the help screen as follows: 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) Pressing the p key will display the volume's partition information as follows (note that your drive information will be different): Command (m for help): p Disk /dev/hda: 255 heads, 63 sectors, 4982 cylinders Units = cylinders of 16065 * 512 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 383 3076416 b Win95 FAT32 /dev/hda2 384 387 32130 83 Linux /dev/hda3 388 1025 5124735 83 Linux /dev/hda4 1026 4982 31784602+ 5 Extended /dev/hda5 1026 1042 136521 82 Linux swap /dev/hda6 1043 1552 4096543+ 83 Linux /dev/hda7 1553 4102 20482843+ 83 Linux /dev/hda8 4103 4500 3196903+ 83 Linux /dev/hda9 4501 4982 3871633+ 83 Linux Older versions of fdisk would default to /dev/hda. The author of fdisk decided that wasn't a good thing, so now you must always type the device name. TIP The fdisk command is only dangerous to explore if you write the changes to the partition table. Because you are specifically asked whether you want to do this, poke around to satisfy your curiosity and avoid pressing the w key when you're done; just use q to quit. Armed with this knowledge, do not feel too shy if you're curious about the partition table. But if you really do not want to take a chance on breaking anything, play it safe and use the -l (that's the letter L, not the numeral 1) as in # fdisk -l /dev/had fdisk happily prints the contents of the partition table to the screen (often referred to as stdout, or standard output) and exits without placing you in the edit mode. It is always a good idea to keep a hard copy of your edited partition table. You can redirect the output of fdisk -l to a file # fdisk -l device > mypartitiontable.txt or send it to the printer with # fdisk -l device | kprinter In the first example, a redirector symbol (>) is used to redirect the listing from stdout to a file. In the second example, we used a pipe (|) to send the output directly to the printer (assuming that you have one connected). Now that you are running fdisk as root, you can create a partition table. We will assume that you have installed a brand-new drive as /dev/hdb (the Primary Slave IDE device) and want to partition the entire drive as a single partition. Launch fdisk with # fdisk /dev/hdb Use the n key to create a new partition, and fdisk will prompt you for the beginning cylinder: First Cylinder (1-9729, default 1) : Press the Enter key to accept the default of 1. Now, fdisk prompts Using the default value of 1 Last Cylinder or +size or +sixeM or +sizeK (2-9729, default 9729) : Here, you can give the size in cylinders, the size in kilobytes, the size in megabytes, or accept the default value (which is the last cylinder on the disk). Press the Enter key to accept the default. Using default value of 9729 And we are back at the fdisk prompt: Command (m for help) : Enter the w command to write the new partition table to the disk, and fdisk will exit, returning you to the command prompt. The parted CommandIn the past, Red Hat used a partition editor during its installation process named Disk Druid; the underlying code for Disk Druid has been replaced by GNUparted (also known simply as parted, the name of the command itself). GNUparted is the GNU partition editor and a very powerful utility. You use parted to create, delete, move, resize, and copy ext2, ext3, and FAT32 partitions. Although GNUparted displays a GUI interface during the installation process, it really is a console utility. GNUparted can be used from the command line. Creating the File System on the Partitioned DiskAfter you have partitioned the disk for a specific file system, you can create the file system on it. In the DOS world, this two-part process is described by DOS as low-level formatting (creating the partitions and partition table) and formatting (creating the file system). In the Unix world, the latter is known as creating a file system. In this section, you learn how to create a file system in Linux. An unformatted disk storage device (a floppy disk, hard disk drive, or removable media) typically arrives to you with a low-level format, which has been done with a tool such as fdisk or superformat. Although the disk might have a boot block and partition information, it typically lacks the file structure needed for a file system. NOTE If you are preparing to create a file system on any device other than a floppy disk, examine it with fdisk or another utility of your choice and modify the partition table accordingly (following the instructions you saw in the preceding sections of this chapter). To create the file system structure, you need to do what is sometimes referred to as a high-level format. For FAT file systems, this is accomplished by the format command. In Linux, you use the mke2fs -j command to create an ext3 file system. NOTE If you are creating a Reiser file system, use the mkreiserfs command. To create a DOS file system, use the mkdosfs command. Other commands for other file systems include mkfs.bfs The SCO file system mkfs.ext2 The ext2 file system mkfs.minix The minix file system mkfs.msdos The MS-DOS file system mkfs.vfat The FAT32 file system Using mke2fs to Create the File SystemThe mke2fs command is used to create both the ext2 and the ext3 file systems. At its simplest, the command is used as # mke2fs psrtition such as # mke2fs /dev/hdc4 Here are some of the most useful options for mke2fs:
As you can see, mke2fs offers a few options to make more space available for the regular users. But that extra space always comes from the superuser's space for recovering damaged files. The default settings accommodate most users, so think carefully before using one of these options. Hard disks are getting less expensive all the time, so adding another might be a better solution. Using mkfs.ext3To make a new ext3 file system, you use the mke2fs command with the -j or -J option, or call the command as mkfs.ext3. Use the tune2fs command on an existing ext2 file system to add journaling. You learn how to convert an existing ext2 file system into an ext3 file system later in this chapter. Here, x represents a partition: # tune2fs /dev/hdx -j Some arguments you can use with this command include
NOTE The latter two options in the arguments list are mutually exclusive. To select the ext3 journaling mode, you must add the appropriate entry in /etc/fstab. Because the ext3 file system is a new version of the ext2 file system with journaling added, it supports the same options as ext2, as well as the following additions:
Using mkreiserfsThe Reiser file system journals file data and handles smaller files more efficiently than the ext3 file system. Although it is suitable for use as the root file system, Fedora Core does not officially support its use in that way. You use the mkreiserfs command to create a Reiser file system. The default values for mkreiserfs work well. To create a Reiser file system, use # mkreiserfs device Creating a DOS File System with mkdosfsIt is possible to create DOS file systems without owning any Microsoft software using the mkdosfs command. To create a DOS file system in an image file, use the -C option. The -n option allows you to specify a volume label. To create a 1.4M DOS file system as an image file with the label dosfloppy, the sector size (-S) should be 512 and the block count should be 1440. Use the -v option to provide verbose output so that we can observe what happens. # mkdosfs -n dosfloppy -v -C floppy.img -S 512 1440 TIP To create a DOS file system on a floppy disk drive, use # fdformat device. A complete review of all the argument options and syntax for creating a DOS file system can be found in man mkdosfs. The new file system must be mounted (as described in the following section) and then formatted with the mformat command. |
< Day Day Up > |