Adding a Hard Drive in Linux

Published on June 2016 | Categories: Documents | Downloads: 56 | Comments: 0 | Views: 196
of 4
Download PDF   Embed   Report

Comments

Content

Adding a Hard Drive in Linux

http://www.skullbox.net/newsda.php

Si vis pacem, para bellum

Home | Articles | About | Contact | Blog

Thursday, July 28, 2011

Audience: Self Learners - System Admins Last Updated: 6/6/2011 1:38:28 M **All times are EST**

Linux Server Administration IT Chop Shops Flow Viewers: SFLOW, NetFLOW, and JFLOW

Adding a Hard Drive in Linux
By Erik Rodriguez This article is a HOWTO for adding a new drive in Linux. You can also watch the video.

Exchange 2007 Back Pressure IPtables open port for specific IP Politics in IT Departments

Adding New Drives There are many reasons why you would need to add a new drive to your Linux box. You might have out-grown your current space limitations, or you may want to add a separate drive for a specific project or service. In any case, if you follow this guide, you should have no problems. First, you must be familiar with the naming scheme Linux uses for your drives. For purposes if this article, everything highlighted in blue is the command you must type at the terminal prompt. Anything hightlighted in red indicates changes made by a previous command or something you should pay special attention to. Anything highlighted in green is simply the standard output from a terminal or issued command. The machine used for this guide is running Red Hat Entperise Linux. Conventional Naming This article assumes you know the difference between primary, extended and logical partitions. In the following example, I added a SCSI hard drive with one primary partition. With that being said, I'll continue explaining the naming scheme. Linux gives each drive a 3 letter name followed by a partition number. If you are using IDE drives, these will all be named hd**. Where hd denotes the drive and the next two variables are aassociated with IDE order (primary master, primary slave, etc) and partition number. So, your primary master drive will always be named hda. If you are using SCSI drives, everything remains the same except instead of using hd, drives are named sd**. Your SCSI primary master drive will always be named sda. All of these devices reside under the /dev portion of your Linux file system. For instance, as root, you can issue the following command to view the naming combinations possible for your system. Remember, in this example, I am using SCSI hardware. If you are using IDE, simply use hd is place of sd here.

HOWTO - Block Dropbox Cisco IOS Cheat Sheet Subnet Cheat Sheet TCP vs. UDP Design a DMZ Network How DNS works Firewall Configuration

Mailing List E-mail:

Juniper SSG Firewalls Server Management Configuring VLANs Runlevels in Linux Server Clustering SONET Networks The Red Hat Network Server Colocation

By Joining the mailing list you will be notified of site updates.

Show Your Support For This Site By Donating:

[root@roswell root]# ls /dev/sda* /dev/sda /dev/sdab10 /dev/sdad12 /dev/sda1 /dev/sdab11 /dev/sdad13 /dev/sda10 /dev/sdab12 /dev/sdad14 /dev/sda11 /dev/sdab13 /dev/sdad15 /dev/sda12 /dev/sdab14 /dev/sdad2 /dev/sda13 /dev/sdab15 /dev/sdad3 /dev/sda14 /dev/sdab2 /dev/sdad4 ---Some results omitted** ---[root@roswell root]#

Complicated Linux Servers /dev/sdaf14 /dev/sdaf15 /dev/sdaf2 /dev/sdaf3 /dev/sdaf4 /dev/sdaf5 /dev/sdaf6 /dev/sdah2 /dev/sdah3 /dev/sdah4 /dev/sdah5 /dev/sdah6 /dev/sdah7 /dev/sdah8 /dev/sdaj4 /dev/sdaj5 /dev/sdaj6 /dev/sdaj7 /dev/sdaj8 /dev/sdaj9 /dev/sdak /dev/sdal6 /dev/sdal7 /dev/sdal8 /dev/sdal9 /dev/sdam /dev/sdam1 /dev/sdam10 Dark Fiber Data Center Network Design Firewall Types Colocation Bandwidth

Note that I omitted a large portion of the results because they were huge! Remember that this list is not dependent on the current number of hard drives in the system, but the maximum naming possibilities for any number of drives and partitions. Do not be surprised if your results are rather lengthy as well. Creating, Mounting, and Configuration New Partitions Before adding an extra drive, this machine had 2 physical drives. Both of them were named accordingly (sda and sdb) before the new drive was added. The second drive containing the swap partitions was automatically renamed when the new drive was added. Notice the command and output below:

[root@roswell root]# df -h Filesystem Size /dev/sda1 8.3G /dev/sda2 99M /dev/sdc1 16G none 250M [root@roswell root]#

Used Avail Use% Mounted on 2.4G 5.5G 30% / 26M 69M 27% /boot 13G 2.3G 85% /export 0 250M 0% /dev/shm

This command simply lists all currently mounted drives, their names, and space usage. Notice that sdb is not presently mounted. However, we know that it exists otherwise, there would not be an sdc present. I could not add my new drive as sdc because my SCSI hotswap drive cage reserves the first two slots for 1.5" drives. So I was forced to make the new drive sdb because it is a 1.5" drive. Setting Partitions You should be fairly familiar with fdisk. The commands are somewhat different than it's DOS equivalent. See the following commands and output:

[root@roswell root]# fdisk /dev/sdb Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel

1 of 4

28-07-2011 12:24

Adding a Hard Drive in Linux

http://www.skullbox.net/newsda.php

c d l m n o p q s t u v w x

toggle the dos compatibility flag delete a partition list known partition types print this menu add a new partition create a new empty DOS partition table print the partition table quit without saving changes create a new empty Sun disklabel change a partition's system id change display/entry units verify the partition table write table to disk and exit extra functionality (experts only)

Command (m for help):

