May 032012
 Posted by on May 3, 2012 at 6:15 pm Linux, Operating Systems Tagged with: , , , ,  Add comments
The most common tool for managing your disks and file systems is the fdisk utility.This utility allows you to partition your drives and assign file systems to them.
To use fdisk on your hard drives, specify which hard drive you are using with the following conventions:
– The first ATA/IDE hard drive is called hda; the second is called hdb, etc.
– The first SCSI drive is called sda; the second is called sdb, etc.
With these hard drives, each partition is also numbered, so the first partition of the first IDE drive is hda1.
To start fdisk on the first ATA/IDE drive, use the following command:
fdisk /dev/hda
To view a list of commands that you can use from the fdisk prompt, type ?(question mark). A display output similar to the following appears:
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatiblity flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
p print the partition table
q quit without saving changes
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)
In addition, in expert mode (see the “x” command in the preceding example), you can use these advanced commands, but I recommend that you don’t use these commands unless you know what you are doing. For most users, the following basic commands will suffice:
Command action
b move beginning of data in a partition
c change number of cylinders
d print the raw data in the partition table
e list extended partitions
h change number of heads
m print this menu
p print the partition table
q quit without saving changes
r return to main menu
s change number of sectors
v verify the partition table
w write table to disk and exit

I recommend that you begin with the “p” command to print a list of your current partition table. The following is a sample partition table from a Linux system:
Disk Output

In the preceding example, you can see that /dev/hda1 is the boot drive and that it contains the main Linux system. The system ID is the type of Linux file system, which, in this case, is the ext2 filesystem—the default for Linux.

The Linux swap file is ID 82, and is installed on the /dev/hda5 partition. The following is a list of other file system numbers:

list of other file system numbers


The most important ID numbers to remember are the Linux specific designations, such as 82 for the Linux Swap file, and 83 for a typical Linux partition.

As the preceding examples demonstrate, you can see and format partitions for all types of systems. If you have a dual-boot system with Microsoft Windows, use the DOS fat file system.

You can use the fdisk tool to add and delete partitions. You must set the size of the partition by number of blocks. You must also set the file system with the file system ID number. After you finish, hit the “w” command to write the partition table to disk, and then exit the utility.

After you have set up your partitions, you won’t be able to use them until you actually format the partitions with a valid file system. For Linux, the default file system is the ext2 system. If you have added another hard drive to your system, such as /dev/hdb, you will want to create another partition for Linux to use on that drive.

Using the fdisk tool, add a partition called /dev/hdb1. If you want, use all the available blocks to allocate the entire drive to one partition. After you finish using fdisk, format the partition with the ext2 file system.

For this, you need to use the mkfs command:

mkfs -t ext2 /dev/hdb2

This command tells the mkfs command to invoke the mke2fs utility to format the partition with the ext2 file system.
To mount the file system for use, use the mount command to mount your new partition:

mount /dev/hdb1 /home2

The file system used by Linux is the ext2 file system.

Repairing Partitions

File systems can be very complex, and with a great amount of disk activity and read and writes, the occasional error is bound to happen. The utility that you use to repair these problems and inconsistencies is fsck, which is short for “File System Check.” (This is similar in function to the Windows SCANDISK utility) The fsck utility scans all disks and partitions, and if possible, repairs them when necessary. This utility runs automatically at boot time if the system has shut down abnormally.

If your hard drives were unmounted improperly, they may contain errors and inconsistencies, which fsck will fix before remounting the file system. This utility can never be run on a mounted file system. You must unmount any file system before checking it with fsck. This is important because fsck won’t work properly if the file system is still in use, and the data it keeps on the drive is still changing.

To check your file system for errors, first unmount the drive:

umount /dev/hdb2

Then, you can run fsck manually on the partition:

fsck /dev/hdb2

The system asks you if you want fsck to fix any errors. Always let fsck fix the errors; otherwise, the file system will likely become more inconsistent through use. You can use the -a option on fsck to have it automatically fix errors without manual intervention.

Using fsck on a large file system may take quite a long time to complete. If you are running fsck on a large file system manually, try to do it during off-hours so it won’t affect your users.

The fsck utility will run automatically if the system is shutdown abnormally. It will check the file systems for any errors caused by the abrupt shutdown.

© Incase of any copyright infringements please check copyrights page for faster resolutions.

Leave a Reply

Show Buttons
Hide Buttons