Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts

Formatting a second drive on RHEL Linux

Posted by plattapuss on December 18th, 2006

Here is a quick little how-to for formatting a second drive on RHEL4 Linux. A great deal of credit goes to http://www.eth0.us/mount on this.

This how-to is based on my machine which has two 80GB scsi drives which we can see by doing the following:

CODE:
  1. #cat /proc/scsi/scsi
  2. Attached devices:
  3. Host: scsi0 Channel: 00 Id: 00 Lun: 00
  4.   Vendor: FUJITSU  Model: MAW3073NP        Rev: 5803
  5.   Type:   Direct-Access                    ANSI SCSI revision: 03
  6. Host: scsi0 Channel: 00 Id: 01 Lun: 00
  7.   Vendor: SEAGATE  Model: ST373207LW       Rev: D702
  8.   Type:   Direct-Access                    ANSI SCSI revision: 03

WARNING: Be very careful as the smallest mistake can lead to a complete loss of ALL information on your machine!

Now let's get going!

The first thing we will do is run fdisk which is used to format a disk. I first run it with the -l (elle) flag to see what partitions my drives currently have:

CODE:
  1. [root@server var]# fdisk -l
  2.  
  3. Disk /dev/sda: 73.4 GB, 73407820800 bytes
  4. 255 heads, 63 sectors/track, 8924 cylinders
  5. Units = cylinders of 16065 * 512 = 8225280 bytes
  6.  
  7.    Device Boot      Start         End      Blocks   Id  System
  8. /dev/sda1   *           1          13      104391   83  Linux
  9. /dev/sda2              14         268     204828782  Linux swap
  10. /dev/sda3             269         399     105225783  Linux
  11. /dev/sda4             400        8924    68477062+   5  Extended
  12. /dev/sda5             400        8924    68477031   83  Linux
  13.  
  14. Disk /dev/sdb: 73.4 GB, 73407820800 bytes
  15. 255 heads, 63 sectors/track, 8924 cylinders
  16. Units = cylinders of 16065 * 512 = 8225280 bytes
  17.  
  18.    Device Boot      Start         End      Blocks   Id  System
  19. /dev/sdb1   *           1          13      104391   83  Linux
  20. /dev/sdb2              14         268     204828782  Linux swap
  21. /dev/sdb3             269         399     105225783  Linux
  22. /dev/sdb4             400        8924    68477062+   5  Extended
  23. /dev/sdb5             400        8924    68477031   83  Linux

As you can see above I can see the two SCSI drives and they both have partitions. This is because at some point in the past I ran dd to duplicate my primary disk over to my secondary disk. I want to now get rid of all those partitions on drive B and format drive B with one partition, which I will use to store my backups on.

The following is what did to remove the old paritions and create a new one:

CODE:
  1. [root@server var]# fdisk /dev/sdb
  2.  
  3. The number of cylinders for this disk is set to 8924.
  4. There is nothing wrong with that, but this is larger than 1024,
  5. and could in certain setups cause problems with:
  6. 1) software that runs at boot time (e.g., old versions of LILO)
  7. 2) booting and partitioning software from other OSs
  8.    (e.g., DOS FDISK, OS/2 FDISK)
  9.  
  10. Command (m for help): n
  11. No free sectors available
  12.  
  13. Command (m for help): d
  14. Partition number (1-5): 5
  15.  
  16. Command (m for help): d
  17. Partition number (1-5): 4
  18.  
  19. Command (m for help): d
  20. Partition number (1-4): 3
  21.  
  22. Command (m for help): d
  23. Partition number (1-4): 2
  24.  
  25. Command (m for help): d
  26. Selected partition 1
  27.  
  28. Command (m for help): d
  29. No partition is defined yet!
  30.  
  31. Command (m for help): n
  32. Command action
  33.    e   extended
  34.    p   primary partition (1-4)
  35. <strong>p</strong>
  36. Partition number (1-4): 1
  37. First cylinder (1-8924, default 1)(Here we just hit -ENTER- to accept the default)
  38. Using default value 1
  39. Last cylinder or +size or +sizeM or +sizeK (1-8924, default 8924): (Here we just hit -ENTER- to accept the default)
  40. Using default value 8924
  41.  
  42. Command (m for help): w
  43. The partition table has been altered!
  44.  
  45. Calling ioctl() to re-read partition table.
  46. Syncing disks.

