Linux Tips

  


Partitioning and Formatting Second Hard Drive in Linux - (ext3)

by Jeff Hunter, Sr. Database Administrator

Contents

Introduction

This article presents the commands used to partition and format a second hard drive in Linux using the ext3 file system. For the purpose of this example, I installed a second hard drive in a Red Had Linux system where the drive is recognized as /dev/hdb. I want to make only one partition on this hard drive which will be /dev/hdb1.

fdisk

First, you will need to run the fdisk command in order to partition the disk. For this example, I only want to create one ext3 partition. Here is an example session:


[root@racnode1 ~]# fdisk /dev/hdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. The number of cylinders for this disk is set to 4865. 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 Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-4865, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (1-4865, default 4865): 4865 Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): 83 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.

Create ext3 File System

The next step is to create an ext3 file system on the new partition. Provided with the distribution is a script named /sbin/mkfs.ext3. Here is an example session of using the mkfs.ext3 script:


[root@racnode1 ~]# mkfs.ext3 -b 4096 /dev/hdb1 mke2fs 1.27 (8-Mar-2002) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 4889248 inodes, 9769520 blocks 488476 blocks (5.00%) reserved for the super user First data block=0 299 block groups 32768 blocks per group, 32768 fragments per group 16352 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624 Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

Mounting the File System

Now that the new hard drive is partition and formated, the last step is to mount the new drive. For this example, I will be mounting the new hard drive on the directory /db.

 

You will first need to create the /db directory before mouting the disk! (e.g. mkdir /db)

Edit the /etc/fstab file and add an entry for the new drive. For my example, I will create the /dev/hdb1 entry as follows:


LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 none /dev/pts devpts gid=5,mode=620 0 0 none /proc proc defaults 0 0 none /dev/shm tmpfs defaults 0 0 /dev/hdb1 /db ext3 defaults 1 1 /dev/hda2 swap swap defaults 0 0 /dev/cdrom /mnt/cdrom iso9660 noauto,owner,kudzu,ro 0 0 /dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0

After making the entry in the /etc/fstab file, it is now just a matter of mounting the disk:

[root@racnode1 ~]# mount /db

[root@racnode1 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda3             37191660  11016692  24285724  32% /
/dev/hda1               101089     12130     83740  13% /boot
none                    515524         0    515524   0% /dev/shm
/dev/hdb1             38464340     32828  36477608   1% /db

About the Author

Jeffrey Hunter is an Oracle Certified Professional, Java Development Certified Professional, Author, and an Oracle ACE. Jeff currently works as a Senior Database Administrator for The DBA Zone, Inc. located in Pittsburgh, Pennsylvania. His work includes advanced performance tuning, Java and PL/SQL programming, developing high availability solutions, capacity planning, database security, and physical / logical database design in a UNIX / Linux server environment. Jeff's other interests include mathematical encryption theory, tutoring advanced mathematics, programming language processors (compilers and interpreters) in Java and C, LDAP, writing web-based database administration tools, and of course Linux. He has been a Sr. Database Administrator and Software Engineer for over 20 years and maintains his own website site at: http://www.iDevelopment.info. Jeff graduated from Stanislaus State University in Turlock, California, with a Bachelor's degree in Computer Science and Mathematics.



Copyright (c) 1998-2014 Jeffrey M. Hunter. All rights reserved.

All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at jhunter@idevelopment.info.

I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.

Last modified on
Wednesday, 28-Dec-2011 14:12:20 EST
Page Count: 485125