If there is a problem, and there is no drive associated with /dev/sdb, you will get an error message. Remember, that nothing will actually be executed until you issue a w command. It's always a good idea to read through the variables of your commands. Doing so will ensure that you aren't forgetting anything. Let's get started!

Command (m for help): p Disk /dev/sdb: 50.0 GB, 50019202560 bytes 255 heads, 63 sectors/track, 6081 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System

Command (m for help): If you issue a p command, you will see any partitions that currently exist on the drive. You can see by the output above there are no existing partitions. This drive is un-partitionedd and unformatted. To create a new partition, is the n command.

Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-6081, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (1-6081, default 6081): 6081 Command (m for help): In the output above notice that interval I selected for the cylinders. Using the entire range allows you create one partition across the entire drive. So, in order to create a primary partition on /dev/sdb/ we issued the following commands: n (creates a new partition) p (creates a primary partition) 1 (the number 1 denotes the partition will be /dev/sdb1) We can check the partition specifications we just entered by using the p command again.

Command (m for help): p Disk /dev/sdb: 50.0 GB, 50019202560 bytes 255 heads, 63 sectors/track, 6081 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot /dev/sdb1 Start 1 End 6081 Blocks 48845601 Id 83 System Linux

Command (m for help):

Notice the new partition (highlighted in red). However, we must issue a w command to finalize it. If you messed anything up, you can use the d command and specify which partition you want to delete.

Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@roswell root]#

Formatting Now that the partition has been created, you need to format the drive. You can format it with almost any file system you wish. However, the most common Linux formats are ext2 and ext3. Ext3 is simply a candy coated version of ext2 that adds a logging feature. You must specify which partition to format by calling the device and partition number like this:

[root@roswell root]# mkfs -t ext3 /dev/sdb1 mke2fs 1.32 (09-Nov-2002) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 6111232 inodes, 12211400 blocks 610570 blocks (5.00%) reserved for the super user First data block=0 373 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

2 of 4

28-07-2011 12:24

Adding a Hard Drive in Linux

http://www.skullbox.net/newsda.php

This filesystem will be automatically checked every 38 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@roswell root]#

What did we do there? Using the mkfs (make file system) command, we specified the type (using the -t) ext3 using the device and partition name (/dev/sdb1). You have successfull partitioned and formatted your new drive. Wait, you're not done yet. You will want to mount this partition to make it usable. You will also want this partition to mount automatically when you reboot the machine.

Mounting In order to automatically mount a partition, you must edit the /etc/fstab file. The fstab file tells Linux where to mount all partitions located within the system. The output below shows the current fstab file before including the newly added drive:

[root@roswell root]# vi /etc/fstab LABEL=/ / LABEL=/boot /boot none /dev/pts LABEL=/export /export none /proc none /dev/shm /dev/sdb2 swap /dev/cdrom /mnt/cdrom /dev/fd0 /mnt/floppy

ext3 defaults 1 1 ext3 defaults 1 2 devpts gid=5,mode=620 0 0 ext3 defaults 1 2 proc defaults 0 0 tmpfs defaults 0 0 swap defaults 0 0 udf,iso9660 noauto,owner,kudzu,ro 0 0 auto noauto,owner,kudzu 0 0

You may notice I viewed this file using vi. Vi is a simple text editor that may or may not be loaded on your Linux system. It is somewhat similar to emacs. In any case, both programs can perform the same task. We will mount the new partition as /media. Remember to create a directory named media, otherwise fstab won't be able to mount the partition. It is shown high-lighted red in the output below:

LABEL=/ LABEL=/boot none LABEL=/export none none /dev/sdb1 /dev/sdb2 /dev/cdrom /dev/fd0

/ /boot /dev/pts /export /proc /dev/shm /media swap /mnt/cdrom /mnt/floppy

ext3 defaults 1 1 ext3 defaults 1 2 devpts gid=5,mode=620 0 0 ext3 defaults 1 2 proc defaults 0 0 tmpfs defaults 0 0 ext3 defaults 1 2 swap defaults 0 0 udf,iso9660 noauto,owner,kudzu,ro 0 0 auto noauto,owner,kudzu 0 0

Next, issue a simple mount command providing the partition name:

[root@roswell export]# mount /dev/sdb1 [root@roswell export]# You're all done! You will be able to access the /media folder immediately and after the machine reboots as fstab will automatically re-mount it for you. If you want to verify the partition is successfully present and mounted, use the following commands:

[root@roswell media]# mount /dev/sda1 on / type ext3 (rw) none on /proc type proc (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) usbdevfs on /proc/bus/usb type usbdevfs (rw) /dev/sda2 on /boot type ext3 (rw) /dev/sdc1 on /export type ext3 (rw) none on /dev/shm type tmpfs (rw) /dev/sdb1 on /media type ext3 (rw) [root@roswell media]# The red line shows our new drive freshly mounted. You can check the space usage if you issue the following command.

[root@roswell media]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 8.3G 2.4G 5.5G 30% / /dev/sda2 99M 26M 69M 27% /boot /dev/sdc1 16G 13G 2.3G 85% /export none 250M 0 250M 0% /dev/shm /dev/sdb1 46G 33M 44G 1% /media [root@roswell media]#

HAPPY MOUNTING ;)

If you found this information useful, click the +1 button

Your E-mail:

Subject:

Type verification image:

Message:

3 of 4

28-07-2011 12:24

Adding a Hard Drive in Linux

http://www.skullbox.net/newsda.php

Send Message

Copyright © 2002-2011 Skullbox.Net All Rights Reserved. A division of Orlando Tech Works, LLC By using this site you agree to its Terms and Conditions. Contact Erik Rodriguez

4 of 4

28-07-2011 12:24

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close