justlinux.com
Mon, 23-Nov-2009 09:23:04 GMT
internet.com
Forum: Registered Users: 73495, Online: 209
nhfs Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home Home

Help File Library: Creating Filesystems


Written By: Danny "Strike" DiPaolo

The 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, like the ones we just made with fdisk.

--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 mkswap are (ripped from 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 mkswap will refuse to create a v0 swap on  a
       device with a valid SPARC superblock, as that prob
       ably 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 

So, mine on /dev/hdb13 would be:


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

When I enter this in, it takes a while (took me about 40 seconds on a decently fast hard drive and overall decently fast system). 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 swapon, 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 (and never because of a crash, mind you), let's do both.

Turning it on with swapon
The 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 my case, I issue:


/sbin/swapon /dev/hdb13

And when I do so, it seems like nothing happened. Let's examine what the difference is though. Here's what free says before the change (note, I'm cutting out the last three columns for space considerations):


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

And here's after the change:


[root@half-life ddipaolo]# 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? All right! Now to put it in /etc/fstab so we can always enjoy the swap goodness without having to turn it on each and every time.

Adding it to /etc/fstab
If you've messed with /etc/fstab before, this step ought to be easy. Hey, even if you HAVEN'T messed with /etc/fstab before this step ought to be easy, because it's pretty much copy-and-paste.

Sometimes I forget the format of /etc/fstab, but thankfully, I have enough partitions in there that I can just look at it and figure it out. Also, I have a swap partition in there I can use as a guide to adding this new one in there. The line with my first swap partition says:


/dev/hdb2       swap         swap    defaults  0 0

So, you know what I do? Add another copy of that line with exactly the same stuff, except changing the first part to the partition on which we just created our filesystem. So, I add this:


/dev/hdb13      swap         swap    defaults  0 0

Told you it was easy...

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 I'll 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, and I always like verbose output just because it helps in case something goes wrong. The format is almost identical to the mkswap command:


/sbin/mke2fs -c -v 

This time, mine 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@half-life ddipaolo]# /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. I see no reason why you wouldn't though.

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, I'll mount this at /mnt/temp and copy some files to it just to show you.


[root@half-life ddipaolo]# mkdir /mnt/temp
[root@half-life ddipaolo]# mount /dev/hdb14 /mnt/temp
[root@half-life ddipaolo]# cp ~/*rpm /mnt/temp/
[root@half-life ddipaolo]# ls /mnt/temp
Eterm-backgrounds-0.9-2.i386.rpm    licq-0.81-1.i386.rpm
NVIDIA_GLX-0.9-2.i386.rpm           licq-data-1.6-1.noarch.rpm
NVIDIA_kernel-0.9-2.i386.rpm        lost+found
ORBit-0.5.0-1.i386.rpm              lpr-0.48-1.i386.rpm
ORBit-devel-0.5.0-1.i386.rpm        mc-4.5.40-2.i386.rpm
SDL-1.1.2-1.i386.rpm                mdkrpm
audiofile-0.1.9-1.i386.rpm          mtv-1.1.1.0-1.i386.rpm
enlightenment-0.16.4-1.i386.rpm     ncurses-5.0-12.i386.rpm
esound-0.2.15-1.i386.rpm            nmap-2.53-1.i386.rpm
esound-devel-0.2.15-1.i386.rpm      nmap-frontend-0.2.53-1.i386.rpm
fnlib-0.5-1.i386.rpm                oregano-0.16.1-1.i386.rpm
fnlib-devel-0.5-1.i386.rpm          plugger-3.2-1.i386.rpm
gaim-0.9.15-1.i386.rpm              popt-1.5-6x.i386.rpm
gaim-0.9.18-1.i386.rpm              qt-2.1.0-4.beta1.i386.rpm
gkrellm-0.9.8-1.i386.rpm            rp7_linux20_libc6.i386.b2.rpm
gkrellm-0.9.8-1mdk.i686.rpm         rpm-3.0.4-6x.i386.rpm
gmc-4.5.40-2.i386.rpm               samba-2.0.7-20000425.i386.rpm
gnapster-1.3.9-1.i386.rpm           spice-rhcn-3f5-3.i386.rpm
gnome-libs-1.0.53-1.i386.rpm        vim-athena-rhcn-5.0-1.i386.rpm
gnome-libs-devel-1.0.53-1.i386.rpm  wine-20000430-7.i386.rpm
gtkicq-0.62-1.i386.rpm              xmms-1.0.1-1.i386.rpm
imlib-1.9.8-1.i386.rpm              xmms-devel-1.0.1-1.i386.rpm
imlib-cfgeditor-1.9.8-1.i386.rpm    xmms-esd-1.0.1-1.i386.rpm
imlib-devel-1.9.8-1.i386.rpm        xmms-gnome-1.0.1-1.i386.rpm

Wow, I have far too many RPMs in my home directory. :) Guess that means it's time for me to go clean that out, because we are DONE!

Send me feedback - Danny "Strike" DiPaolo


internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
internet.commerce
Be a Commerce Partner











internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs