next up previous contents index
Next: Mounting and unmounting Up: Filesystems Previous: Which filesystem should be

Creating a filesystem

 

Filesystems are created, i.e., initialized, with the mkfs  command. There is actually a separate program for each filesystem type. mkfs  is just a front end that runs the appropriate program depending on the desired filesystem type. The type is selected with the -t fstype option.

The programs called by mkfs  have slightly different command line interfaces. The common and most important options are summarized below; see the manual pages for more.

-t fstype
Select the type of the filesystem.
-c
Search for bad blocks and initialize the bad block list accordingly.
-l filename
Read the initial bad block list from the file filename.

To create an ext2 filesystem on a floppy, one would give the following commands:
$ fdformat -n /dev/fd0H1440
Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Formatting ... done
$ badblocks /dev/fd0H1440 1440 > bad-blocks
$ mkfs -t ext2 -l bad-blocks /dev/fd0H1440
mke2fs 0.5a, 5-Apr-94 for EXT2 FS 0.5, 94/03/10
360 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1 block group
8192 blocks per group, 8192 fragments per group
360 inodes per group

Writing inode tables: done
Writing superblocks and filesystem accounting information: done
$
First, the floppy was formatted (the -n option prevents validation, i.e., bad block checking). Then bad blocks were searched with badblocks , with the output redirected to a file, bad-blocks. Finally, the filesystem was created, with the bad block list initialized by whatever badblocks  found.

The -c option could have been used with mkfs  instead of badblocks  and a separate file. The example below does that.

$ mkfs -t ext2 -c /dev/fd0H1440
mke2fs 0.5a, 5-Apr-94 for EXT2 FS 0.5, 94/03/10
360 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1 block group
8192 blocks per group, 8192 fragments per group
360 inodes per group

Checking for bad blocks (read-only test): done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
$
The -c is more convenient than a separate use of badblocks , but badblocks  is necessary for checking after the filesystem has been created.

The process to prepare filesystems on hard disks or partitions is the same as for floppies, except that the formatting isn't needed.


next up previous contents index
Next: Mounting and unmounting Up: Filesystems Previous: Which filesystem should be

Lars Wirzenius
Sun May 4 14:08:43 EEST 1997