SANGKRIT

Managing File Systems

An introduction to Linux file system is ‘here‘.
If you want to reformat the flash drive with a Linux native file system, rather than the FAT32 system. It involves two steps. First create a new partition layout if the existing one is not to our liking, and second create a new, empty file system on the drive.
Handling Partitions With fdisk: The fdisk program allows us to interact directly with disk-like devices (such as hard disk drives and flash drives) at a very low level. With this tool we can edit, delete, and create partitions on the device. To work with our flash drive, we must first unmount it (if needed) and then invoke the fdisk program as follows:

[linux@ubuntu ~]$ sudo umount /dev/sdb1
[linux2@ubuntu ~]$ sudo fdisk /dev/sdb

Note that we must specify the device in terms of the entire device, not by partition number. (use m for help)

  • 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
  • o extra functionality

Test and repair: Each time the system boots, it routinely checks the integrity of the file systems before mounting them. This is done by the fsck program (short for “file system check”). The last number in each fstab entry defines the order the devices are to be checked. The root file system is checked first, followed by the home and boot file systems. Devices with a zero as the last digit are not routinely checked.

In addition to checking the integrity of file systems, fsck can also repair corrupt file systems with varying degrees of success, depending on the amount of damage. On Unix like file systems, recovered portions of files are placed in the lost+found directory, located in the root of each file system.

To check our flash drive we could do the following:

[linux@ubuntu ~]$ sudo fsck /dev/sdb1
fsck 1.40.8 (19-Apr-2011)
e2fsck 1.40.8 (19-Apr-2011)
/dev/sdb1: clean, 11/3904 files, 1661/15608 blocks

Mostly, file system corruption is quite uncommon unless there is a hardware trouble, such as a failing disk drive. On most systems, file system corruption detected at boot time will cause the system to stop and direct you to run fsck before continuing.

“In Unix society, the word “fsck” is often utilized in spot of a popular word with which it shares three letters. This is especially appropriate, given that you will probably be uttering the aforementioned word if you find yourself in a situation where you are forced to run fsck.”

Leave a Reply