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:

/sbin/mkswap -c -v1

Eg. /dev/hdb13 would be:

/sbin/mkswap -c -v1 /dev/hdb13

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

Setting up swapspace version 1, size = 271396864 bytes

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:

/sbin/swapon 

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:

/sbin/swapon /dev/hdb13

Here’s what free says before the change

[root@abc]# free 
            total       used       free 
Mem:        255644     252756       2888 
-/+ buffers/cache:     109248     146396 
Swap:       136544       1244     135300

And here’s after the change:

[root@abc]# free 
            total       used       free 
Mem:        255644     253792       1852 
-/+ buffers/cache:     110284     145360 
Swap:       401576       1244     400332

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:

/sbin/mke2fs -c -v

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

/sbin/mke2fs -c -v /dev/hdb14

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:

[root@abc]# /sbin/mke2fs -c -v /dev/hdb14 
      mke2fs 1.15, 18-Jul-1999 for EXT2 FS 0.5b, 95/08/09 
      Filesystem label= 
      OS type: Linux 
      Block size=4096 (log=2) 
      Fragment size=4096 (log=2) 
      131616 inodes, 263056 blocks 
      13152 blocks (5.00%) reserved for the super user 
      First data block=0 
      9 block groups 
      32768 blocks per group, 32768 fragments per group 
      14624 inodes per group 
      Superblock backups stored on blocks: 32768, 98304, 163840, 229376,

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.

    [root@abc]# mkdir /mnt/temp 
    [root@abc]# mount /dev/hdb14 /mnt/temp 
    [root@abc]# cp ~/*rpm /mnt/temp/

I hope it has been a useful article