|
|
Installing a Disk
Linux Tips by Burleson Consulting |
While the exact steps will
be vendor specific (always consult the documentation for your hardware and
software) here is the overall procedure for installing a new disk in a typical
desktop Linux workstation. In the example described below we are adding a new
drive to an open drive bay.
Here is a quick overview of the steps we will take to
setup a new disk:
1.
Shut down the system
2.
Install the drive into an open drive bay
3.
Startup the system and enter the BIOS to make the hardware aware of the
new disk
4.
Partition the new disk with fdisk
5.
Format the new partition with mkfs
6.
Mount the new partition with the mount command
7.
Add the new partition to the /etc/fstab file so it will be mounted at
startup time in the future
Most workstations have IDE or EIDE hard drives. SATA
has also recently become a popular option. Modern onboard EIDE controllers can
handle four attached devices. Typically at least one of these devices is a
CD-ROM or DVD-ROM drive and one other is a hard drive. In Linux, these four
devices are identified as hda, hdb, hdc, and hdd in the /dev directory. The hard
disks can have many partitions on each disk and the partitions are also
identified in the /dev directory. For example, /dev/hda2 refers to the second
partition on the hard disk connected to the first controller port.
Follow your manufacturer's instructions and any
instructions that came with the hard drive to install the drive in a free bay.
I would give you more specific instructions here if I could, but the methods for
the hardware part of installing and configuring a drive vary widely between
manufacturers. Especially close attention must be paid to jumper settings on
the hard drives.
If there are no free bays or ports left you may need to
replace one of the installed drives, just be careful you don't remove the drive
you're booting from. It is important to remember to hook up both the IDE and
power cables before closing the machine; otherwise you will be very disappointed
with the results.
As the machine boots you will want to enter the BIOS
setup for the system to make the hardware aware of the new disks presence. The
methods of entering the BIOS also vary from machine to machine but most systems
will tell you just as they start booting up how to enter the BIOS.
Partition the New Disk
Now that we've installed the disk and we know its device
path we are ready to partition it. The fdisk command is used to set up Linux
partitions. Older versions of Microsoft Windows had a utility called fdisk
which shared both name and function with the Linux version, but the Linux one is
a bit different so be careful.
* Make sure you get the right disk here! If you
repartition a disk with fdisk all data on affected partitions will be lost!
We invoke the fdisk command with the device path to the
disk we want to partition:
fdisk /dev/hdb
The number of cylinders for this disk is set to 1401.
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): 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)
Command (m for help): p
Disk /dev/hda: 11.5 GB, 11525455872 bytes
255 heads, 63 sectors/track, 1401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id
System
Command (m for help):
The fdisk utility is menu driven. The m command can be
used to show the menu options available at the main menu. Also shown above, the
p command will print the partition layout currently on that disk.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (14-9726, default 14):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-9726,
default 9726):
Using default value 9726
Command (m for help): w
The n menu selection can be used to create a new
partition. You can then choose to create it as an extended (e) or primary (p)
partition type. Typically you will want to create a primary partition. Next
select a partition number. On a new disk 1 should be appropriate. We can then
type w to write out the new partition table to the disk and it will be ready to
format.
Format the New Disk
Next, the mkfs (make file system) commands would be used
to format Linux partitions using an ext3 file system on the new partition. Now
when we are referring to the device path we also include the partition number
(in this case 1) that we just created.
$ mkfs ?t ext3 -c /dev/hdb1
The ?t option is used to specify the type of filesystem
to create. The ?c option specified here will cause mkfs to check the partition
for bad blocks (physical defects in the disk) before creating the file system.
If you want to format a swap partition on the new disk,
the mkswap command can be used instead of mkfs as follows:
$ mkswap ?c /dev/hdb1
Notice that we do not have to specify the partition type
since mkswap will only create swap partitions. The ?c option can still be used
to check for bad blocks.
Mount the New Disk
The next step is to create a directory for use as a
mount point for our new partition. The mkdir command is used to create a
directory, in this case called /new1. There is nothing special about this
directory but it's best to keep it empty since any contents of this directory
will disappear when the new partition is mounted at that location.
$ mkdir /new1
Now that we have created our mount point we can mount
the partition making it available for use:
$ mount -t ext3 /dev/hdb1 /new1
Here we see that the mount command takes several
options. First the -t ext3 specifys the partition type, the same type which
was used for the newfs command. The next option, /dev/hdb1, specifies the
device path and the final option listed here, /new1 is the mount point we just
created.
We could now start using the new disk at the location
/new1 but when the system reboots the /new1 partition will not be mounted! To
make it mount automatically we will need to add it to the /etc/fstab file.
This is an excerpt from "Easy
Linux Commands" by Linux guru Jon Emmons. You can purchase it for only
$19.95 (30%-off) at
this link.