CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" >

8. Setting up an Ext2 filesystem

The procedures described here will give the entire flash memory device a single partition endowed with the ext2 filesystem. This will make the device more suitable for use between Linux machines. Don't do this if the device is supposed to operate between Linux and Windows machines.

Important

The device associated with /dev/sda will be re-formatted. Any data present on it will be destroyed. To make sure that the device you work with is the one intended, remove similar devices from the USB-bus before starting these procedures.

8.1. Partitioning

It is assumed that the flash memory is mapped to /dev/sda. In this section we treat the situation where the whole flash memory device will become devoted to a single ext2 partition. In the example procedure shown below, a 128MB flash memory was formatted for ext2. That is why figures like 131MB and 888 cylinders appear. The fdisk tool, which is used, simply reads that from the device.

All operations are done by root. The single partition will be created on /dev/sda (please note: not /dev/sda1 ) The procedure is described in a series of steps with comments. The standard prompt of fdisk is Command (m for help): and you can, at any stage enter m to see the available commands. If you do that the result would be


             Command   action 
                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 
                x      extra functionality (experts only) 
   

Your memory stick must be plugged in, but not mounted. Take care that write protect is off.

Here goes:


             # fdisk /dev/sda 
             Command (m for help):d {enter }
             Selected partition 1  
             Command (m for help):n {enter} 
             Command action  
                e  extended  
                p  primary partition (1-4)  
             p {enter}  
             Partition number (1-4):1 {enter} 
             First cylinder (1-888, default 1): {press enter} 
             Using default value 1  
             Last cylinder ... (1-888, default 888): {press enter} 
             Using default value 888  
   

Now is a good time to verify that all went well by printing out the partition details and table.


             Command (m for help): p 
             Disk /dev/sda: 131 MB, 131072000 bytes  
             9 heads, 32 sectors/track, 888 cylinders  
             Units = cylinders of 288 * 512 = 147456 bytes 

             Device     Boot Start End Blocks Id System 
	  
             /dev/sda1         1   888 127856 83 Linux 
   

Make sure that the partition is not set up as bootable. There should not be an asterisk under the heading "Boot" in the partition table. Furthermore, the headings "Id" and "System" should be as they are in the printout shown above. That indicates that you can format the device in ext2 (next section). These are the defaults. If they are not, they can be changed by


             Command (m for help): a [toggle a bootable flag] 
             Command (m for help): t [change a partition's system id] 
   

If (or when) the partition table is correct, you can conclude the procedure with


             Command (m for help): w [write table to disk and exit] 
    

That's it!

8.2. Making an ext2 device

Having completed the partition part, we go straight on to "formatting" the device in ext2. For this we use the tool mke2fs. This is straightforward.


             # mke2fs /dev/sda1 
   

You might like to watch the led on your memory stick flicker while this is happening. When it stops, the job is done.

8.3. Tests -- ext2

To see if you were successful, essentially repeat the procedures described in Section 7.3 and Section 7.4 with two exceptions of detail. In the first place the mount command should be


             # mount -t ext2 /dev/sda1 /mnt/memstick 
   

The second exception is that the permissions on your favourite text file should not change anymore.