BACK

Making a File System

This page is an update for the original file system page.

Fdisk

Run fdisk to make a new partition on a hard drive, in this example I'm making a partition of type 82 (Linux swap file).

  1. Start the fdisk program on the desired drive.
      suse:/ # fdisk /dev/hda
    
  2. Enter m for a list of commands at any time
       Command (m for help): m
       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)
    
  3. Enter n for a new partition, you will be prompted for extended or primary (You can only have 4 primary partitions on a drive, but you can create an extended partition and put logical partitions on it). In this case I created an extended partition 256MB in size (/dev/hda4) and in the extended partition I'll make a logical drive of 256MB for the swap partition. Notice that I'm not using the entire drive for the extended partition, the drive has 788 cylinders, and the extended partition ends on cylinder 347. If you want to add more partitions later, make the extended partition encompass the rest of the disk then only use what you want for the swap partition. ( I am updating this page two weeks later, the screen output on this page was from a test system running Debian 2.2, and in fact Debian is no longer installed on the computer; it was replaced with OpenBSD 2.7 several days after the page's creation. )
       Command (m for help): n
       Command action
         e   extended
         p   primary partition (1-4)
       e
       Partition number (1-4): 4
       First cylinder (315-788, default 315): 
       Using default value 315
       Last cylinder or +size or +sizeM or +sizeK (315-788, default 788): +256M
    
       Command (m for help): p
    
       Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders
       Units = cylinders of 16065 * 512 bytes
    
         Device Boot    Start       End    Blocks   Id  System
       /dev/hda1             1        61    489951   83  Linux
       /dev/hda2            62       122    489982+  83  Linux
       /dev/hda3           123       314   1542240   83  Linux
       /dev/hda4           315       347    265072+   5  Extended
    
  4. Now I'll create the logical drive, notice you aren't prompted for extended or primary as four primary partitions have already been created.
       Command (m for help): n
       First cylinder (315-347, default 315): 
       Using default value 315
       Last cylinder or +size or +sizeM or +sizeK (315-347, default 347): +256M
    
       Command (m for help): p
    
       Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders
       Units = cylinders of 16065 * 512 bytes
    
          Device Boot    Start       End    Blocks   Id  System
       /dev/hda1             1        61    489951   83  Linux
       /dev/hda2            62       122    489982+  83  Linux
       /dev/hda3           123       314   1542240   83  Linux
       /dev/hda4           315       347    265072+   5  Extended
       /dev/hda5           315       347    265041   83  Linux
    
  5. Now to change /dev/hda5's type to that of a swap partition. Enter t at the prompt and change the new partition's type to 82 for a swap, if you're making a regular partition it already should be of type 83 for an ext2 file system. If you're going to be making a swap partition record the partition number (/dev/hda5) and block count (265041).
       Command (m for help): t
       Partition number (1-5): 5
       Hex code (type L to list codes): 82
       Changed system type of partition 5 to 82 (Linux swap)
    
       Command (m for help): p
    
       Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders
       Units = cylinders of 16065 * 512 bytes
    
          Device Boot    Start       End    Blocks   Id  System
       /dev/hda1             1        61    489951   83  Linux
       /dev/hda2            62       122    489982+  83  Linux
       /dev/hda3           123       314   1542240   83  Linux
       /dev/hda4           315       347    265072+   5  Extended
       /dev/hda5           315       347    265041   82  Linux swap
    
  6. Enter w to write the partition table and exit fdisk.
       Command (m for help): w
       The partition table has been altered!
    
       Calling ioctl() to re-read partition table.
    
       WARNING: If you have created or modified any DOS 6.x
       partitions, please see the fdisk manual page for additional
       information.
       Syncing disks.
       root@debian:~# 
    
  7. Next run mke2fs to make an ext2 filesystem or skip to below for a swap partition.



mkfs

Used to build a Linux file system on a device.

Syntax:
# mkfs [ -V ] [ -t fstype ] [ fsoptions ] FILESYSTEM [ blocks ]
Example:
# mkfs -V  -t ext2  -c  /dev/hda3
Options
-V verbose
[ fsoptions ]
-c check for bad blocks
-l filename file with list of bad blocks
-v verbose



mke2fs

Used to create a Linux second extended file (ext2) system.

Syntax:
  mke2fs [options] DEVICE [block count]
Example:
   root@debian:/# mke2fs -c -v /dev/hdb1
   mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
   Filesystem label=
   OS type: Linux
   Block size=4096 (log=2)
   Fragment size=4096 (log=2)
   791840 inodes, 1582394 blocks
   79119 blocks (5.00%) reserved for the super user
   First data block=0
   49 block groups
   32768 blocks per group, 32768 fragments per group
   16160 inodes per group
   Superblock backups stored on blocks: 
           32768, 98304, 163840, 229376, 294912, 819200, 884736

   Running command: badblocks -b 4096 -s /dev/hdb1 1582394
   Checking for bad blocks (read-only test): done                        
   Writing inode tables: done                            
   Writing superblocks and filesystem accounting information: done
   root@debian:/# 
Options:
-c checks the device for bad blocks before creating file system
-f fragment size specifies the size of file fragments in bytes
-ibytes per inode creates a inode for every bytes per inode on the disk, min. = 1024, default = 4096
-l filename read the filename for a list of bad blocks
-m reserved blocks percentage specifies the percentage of blocks reserved for SuperUser, default= 5%
-o creator OS manually overrides default value
-q quiet execution
-v verbose
-F forces mk2fs to run even if the device isn't a block special device
-L volume label sets the filesystem's volume label
-M last mounted directory ets the last mounted directory for the file system
-r revision sets the file system revision for the file system
-R RAID options sets RAID related options for the file system
-S Write superblock and group description only

Mounting the new drive

  1. Edit /etc/fstab to add a new entry for the new drive
       #/etc/fstab: static file system information.
    
       # <file system> <mount point>   <type>  <options>               <dump>  <pass>
       /dev/hda1       /       ext2    defaults,errors=remount-ro      0       1
       /dev/hda5       none            swap    sw                      0       0
       proc            /proc           proc    defaults                0       0
       /dev/fd0        /floppy         auto    defaults,user,noauto    0       0
       /dev/cdrom      /cdrom          iso9660 defaults,ro,user,noauto 0       0
       /dev/hda2       /root           ext2    defaults                0       0
       /dev/hda3       /usr            ext2    defaults                0       0
       /dev/hdb1       /drive2         ext2    defaults                0       0
       suse:/bakup     /nfsbakup       nfs     ro,noauto               0       0
    
  2. Mount the new drive at /drive2
       root@debian:/# mount /drive2
    
  3. Verifying the drive is mounted, you can use df or mount.
       root@debian:/drive2# df -h
       Filesystem            Size  Used Avail Use% Mounted on
       /dev/hda1             463M  107M  332M  24% /
       /dev/hda2             463M  7.0k  439M   0% /root
       /dev/hda3             1.4G  497M  910M  35% /usr
       /dev/hdb1             5.9G   20k  5.6G   0% /drive2
    
    Using mount command.
       root@debian:/drive2# mount
       /dev/hda1 on / type ext2 (rw,errors=remount-ro,errors=remount-ro)
       proc on /proc type proc (rw)
       devpts on /dev/pts type devpts (rw,gid=5,mode=620)
       /dev/hda2 on /root type ext2 (rw)
       /dev/hda3 on /usr type ext2 (rw)
       /dev/hdb1 on /drive2 type ext2 (rw)
    




mkswap

  • Run mkswap to create the swap partition the -c is for bad block check, this is the swap partition I created with fdisk above.
       debian:~# mkswap -c /dev/hda5 265041 
    

swapon

  • Initialize the swap file with swapon.
       debian:~# swapon /dev/hda5
    

    Edit /etc/fstab to make sure the swap partition is properly referenced.

       #/etc/fstab: static file system information.
    
       # <file system> <mount point>   <type>  <options>               <dump>  <pass>
       /dev/hda1       /       ext2    defaults,errors=remount-ro      0       1
       /dev/hda5       none            swap    sw                      0       0
       proc            /proc           proc    defaults                0       0
       /dev/fd0        /floppy         auto    defaults,user,noauto    0       0
       /dev/cdrom      /cdrom          iso9660 defaults,ro,user,noauto 0       0
       /dev/hda2       /root           ext2    defaults                0       0       
       /dev/hda3       /usr            ext2    defaults                0       0       
       /dev/hdb1       /drive2         ext2    defaults                0       0
       suse:/bakup     /nfsbakup       nfs     ro,noauto               0       0       
    


BACK