ITG Unix Support
>    
     |  List directory  |  History  |  Similar  |  Print version  

OS > Linux > Adding a disk to a Linux machine

Adding a disk to a Linux machine

So, someone told you that you need to add a new disk onto a Linux machine. What I intend to do is explain how to do so, without being specific to any distribution.

Picking your filesystem

Linux comes with support for numerous filesystems, but there are 4 that are generally used:

  • reiserfs: Great performance all-around. Particularly good for lots of small files.
  • ext3fs: Decent performance.
  • xfs: Tuned for large multi-gigabyte files. Highest performance on large files, okay performance on smaller ones.
  • ext2fs: Old non-journaled filesystem. Normally used strictly for compatibility.

YaST in SUSE Linux

If you are in SUSE Linux, you may want to just use YaST. If you are in a graphical interface, it should be under System->YaST. If you are in a command-line interface, run /sbin/yast as root.

Once YaST is loaded, select the System tab, then go to the Partition tool.

The Command-Line way

This method will work in any UNIX distribution. You need to locate your disk drive, and then pick a filesystem type for it to be.

Finding the disk device

Every disk has a name. If it is an IDE disk, it's going to be hda (primary master), hdb (primary slave), hdc (secondary master), etc. SCSI or Firewire disks will be sd*.

The easiest way to locate the correct device name for your drive is to use dmesg to search the bootup logs.

% dmesg | grep DISK
RAMDISK driver initialized: 16 RAM disks of 16384K size 1024 blocksize
hda: QUANTUM FIREBALLP LM10.2, ATA DISK drive
hdb: ST3200822A, ATA DISK drive
md: md driver 0.90.0 MAX_MD_DEVS=256, MD_SB_DISKS=27
RAMDISK: Compressed image found at block 0

Identify the disk you would like to format. In my case, it's hdb.

Partitioning the disk.

We will assume that we are only going to create one partition, but you can create more. As root, run /sbin/fdisk /dev/hdb. It will look something like this:

$ sudo /sbin/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 9729.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help):

At the command prompt, you can press m (or ?) for help. We are just going to create a new partition, so we will press "n" for new partition, and select primary for partition type:

Command (m for help): n

Command action
   e   extended
   p   primary partition (1-4)

When it asks partition number, answer 1. Your partition device will then be known as hdb1. It will then ask about what cylinders you would like your partition to start and end on, and you can just press enter:

Partition number (1-4): 1
First cylinder (1-9729, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-9729, default 9729):
Using default value 9729

When you are done, press "w" to write the table and exit.

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.

Formatting the partition device

If you've been paying attention, you'll know that the partition is referred to as "hdb1". This means "hard disk b (primary master), partition 1". We will now format it. The syntax for formatting disks is:

/sbin/mkfs.<type> /dev/<partition name>

For instance, if I want to format /dev/hdb1 with reiserfs, I type:

/sbin/mkfs.reiserfs /dev/hdb1

Setting up the mountpoint.

Now that you've got a nice shiny formatted disk, you need to tell Linux where you would like to access it from. Every partition gets a directory associated with it, so we will create one called /data.

mkdir /data

Now, we must add the mapping for this partition to this directory. To do this, we edit /etc/fstab, and add the following line to it:

/dev/hdb1    /data           reiserfs    defaults    1 2

This defines the partition, the directory, the filesystem type, any options for that filesystem (there are quite a few!), if it should be backed up, and in what order should it be checked during bootup. See the fstab manpage for more details.

Mounting the drive

Now that fstab is setup, you can just mount the drive by typing:

mount /data

It will be available the next time you reboot.

Troubleshooting

/sbin/mkfs.reiserfs: command not found

Most likely you are on a Fedora Linux system without reiserfs-utils installed. Type the following to install them:

yum install reiserfs-utils

 

Reference http://wiki.chem.indiana.edu/OS/AddingADiskToALinuxMachine
Rights rw-rw-r--   tstrombe   ITG

Prev. Which Linux distribution should you pick?   Supported Linux Distributions within IU Chemistry Next