Information and Links
Join the fray by commenting, tracking what others have to say, or linking to it from your blog.
Formatting a second drive on RHEL Linux
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:
-
#cat /proc/scsi/scsi
-
Attached devices:
-
Host: scsi0 Channel: 00 Id: 00 Lun: 00
-
Vendor: FUJITSU Model: MAW3073NP Rev: 5803
-
Type: Direct-Access ANSI SCSI revision: 03
-
Host: scsi0 Channel: 00 Id: 01 Lun: 00
-
Vendor: SEAGATE Model: ST373207LW Rev: D702
-
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:
-
[root@server var]# fdisk -l
-
-
Disk /dev/sda: 73.4 GB, 73407820800 bytes
-
255 heads, 63 sectors/track, 8924 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sda1 * 1 13 104391 83 Linux
-
/dev/sda2 14 268 2048287+ 82 Linux swap
-
/dev/sda3 269 399 1052257+ 83 Linux
-
/dev/sda4 400 8924 68477062+ 5 Extended
-
/dev/sda5 400 8924 68477031 83 Linux
-
-
Disk /dev/sdb: 73.4 GB, 73407820800 bytes
-
255 heads, 63 sectors/track, 8924 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sdb1 * 1 13 104391 83 Linux
-
/dev/sdb2 14 268 2048287+ 82 Linux swap
-
/dev/sdb3 269 399 1052257+ 83 Linux
-
/dev/sdb4 400 8924 68477062+ 5 Extended
-
/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:
-
[root@server var]# fdisk /dev/sdb
-
-
The number of cylinders for this disk is set to 8924.
-
There is nothing wrong with that, but this is larger than 1024,
-
and could in certain setups cause problems with:
-
1) software that runs at boot time (e.g., old versions of LILO)
-
2) booting and partitioning software from other OSs
-
(e.g., DOS FDISK, OS/2 FDISK)
-
-
Command (m for help): n
-
No free sectors available
-
-
Command (m for help): d
-
Partition number (1-5): 5
-
-
Command (m for help): d
-
Partition number (1-5): 4
-
-
Command (m for help): d
-
Partition number (1-4): 3
-
-
Command (m for help): d
-
Partition number (1-4): 2
-
-
Command (m for help): d
-
Selected partition 1
-
-
Command (m for help): d
-
No partition is defined yet!
-
-
Command (m for help): n
-
Command action
-
e extended
-
p primary partition (1-4)
-
<strong>p</strong>
-
Partition number (1-4): 1
-
First cylinder (1-8924, default 1): (Here we just hit -ENTER- to accept the default)
-
Using default value 1
-
Last cylinder or +size or +sizeM or +sizeK (1-8924, default 8924): (Here we just hit -ENTER- to accept the default)
-
Using default value 8924
-
-
Command (m for help): w
-
The partition table has been altered!
-
-
Calling ioctl() to re-read partition table.
-
Syncing disks.
Now when we run fdisk we can see the two drives with different partitions:
-
[root@server var]# fdisk -l
-
-
Disk /dev/sda: 73.4 GB, 73407820800 bytes
-
255 heads, 63 sectors/track, 8924 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sda1 * 1 13 104391 83 Linux
-
/dev/sda2 14 268 2048287+ 82 Linux swap
-
/dev/sda3 269 399 1052257+ 83 Linux
-
/dev/sda4 400 8924 68477062+ 5 Extended
-
/dev/sda5 400 8924 68477031 83 Linux
-
-
Disk /dev/sdb: 73.4 GB, 73407820800 bytes
-
255 heads, 63 sectors/track, 8924 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
-
Device Boot Start End Blocks Id System
-
/dev/sdb1 1 8924 71681998+ 83 Linux
Now we need to format partition sdb1 so that Linux can use it. We will use ext3 in this case:
-
[root@server var]# mkfs.ext3 /dev/sdb1
-
mke2fs 1.35 (28-Feb-2004)
-
Filesystem label=
-
OS type: Linux
-
Block size=4096 (log=2)
-
Fragment size=4096 (log=2)
-
8962048 inodes, 17920499 blocks
-
896024 blocks (5.00%) reserved for the super user
-
First data block=0
-
Maximum filesystem blocks=20971520
-
547 block groups
-
32768 blocks per group, 32768 fragments per group
-
16384 inodes per group
-
Superblock backups stored on blocks:
-
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
-
4096000, 7962624, 11239424
-
-
Writing inode tables: done
-
Creating journal (8192 blocks): done
-
Writing superblocks and filesystem accounting information: done
-
-
This filesystem will be automatically checked every 32 mounts or
-
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.
-
[root@server5 var]# mkdir /mnt
-
[root@server5 var]# cd mnt
-
[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:
-
[root@server mnt]# pico -w /etc/fstab
-
-
# This file is edited by fstab-sync - see 'man fstab-sync' for details
-
/dev/sda5 / ext3 usrquota,grpquota 1 1
-
/dev/sda1 /boot ext3 defaults 1 2
-
/dev/sda3 /tmp ext3 defaults,noexec 1 0
-
none /dev/pts devpts gid=5,mode=620 0 0
-
none /proc proc defaults 0 0
-
none /dev/shm tmpfs defaults 0 0
-
/dev/sda2 swap swap defaults 0 0
-
/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:
-
[root@server scsi]# cd /mnt/sdb/
-
[root@server5 sdb]# ls
-
lost+found
That's all there is to it.

