How to Creating Filesystems

There are two types of filesystems you will need to learn how to make in order to get your Linux multi-partition system up and running are swap and ext2.

–Creating a swap filesystem–

The command for this is mkswap. You have to be root to run this, of course. If you get a “command not found” error, then you need to enter the full path, which is: /sbin/mkswap

The options for mkswapare (ripped from the man page):

-c     Check the device (if it is a block device) for bad blocks before creating the swap area.  If any are found, the count is printed.

-f     Force – go ahead even if the command is stupid. This allows the creation of a swap area larger than
the file or partition it resides on.   On  SPARC, force creation of the swap area.  Without this option, mkswapwill refuse to create a v0 swap on a device with a valid SPARC superblock, as that probably means one is going to erase the partition table.

-v0    Create an old-style swap area.

-v1    Create a new style swap area.

The “-c” option is probably a good idea, just to be safe. The “-f” option should probably be avoided, unless of course, you know what you are doing (but if you are reading this NHF, the chances that you do are not real high). The “-v0” and “-v1” options are not really necessary. Look at the man page if you want an explanation of the differences between the two. We will use a new style swap area.

So, if you don’t remember what partition you created your swap partition on, now is the time to go look it up in fdisk, because we will need it. Once you’ve got it, you should issue this command:

Eg. /dev/hdb13 would be:

It  takes a while and eventually it came back with this sort of “confirmation message” though:

And then another command-line prompt. And… that’s it! We’re done. Now we can turn it on right away using, or we can simply stick it in /etc/fstab and let it turn on the next time we reboot. But, since I tend to go at least a few days at a time without rebooting

Turning it on with swaponThe syntax is simple and straight-forward:

The only flags/options here that are available aren’t incredibly useful right now, so we’ll just stick with that. So, in case, issue:

Here’s what free says before the change

And here’s after the change:

The key number is the “total” in the “Swap:” row. See how much bigger it got? Now to put it in /etc/fstab so can always enjoy the swap goodness without having to turn it on each and every time.
–Creating an ext2 filesystem–

The command for this is mke2fs. Again, you have to be root to run this, and the same advice applies to those of you who get the “command not found” error message because mke2fs is in /sbin as well.

The options for mke2fs are far too numerous to list here, so just list the ones that we are going to use:

-c     Check the device for bad blocks before creating the file system, using a fast read-only test.

-v     Verbose execution.

Again, checking the device is never a bad idea, because it helps in case something goes wrong. The format is almost identical to the mkswapcommand:

This time, eg on /dev/hdb14 would be:

This step then spits out a bunch of garbage and took about a minute and a half  (a little over a minute of which was the bad block checking). Here’s what came out:

Running command: badblocks -b 4096 -s /dev/hdb14 263056
Checking for bad blocks (read-only test): done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

Your messages, of course, will vary, depending upon how big of a partition you created, and whether or not you put the “-c” flag on the mke2fs call.

And, basically, we’re done. To use this brand new partition with its fresh new filesystem, all you have to do is mount it. As an example, mount this at /mnt/temp.

I hope it has been a useful article