Now when we run fdisk we can see the two drives with different partitions:

CODE:
  1. [root@server var]# fdisk -l
  2.  
  3. Disk /dev/sda: 73.4 GB, 73407820800 bytes
  4. 255 heads, 63 sectors/track, 8924 cylinders
  5. Units = cylinders of 16065 * 512 = 8225280 bytes
  6.  
  7.    Device Boot      Start         End      Blocks   Id  System
  8. /dev/sda1   *           1          13      104391   83  Linux
  9. /dev/sda2              14         268     204828782  Linux swap
  10. /dev/sda3             269         399     105225783  Linux
  11. /dev/sda4             400        8924    68477062+   5  Extended
  12. /dev/sda5             400        8924    68477031   83  Linux
  13.  
  14. Disk /dev/sdb: 73.4 GB, 73407820800 bytes
  15. 255 heads, 63 sectors/track, 8924 cylinders
  16. Units = cylinders of 16065 * 512 = 8225280 bytes
  17.  
  18.    Device Boot      Start         End      Blocks   Id  System
  19. /dev/sdb1               1        8924    7168199883  Linux

Now we need to format partition sdb1 so that Linux can use it. We will use ext3 in this case:

CODE:
  1. [root@server var]# mkfs.ext3 /dev/sdb1
  2. mke2fs 1.35 (28-Feb-2004)
  3. Filesystem label=
  4. OS type: Linux
  5. Block size=4096 (log=2)
  6. Fragment size=4096 (log=2)
  7. 8962048 inodes, 17920499 blocks
  8. 896024 blocks (5.00%) reserved for the super user
  9. First data block=0
  10. Maximum filesystem blocks=20971520
  11. 547 block groups
  12. 32768 blocks per group, 32768 fragments per group
  13. 16384 inodes per group
  14. Superblock backups stored on blocks:
  15.         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  16.         4096000, 7962624, 11239424
  17.  
  18. Writing inode tables: done                           
  19. Creating journal (8192 blocks): done
  20. Writing superblocks and filesystem accounting information: done
  21.  
  22. This filesystem will be automatically checked every 32 mounts or
  23. 180 days, whichever comes first.  Use tune2fs -c or -i to override.

The only thing left to do is create a mount point for the drive and add one line to our fstab. I like to put all my drives in a root folder called /mnt. So let's create mnt and meaningful place within mount which I like to name after the drive, so in this case sdb. For future reference we can now easily keep track of which drive is which.

CODE:
  1. [root@server5 var]# mkdir /mnt
  2. [root@server5 var]# cd mnt
  3. [root@server5 var]# mkdir /sdb

Now we can add the line to fstab so the system know what to mount and where. Note that your fstab will vary considerably. The line I enter is '/dev/sdb1 /mnt/sdb ext3 defaults 1 1' without the quotes:

CODE:
  1. [root@server mnt]# pico -w /etc/fstab
  2.  
  3. # This file is edited by fstab-sync - see 'man fstab-sync' for details
  4. /dev/sda5 /       ext3     usrquota,grpquota 1 1
  5. /dev/sda1 /boot   ext3    defaults 1 2
  6. /dev/sda3 /tmp    ext3    defaults,noexec 1 0
  7. none      /dev/pts devpts gid=5,mode=620 0 0
  8. none      /proc   proc    defaults 0 0
  9. none      /dev/shm tmpfs  defaults 0 0
  10. /dev/sda2 swap    swap    defaults 0 0
  11. /dev/hdc                /media/cdrom            au

to pamconsole,exec,noauto,managed 0 0
/dev/sdb1 /mnt/sdb ext3 defaults 1 1[/code]

Now ew can simply use the mount command to use our drive and check that it is there:

CODE:
  1. [root@server scsi]# cd /mnt/sdb/
  2. [root@server5 sdb]# ls
  3. lost+found

That's all there is to it.



Reader Comments

Sorry, comments are closed.