In: Categories » Computers and technology » Linux Commands » The process of adding a disk under Linux on the Intel
The process of adding a disk under Linux on the Intel (x86) platform is relatively easy. Assuming you are adding a disk that is of similar type to your existing disks (e.g., adding an IDE disk to a system that already has IDE drives or adding a SCSI disk to a system that already has SCSI drives), the system should automatically detect the new disk at boot time, and all that is left is partitioning it and creating a file system on it. If you are adding a new type of disk (like a SCSI disk on a system that has only IDE drives), you may need to compile in support for your SCSI card to the kernel. (Note that most Linux distributions come with support for many popular SCSI cards as part of the standard installation. If you didn’t recompile the kernel from the original installation, it is unlikely that you will need to recompile the kernel to add support.) To compile in support for a new type of disk, see Linux tutorial 9. Be sure to step through all of the relevant menus and mark the appropriate driver to be compiled either into the base kernel or as a module (assuming it can be compiled as a module).
Once the disk is in place, simply boot the system and you’re ready to go. If you aren’t sure about whether the system can see the new disk, run the dmesg command and see whether the driver loaded and was able to find your disk. For example:
[root@tedford /root]# dmesg | more
Overview of Partitions
For the sake of clarity, and in case you need to know what a partition is and how it works, let’s do a brief review of this subject. Every disk must be partitioned. Partitions divide up the disk, and each segment acts as a complete disk by itself. Once a partition is filled, it cannot (without special software) automatically overflow onto another partition. Usually, the process of partitioning a disk accomplishes one of two goals: Either the user needs two different operating systems installed and each operating system requires its own partition, or it may be prudent that the usage of space on one partition not interfere with space dedicated to other tasks on other partitions. An example of the latter occurs in user home directories. When users of the system are not the administrators of the system, the administrator must ensure that users don’t consume the entire disk for their personal files. This takes up room needed for logging purposes and temporary files, causing the system to misbehave. To prevent this, a special partition is created for user files so that they don’t overflow into protected system space.
NOTE
It is acceptable to partition a disk so that only one large partition is taking up the entire disk. But beware: If this is the boot partition, the entire partition must fit within the 1024 cylinder boundary, or you may not be able to boot. See Linux tutorial 8 for more information.
Where Disks Exist
Under Linux, each disk is given its own device name. IDE disks start with the name /dev/hdX, where X can range from a through z, with each letter representing a physical device. For example, in an IDE-only system with one hard disk and one CD-ROM, both on the same IDE chain, the hard disk would be /dev/hda, and the CD-ROM would be /dev/hdb. Disk devices are automatically created during system installation. When partitions are created, new devices are used. They take the form of /dev/hdXY, where X is the device letter (as just described), and Y is the partition number. Thus, the first partition on the /dev/hda disk is /dev/hda1, the second partition would be /dev/hda2, and so on. SCSI disks follow the same basic scheme as IDE, except instead of starting with /dev/hd, they start with /dev/sd. Therefore, the first partition on the first SCSI disk would be /dev/sda1, the second partition on the third SCSI disk would be /dev/sdc2, and so on.
Creating Partitions CAUTION
The process of creating partitions is irrevocably destructive to the data already on the disk. Before creating, changing, or removing partitions on any disk, you must be very sure of what’s on the disk being modified, and you need to have a backup if that data is still needed. During the installation process, you probably used a “pretty” tool to create partitions. Unfortunately, Linux platforms don’t ship with a standard utility for creating and managing partitions. A basic mechanism that does exist on all Linux distributions is fdisk. Though it’s small and somewhat awkward, it’s a reliable partitioning tool. Furthermore, in the event you need to troubleshoot a system that has gone really wrong, you should be familiar with basics such as fdisk. The only real downside to fdisk is its lack of a user interface. For this sample run, assume that you want to partition the /dev/hdb device, a 340MB IDE hard disk. (Yes, they do still exist.) You begin by running fdisk with the /dev/hdb parameter:
[root@tedford /root]# fdisk /dev/hdb
which outputs a simple prompt:
Command (m for help):
Let’s use m to see what your options are. This menu is reasonably self-explanatory:
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):
You begin by looking at the existing partition, using the p command (print the partition table):
Command (m for help): p
Disk /dev/hdb: 16 heads, 63 sectors, 665 cylinders
Units = cylinders of 1008 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 * 1 664 334624+ 6 FAT16
Command (m for help):
You have a little legacy system here, don’t you think? Time to upgrade this disk—start by removing the existing partition using the d command (delete a partition):
Command (m for help): d
Partition number (1-4): 1
Command (m for help):
And use the p (print the partition table) command to verify the results:
Command (m for help): p
Disk /dev/hdb: 16 heads, 63 sectors, 665 cylinders
Units = cylinders of 1008 * 512 bytes
Device Boot Start End Blocks Id System
Command (m for help):
No partition there. Time to start creating partitions. For the sake of discussion, pretend this disk is large enough to accommodate a full workstation configuration. To set this up, you need to create the partitions shown in Image 7-5. So now that you know which partitions to create, let’s do it! Start with the root partition. Given that you have only 340MB to work with, keep root small—only 35MB.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-665, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-665, default 665): +35M
Command (m for help):
Notice the first prompt is for whether you want a primary or extended partition. This is because of a goofy mess created long ago (pre-Linux) when hard disks were so small that no one thought more than four partitions would ever be needed. When disks got bigger and backward-compatibility was an issue, we needed a trick to accommodate more partitions.
The last partition would be an “extended” partition, unseen by the user but able to contain additional partitions. The next question: Which partition number? (You can see the limit of four primary partitions as part of the question.) You start with one, picking the default starting cylinder, and then specify that you want 25MB allocated to it. To create the second partition for swap, type the following:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (68-665, default 68): 68
Last cylinder or +size or +sizeM or +sizeK (52-665, default 665): +16M
Command (m for help):
This time, the prompts are identical to those used for the previous partition, with slightly different numbers. However, by default, fdisk is creating ext2 partitions. You need this partition to be of type swap. To do this, use the t (change partition type) command:
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): L
0 Empty 16 Hidden FAT16 61 SpeedStor a6 OpenBSD
1 FAT12 17 Hidden HPFS/NTF 63 GNU HURD or Sys a7 NeXTSTEP
2 XENIX root 18 AST Windows swa 64 Novell Netware b7 BSDI fs
3 XENIX usr 24 NEC DOS 65 Novell Netware b8 BSDI swap
4 FAT16 <32 <N 3c PartitionMagic 70 DiskSecure Mult c1 DRDOS/secFAT-
5 Extended 40 Venix 80286 75 PC/IX c4 DRDOS/secFAT-
6 FAT16 41 PPC PReP Boot 80 Old Minix c6 DRDOS/secFAT-
7 HPFS/NTFS 42 SFS 81 Minix / old Lin c7 Syrinx
8 AIX 4d QNX4.x 82 Linux swap db CP/M / CTOS .
9 AIX bootable 4e QNX4.x 2nd part 83 Linux e1 DOS access
a OS/2 Boot Manag 4f QNX4.x 3rd part 84 OS/2 hidden C: e3 DOS R/O
b Win95 FAT32 50 OnTrack DM 85 Linux extended e4 SpeedStor
c Win95 FAT32 (LB 51 OnTrack DM6 Aux 86 NTFS volume set eb BeOS fs
e Win95 FAT16 (LB 52 CP/M 87 NTFS volume set f1 SpeedStor
f Win95 Ext'd (LB 53 OnTrack DM6 Aux 93 Amoeba f4 SpeedStor
10 OPUS 54 OnTrackDM6 94 Amoeba BBT f2 DOS secondary
11 Hidden FAT12 55 EZ-Drive a0 IBM Thinkpad hi fe LANstep
12 Compaq diagnost 56 Golden Bow a5 BSD/386 ff BBT
14 Hidden FAT16 5c Priam Edisk
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap)
Command (m for help):
The first question is, of course, what partition number do you want to change to? Since you want the second partition to be the swap, you entered 2. The next prompt is a bit more cryptic: the hexadecimal code for the correct partition. Since people don’t remember hex codes very well, the L command lists all available partition types. You spot 82 for Linux Swap, so enter that, and you’re done.
NOTE
It used to be that Linux’s swap partition was limited to 128M. This is no longer the case. You can create a single swap partition as large as 2GB. You can create multiple swap partitions if you like. Now to create /usr. Make it 100MB in size:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (85-665, default 85): 85
Last cylinder or +size or +sizeM or +sizeK (85-665, default 665): +100M
Command (m for help):
So at this point, you have three partitions: root, swap, and /usr. You can see them by entering the p command:
Command (m for help): p
Disk /dev/hdb: 16 heads, 63 sectors, 665 cylinders
Units = cylinders of 1008 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 51 25672+ 83 Linux
/dev/hdb2 52 84 16632 82 Linux swap
/dev/hdb3 85 288 102816 83 Linux
Command (m for help):
Now you need to create the extended partition to accommodate /tmp, /var, and /home. Do so using the n command, just as for any other new partition:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (289-665, default 289): 289
Last cylinder or +size or +sizeM or +sizeK (289-665, default 665): 665
Command (m for help):
Instead of designating a megabyte value for the size of this partition, you enter the last cylinder number, thus taking up the remainder of the disk. Let’s see what this looks like:
Command (m for help): p
Disk /dev/hdb: 16 heads, 63 sectors, 665 cylinders
Units = cylinders of 1008 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 51 25672+ 83 Linux
/dev/hdb2 52 84 16632 82 Linux swap
/dev/hdb3 85 288 102816 83 Linux
/dev/hdb4 289 665 190008 5 Extended
Command (m for help):
Now you’re ready to create the last three partitions:
Command (m for help): n
First cylinder (289-665, default 289): 289
Last cylinder or +size or +sizeM or +sizeK (289-665, default 665): +100M
Command (m for help): n
First cylinder (493-665, default 493): 493
Last cylinder or +size or +sizeM or +sizeK (493-665, default 665): +45M
Command (m for help): n
First cylinder (585-665, default 585): 585
Last cylinder or +size or +sizeM or +sizeK (585-665, default 665): 665
Command (m for help):
Note that for the very last partition, you again specified the last cylinder instead of a megabyte value, so that you are sure that you have allocated the entire disk. One last p command shows you what your partitions now look like:
Command (m for help): p
Disk /dev/hdb: 16 heads, 63 sectors, 665 cylinders
Units = cylinders of 1008 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 51 25672+ 83 Linux
/dev/hdb2 52 84 16632 82 Linux swap
/dev/hdb3 85 288 102816 83 Linux
/dev/hdb4 289 665 190008 5 Extended
/dev/hdb5 289 492 102784+ 83 Linux
/dev/hdb6 493 584 46336+ 83 Linux
/dev/hdb7 585 665 40792+ 83 Linux
Command (m for help):
Perfect. Commit the changes to disk and quit the fdisk utility by using the w (write table
to disk and exit) command:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
legal notice
Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.
Useful tools and features
If you like this article (tutorial), please link to it from your web page using the information above.
related articles
Editing Text Files Editors are by the far the bulkiest of common tools, but they are also the most useful. Without them, making any kind of change to a text file would be a tremendous undertaking. Regardless of your Linux distribution, you will have gotten a few editors. You should take a few moments to get comfortable with them before you’re busy fighting another problem. NOTE Although all of the editors listed here come with Red Hat 8, not all of them are installed by default. ...
2. Reviewing Linux File System Standards
Reviewing Linux File System Standards One argument you hear regularly against Linux is that there are too many different distributions, and that multiple distributions lead to fragmentation. This fragmentation will eventuate in different, incompatible Linux versions. This is, without a doubt, complete nonsense that plays on “FUD” (Fear, Uncertainty, and Doubt). These types of arguments usually stem from a misunderstanding of the kernel and distributions. However, the Linux community has realized that it h...
3. Linux is built upon the foundation of file systems
File Systems Linux is built upon the foundation of file systems. They are the mechanisms by which the disk gets organized, providing all of the abstraction layers above sectors and cylinders. In this module, you’ll learn about the composition and management of these abstraction layers supported by the default Linux file system, ext2, and its more robust counterpart, ext3. This module covers the many aspects of managing disks. This includes creating partitions, establishing file systems, automating the process ...
4. Mounting and Unmounting Local Disks
Linux’s strong points include its flexibility and the way it lends itself to seamless management of file locations. Partitions are mounted so that they appear as just another subdirectory. Even a substantial number of file systems look, to the user, like one large directory tree. This characteristic is especially helpful to the administrator, who can relocate partitions to various servers but can have the partitions still mounted to the same location in the directory tree; users of the file system need not know abou...
Using fsck The fsck tool, short for File System ChecK, is used to diagnose and repair file systems that may have become damaged in the course of daily operations. Such repairs are usually necessary after a system crash in which the system did not get a chance to fully flush all of its internal buffers to disk. (Although this tool’s name bears a striking resemblance to one of the expressions often uttered after a system crash, that this tool is part of the recovery process is strictly coincidence.) Us...
6. With the partitions created you need to put file systems on them
Syncing disks. WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. [root@tedford /root]# If you needed to write an /etc/fstab file yourself for this configuration, it would look something like this: /dev/hdb1 / ext3 defaults 1 1 /dev/hdb2 swap swap defaults 0 0 /dev/hdb3 /usr ext3 defaults 1 2 /dev/hdb5 /home ext3 defaults 1 2 /dev/hdb6 /var ext3 defaults 1 2 /dev/hdb...
7. Mounting NFS partitions works much the same way as mounting local partitions
Mounting NFS Partitions Mounting NFS partitions works much the same way as mounting local partitions. The only difference is in how the partition is addressed. On local disks, partitions are addressed by their device name, such as /dev/hda1. In NFS mounts, partitions are referenced by their hostnames and export directories. Thus, if the server named ungerer is allowing your host to mount the directory /export/SL1200/MK2 and you want to mount this to /projects/topsecret1, you would use this command:...
8. Using autofs to mount partitions across the network
Starting the autofs Service Because the way you’re using autofs to mount partitions across the network relies on NFS, before using it you’ll need to be sure you can do normal NFS mounts. Once you have this working, just make a simple change to your startup scripts to deploy the autofs service. The easiest way to do this is to run the redhat-config-services utility to enable the daemon. Simply start the configuration tool and mark the autofs check box as shown. If you need to start autofs by hand...