Certification Objective 3.04: Partitioning Utilities

 < Day Day Up > 



It's best to create partitions using Disk Druid during the installation process. This can save you grief as an administrator-and especially during the Red Hat exams. However, mistakes are made. You might forget to create a critical partition during the Installation and Configuration exam. You might need to create a larger /home directory partition for your users. For this purpose, the standard is still the fdisk utility, which I'll describe shortly.

Before you use fdisk to create or revise partitions, you should check your free space and the partitions that are currently mounted. You can do this with the df and mount commands. The following example illustrates how the df command displays the total, used, and available free space on all currently mounted filesystems.

Note the numbers under the 1k-blocks column. In this case, they add up to about 3GB of allocated space. (Don't include the space associated with /dev/hdc, which refers to a CD drive.) If your hard drive is larger, you may have unallocated space that you can use for another partition.

[root@Enterprise root]# df Filesystem           1k-blocks      Used Available Use% Mounted on /dev/hda8               932833    502478    382162  57% / /dev/hda7                23300      2588     19509  12% /boot /dev/hda1              1052064    914784    137280  87% /dosC /dev/hda6              1052064    111648    940416  11% /home none                     62828         0     62828 100% /dev/shm /dev/hdc                556054    556054         0 100% /mnt/cdrom [root@Enterprise root]#

The second command, mount, includes the filesystem type. In this case, we see the partition represented by device /dev/hda1 mounted with the VFAT file type on the /DosC directory. It provides direct access to the C: drive of the Windows operating system. I've set up the data shown from the mount command in columns for clarity; what you actually see in the RHEL 3 command line is less organized.

[root@Enterprise root]# mount /dev/hda8 on /          type ext3 (rw) none      on /proc      type proc (rw) /dev/hda7 on /boot      type ext3 (rw) /dev/hda1 on /dosC      type vfat (rw) /dev/hda6 on /home      type vfat (rw) none      on /dev/pts   type devpts (rw,mode=0620) /dev/hdb  on /mnt/cdrom type iso9660 (ro) [root@Enterprise root]# 
On The Job 

As of this writing, RHEL 3 can reliably recognize NTFS partitions only in read-only mode. While support for write mode is available through the Linux kernel, it is noted as 'dangerous' per the kernel help files.

One of the benefits is that you can move and copy files between the Linux and DOS partitions using standard Linux commands. You cannot, however, run many Microsoft Windows applications within Linux unless you run a DOS or Windows Emulation package such as WINE (www.winehq.org) or CrossOver Office (www.codeweavers.com).

The fdisk Utility

The fdisk utility is universally available and should be one of the first tools you get acquainted with. There are many commands, even an expert mode, but you only need to know a few, as discussed here.

Though you can modify the physical disk partition layout using many programs, we will be discussing the Linux implementation of fdisk. FDISK.EXE from DOS has the same name and is also used for creating partitions, but it doesn't incorporate any Linux-compatible features. It also includes a different interface.

Using fdisk: Starting, Getting Help, and Quitting

The following screen output lists commands that show how to start the fdisk program, how to get help, and how to quit the program. The /dev/hda drive is associated with the first IDE drive on a regular PC. Your computer may have a different hard drive; you can check the output from the df and mount commands for clues.

As you can see, once you start fdisk, it opens its own command line prompt.

# fdisk /dev/hda 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): q

Using fdisk: In a Nutshell

In the fdisk command line prompt, start with the print the partition table command (p). This allows you to review the current entries in the partition table. Assuming you have free space, you then create a new (n) partition, either primary (p) or logical (l). If it doesn't already exist, you can also create an extended partition (e) to contain your logical partitions. Remember that there are four primary partitions, which correspond to numbers 1 through 4. One of the primary partitions can be redesignated as an extended partition. The remaining partitions are logical partitions, numbered between 5 and above. The Linux fdisk utility won't allow you to create more than 16 partitions on the drive.

When you assign space to a partition, you're assigning a block of cylinders on that hard disk. If you have free space, the fdisk default starts the new partition at the first available cylinder. The actual size of the partition depends on disk geometry; do not worry about exact size here.

Using fdisk: Deleting Partitions

In the following example, you will remove the only partition. The sample output screen first starts fdisk. Then you print (p) the current partition table, delete (d) the partition by number (1 in this case), write (w) the changes to the disk, and quit (q) from the program. Needless to say, do not perform this action on any partition where you need the data.

# fdisk /dev/hdb Command (m for help): p Disk /dev/hdb: 255 heads, 63 sectors, 525 cylinders Units = cylinders of 16065 * 512 bytes Device    Boot    Start       End    Blocks   Id  System /dev/hdb1   *         1       525   4217031    6  FAT16 Command (m for help): d Partition number (1-1): 1 

This is the last chance to change your mind before deleting the current partition. If you want to quit without saving changes, exit from fdisk with the q command. If you're pleased with the changes that you've made and want to make them permanent, proceed with the w command:

Command (m for help): w

You did it! Now you have an empty hard disk or hard disk area where you can create the partitions you need.

Using fdisk: Creating Partitions

The following screen output sample shows the steps used to create (n) the first (/boot) partition, make it bootable (a), and then finally write (w) the partition information to the disk. (Note: Although you may ask for a 100MB partition, the geometry of the disk may not allow that precise size, as shown in the example.)

# fdisk /dev/hdb Command (m for help): n Command action    e   extended    p   primary partition (1-4) p Partition number (1-4): First cylinder (1-256, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (2-256,def 256): +100M Command (m for help): a Partition number (1-4): 1 Command (m for help): p Disk /dev/hdb: 255 heads, 63 sectors, 256 cylinders Units = cylinders of 16065 * 512 bytes    Device Boot    Start       End    Blocks   Id  System /dev/hdb1   *         1        12     98163   83  Linux Command (m for help): 

Repeat the previous commands as appropriate to create any other partitions that you might need. I illustrate one possible group of partitions here:

Command (m for help): p Disk /dev/hdb: 255 heads, 63 sectors, 256 cylinders Units = cylinders of 16065 * 512 bytes    Device Boot    Start       End    Blocks   Id  System /dev/hdb1             1         2     16044   83  Linux /dev/hdb2             3        18     64176   82  swap /dev/hdb3            19       169   1203300   83  Linux /dev/hdb4           170       250    649782    5  Extended /dev/hdb5           170       201    248682   83  Linux /dev/hdb6           202       257    449232   83  Linux Command (m for help): w
On The Job 

The number of blocks that you see may vary slightly depending on the size of your hard disk, the number of heads, sectors, and cylinders on that disk, as well as the version of fdisk that you're using.

Using fdisk: A New PC with No Partitions

After installing Linux on a new PC, you'll want to use fdisk to configure additional physical disks attached to the system. For example, if it's the first disk attached to the secondary IDE controller, run the fdisk /dev/hdc command.

Remember the limitations on partitions. If you need more than four partitions on the new physical disk, configure type Primary for the first three partitions, and then Extended for the rest of the disk as partition 4. You can then create logical partitions 5-16 within the extended partition.

Using fdisk: Creating a Swap Partition

You need to create a partition before you can reassign it as a swap partition. At the fdisk prompt, run the L command. You'll see a large number of file types, listed as hex codes. When you create a partition, fdisk creates a Linux Native type partition by default. As you can see from the output of the L command, the associated hex code is (83).

It's easy to reassign a partition as a swap partition. Run the p command. Remember the number of the partition you want to change. Make sure that partition doesn't have data that you want to save.

Now run the t command. Type in the number associated with the partition that you want to change. Type in the hex code for the type you want, in this case, 82 for a Linux swap partition. For example, I could run the following sequence of commands to set up a new swap partition on the second IDE hard drive. The commands that I type are in bold. The details of what you see depend on the partitions that you may have created. It'll be a 1GB swap space on the first primary partition (/dev/hdb1).

# fdisk /dev/hdb Command (m for help): n Command action       e  extended      p  primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-10402, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-10402, default 10402): +1000M Command (m for help): p Disk /dev/hdb: 5368 MB, 5368709120 bytes 16 heads, 63 sectors/track, 10402 cylinders Units = cylinders of 1008 * 512 = 516096 bytes    Device Boot    Start       End    Blocks    Id  System /dev/hdb1             1      1939    977224+   83  Linux Command (m for help): t Selected partition 1 Hex code (type L to list codes): 82 Changed system type of partition 1 to 82 (Linux swap) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table.  Syncing disks. # 

The fdisk utility doesn't actually write the changes to your hard disk until you run the write (w) command. You have a chance to cancel your changes with the quit (q) command.



 < Day Day Up > 



RCHE Red Hat Certified Engineer Linux Study Guide[c] Exam (Rh302)
RCHE Red Hat Certified Engineer Linux Study Guide[c] Exam (Rh302)
ISBN: 71765654
EAN: N/A
Year: 2003
Pages: 194

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