Linux file system structure management
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)
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
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:
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.
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:
Then, you can run fsck manually on the partition:
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.
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.