Last week I added a second hard disk to an IBM eServer xSeries 226 server running CentOS 4.4.
I picked up a large hard drive in January, but I didn’t have the proper hardware to install it right away.
Besides that, I had to settle on how to partition the drive, create the filesystems, and decide on the mount points.
Since the overall process did take me some time, I figured I’d share some notes on the steps I took for folks interested in doing the same. I’ve also provided links to resources that helped me out along the way.
Planning is the lion’s share of the work. Once you’ve decided what to do, the actual addition of the drive and the execution of the commands is fairly straightforward.
- Determine why you need another hard drive
It’s always nice to have more space, but beyond that I had some more practical concerns.
The server came with a single 80GB disk. When I installed CentOS, I was quite lazy and settled on a small swap partition with a large root partition taking up the rest of the disk.
So, there were at least four reasons guiding my decision to add another drive:
- To prevent the single root filesystem from filling up and rendering the machine unusable. This could happen since I have nightly cron jobs that sync backups (large media files) from my workstation to the server. It might also happen if my machine was suddenly hit with a burst of traffic or a DOS attack.
- I didn’t want to resize the existing disk partition or reinstall the operating system. I felt more comfortable creating overflow filesystems on a blank disk.
- I wanted to provide a measure of redundancy in case the first hard drive failed. Based on rumors from colleagues and other unscientific anecdotes, Maxtor hard drives are more prone to failure. There’s also the small matter of my server sitting on the floor of a dusty basement next to the litter box.
- To limit different types of disk activity to different partitions. For example, logging (writes to large files) is a different usage pattern than Web serving (reading lots of little files). I wanted a measure of control about how to optimize I/O.
- Find the right drive for your server
Given that my machine had only one free SATA bay, my strategy was to get the largest drive possible for around $100.
A great tool for analyzing your current system to determine its current configuration and potential for expansion is Hardware Lister (lshw). This will give you specific model information and insight into where you might expand your system.
Pipe the output of this command to a text file, so that you’ll have the information readily available. This will guide your upgrade decisions and serve to verify installation later.[firstname.lastname@example.org]# /usr/sbin/lshw > /root/lshw-before.txt
Based on this information, I was able to Google compatible drives for the machine, and found a solid price on a Western Digital 400MB SATA drive at Newegg.
- Make sure you have the right hardware to install the drive
Hard drives are often sold in Retail or OEM packaging. Retail comes in a pretty box and will include the essential hardware bits, such as cables and fasteners. OEM is the way to save some cash if you’re replacing an existing drive or have extra hardware for your box.
Along with an anti-static wrist strap, a Torx T10 screwdriver came in quite handy.
- Install the drive and make sure it’s seen by the kernel
DISCLAIMER: If you intend to add a hard drive to your system, please take all due precautions before starting, as there is a real possibility that you will lose some data.
I shut down the machine, removed the power cable, slid the drive in, closed it up, then booted back up.
I then ran lshw again. Comparing this with the prior snapshot of the system, I could verify that the drive was recognized as /dev/sdb.[email@example.com]# /usr/sbin/lshw > /root/lshw-after.txt
[firstname.lastname@example.org]# diff /root/lshw-before.txt /root/lshw-after.txt
- Create the partitions
Through trial and error I had settled on a reasonable filesystem layout for my previous Sun systems. Solaris has very impractical defaults for my purposes, so I needed to do some leg work in the past to make sure I had enough space in the right places.
This is what my latest Solaris 10 partitioning scheme looks like:
c0t0d0 (~20GB) 0 / (~8GB) [c0t0d0s0] 1 3 4 /swap (~1GB) [c0t0d0s4] 5 6 7 /export/home (~10GB) [c0t0d0s7] c0t2d0 (~80GB) 0 /var (~25GB) [c0t2d0s0] 1 3 4 /opt (~25GB) [c0t2d0s4] 5 6 7 /usr (~25GB) [c0t2d0s7]
If I was doing a fresh Linux operating system install today, I might choose something similar. But given that I was upgrading an existing system, I decided only to offload what was in the /var and /home directories.
Using fdisk, I decided to slice up the 400GB hard drive like so:
- New primary partition of 50GB at /dev/sdb1 (for /var/www)
- New primary partition of 50GB at /dev/sdb2 (for /var/log)
- New primary partition of 50GB at /dev/sdb3 (for /var/mail)
- New primary partition of 200GB at /dev/sdb4 (for /home)
- Create the filesystems
There are several options for filesystems, but ext3 seems to be the sweet spot for most Linux usage scenarios.
I formatted each of the partitions as ext3 using the following command. (From this point on I’ll only show the commands for one of the four new partitions).[email@example.com]# /sbin/mkfs -t ext3 /dev/sdb1
- Mount the filesystems
To make the new filesystems accessible, I mounted each to a location under /mnt.[firstname.lastname@example.org]# mount -t ext3 /dev/sdb1 /mnt/var/www
At this point, all I saw in each new mounted directory was a “lost+found” folder.
- Copy over data to the new filesystem
Now that the new filesystem is ready for use, I needed to move the existing directories to it.
To make sure nothing is being written to the source filesystem, I dropped to single user mode.[email@example.com]# init 1
I then copied data from the source filesystem recursively while preserving file metadata, such as owner and last modified time.[firstname.lastname@example.org]# cd /var/www
[email@example.com]# cp -ax * /mnt/var/www
I verified quickly to make sure everything was copied. You might want to check things more thoroughly than this however.[firstname.lastname@example.org]# find /var/www | wc -l
[email@example.com]# find /mnt/var/www | wc -l
Moved the source directory so I could mount the new filesystem in its place.[firstname.lastname@example.org]# mv /var/www /var/www.old
Mounted the new filesystem and returned to multi-user mode.[email@example.com]# mkdir -p /var/www
[firstname.lastname@example.org]# umount /mnt/var/www
[email@example.com]# mount -t ext3 /dev/sdb1 /var/www
“System Administration Toolkit: Migrating and moving UNIX filesystems,”
“Partitioning in action: Moving /home” and
“Partitioning in action: Consolidating data” are good resources which document these steps.
- Add the drive to fstab
Everything looked good, so I mapped the new filesystems permanently and rebooted the box.[firstname.lastname@example.org]# vi fstab
/dev/sdb1 /var/www ext3 defaults 0 0
In a few days, once I’m satisfied that everything is working as planned, I’ll archive the old directory and remove it to save space.[email@example.com]# rm -fr /var/www.old
And that’s it. Once I had a plan, everything went very quickly. The recursive copy from the source directory to the new destination was probably the longest command timewise, mainly because I had 40GB already in my home directory, but even that step took less than half an hour.
Here are some more resources I consulted when adding my new hard disk.
- “My partition is full! Do I need to reinstall?“
- “How to Add New Hard disk to Linux Machine“
- “How can I add new hard disk after I’ve installed Linux?“
- “Tutorial: Adding Additional Hard Drives in Linux“
I also owe thanks to Martin Corona for doing a sanity check on my setup.