How to add an external USB hard drive to your Linux server (Redhat, CentOS, Ubuntu, Gentoo and SUSE)

No GoodNeed ImprovementOKGoodExcellent (3 votes, average: 3.67 out of 5)
Loading ... Loading ...

Extenal USB hard disk is really useful (and inexpensive) for backing up your Linux server. Follow these steps to get it to work.

1, Buy a USB hard disk (I have bought one 250 GB Western Digital “My Book” Premium 1C External Hard Drive USB2.0/Firewire from CompUSA).

2, Plug in USB cable to your server, power it up.

3, Log in to Linux box, type the following command to if your server can see the disk

tail /var/log/messages

output will have the following entry:

Mar 26 17:45:55 innovitainc kernel: Attached scsi disk sdc at scsi1, channel 0, id 0, lun 0

4, Create partition

fdisk /dev/sdc1

The number of cylinders for this disk is set to 30400.
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): p

Disk /dev/sdc1: 250.0 GB, 250056705024 bytes
255 heads, 63 sectors/track, 30400 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdc1p1 ? 119512 153402 272218546+ 20 Unknown
Partition 1 does not end on cylinder boundary.
/dev/sdc1p2 ? 82801 116350 269488144 6b Unknown
Partition 2 does not end on cylinder boundary.
/dev/sdc1p3 ? 33551 120595 699181456 53 OnTrack DM6 Aux3
Partition 3 does not end on cylinder boundary.
/dev/sdc1p4 * 86812 86813 10668+ 49 Unknown
Partition 4 does not end on cylinder boundary.

Partition table entries are not in disk order

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): d
Partition number (1-4): 1

Command (m for help): d
Partition number (1-4): 2

Command (m for help): d
Partition number (1-4): 3

Command (m for help): d
Selected partition 4

Command (m for help): p

Disk /dev/sdc1: 250.0 GB, 250056705024 bytes
255 heads, 63 sectors/track, 30400 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-30400, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-30400, default 30400):
Using default value 30400

Command (m for help): p

Disk /dev/sdc1: 250.0 GB, 250056705024 bytes
255 heads, 63 sectors/track, 30400 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdc1p1 1 30400 244187968+ 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

5. Format hard disk

mkfs.ext3 /dev/sdc1

mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
30539776 inodes, 61049000 blocks
3052450 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=62914560
1864 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, 20480000, 23887872

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: USB
done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

6. Edit /etc/fstab using command vi /etc/fstab, add the following line to the file:

/dev/sdc1 /media/usbdisk1 ext3 pamconsole,exec,noauto,managed 0 0

7. Make a directory:

mkdir /media/usbdisk1

8, Mount the disk

mount /media/usbdisk1

9, edit crontab, add these line to reboot server and the mount the USB hard disk.

0 3 * * * /sbin/reboot
10 3 * * * mount /media/usbdisk1

10. Verify you have the disk ready for use.

df -k

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
32801652 22583956 8551444 73% /
/dev/sda1 101086 39634 56233 42% /boot
/dev/sdb1 70557052 11410016 55562940 18% /disk2
none 1557528 0 1557528 0% /dev/shm
/dev/sdc1 240362656 94272 228058584 1% /media/usbdisk1

Popularity: 18%

4 Comments »

  1. good said,

    April 13, 2007 @ 12:25 pm

    Respected sir,

    I read your suggestion but i have some other problems. I tried same But I could not mount usb hdd. I am using CENTOS linux os but i am finding where is the problems.

  2. Certosin0 said,

    July 11, 2007 @ 5:45 am

    @good:
    I had some problems too. The problem could be on /etc/fstab (when you mount the usb could send some errors… have a look to the syslog using “tail /var/log/messages/”)

    certofisboxer@gmail.com (email addie WITHOUT boxer ;) )

  3. Maya said,

    October 9, 2007 @ 3:40 pm

    Hi,

    Do you have a handout for how to add a internal hard drive.

    regards,

    Maya

  4. brett said,

    May 21, 2008 @ 9:54 pm

    Centos will automatically mount external hard drives via usb to /media/, well it did anyway on Centos 4.5 thanx

RSS feed for comments on this post · TrackBack URI

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word