Add a Big Hard Disk - Next Time


When I replaced a hard disk, I used Hard Disk Upgrade Mini How-To as a guide. I replaced a disk rather than adding one and had no areas affected by system daemons, so I rearranged some of the steps and omitted others. I added steps I eventually found were unneeded relics of BIOS, Windows, and DOS legacies of the manufacturer's procedure. I created this reference from my notes for use next time.

I installed my disk on a Pentium II MMX 200 with 64 MB RAM and a recently-installed Red Hat 7.1 GNU/Linux system with the 2.4.2-2 kernel.

Please verify these steps before you follow them. I have not used this exact procedure so there may be errors. Read through the whole thing and modify it to your requirements before you start. There is no warranty, etc.

There are references at the bottom of this page.

1. You can check the status of your file system with df now and at most times in the procedure.

# df

Another alternative is to use watch df from another terminal or terminal window at most times.This provides an update every two seconds and is useful during copy and delete operations.

# watch df

2. If you are removing a disk to make way for the new one, copy all files to another drive. Do not allow these files to be used or changed while you are copying them. If you are copying areas that can be affected by system daemons, see Hard Disk Upgrade Mini How-To, 7. Copy the files from the old disk to the new disk. If you are copying areas that can be accessed by other users, block them by shutting down the services they can use.

The following copy command does not follow symlinks; it preserves file attributes, copies directories recursively, generates a line of output for each line copied, and stays on the same file system. First, su to root, then copy.

# su -l

# cp -avx data-from-old-drive/* data-parking

If you are paranoid, verify the copy with diff.

# diff --recursive data-parking data-from-old-drive

If you are truly paranoid, delete all data on the hard drive to be removed with rm or in Midnight Commander (mc). Be really careful and double check your commands and references or you could remove data that you want to keep.

3. To change or create mount points for the new drive, modify /etc/fstab accordingly. I like to use Midnight Commander and its editor. I also record all changes to /etc/fstab in my on-line log.

See the man page for fstab for information on the file format for fstab. In man, space bar advances a page, backspace returns to the previous page, and q quits.

I like to use xman instead of man when I am using Xwindows. It has a quirky menu system and way of scrolling with the mouse but I think it is easier to use than man because it provides easy access to a directory of man pages.

# mc

# man 5 fstab

# xman

4. Shutdown the system to a halt and power off. Remove the old hard disk if you are removing one and attach the new hard disk. The truly, truly paranoid can wipe out traces of data left by rm on the old drive with a bulk video tape eraser in about 30 seconds. This will also destroy any possible reuse of the drive.

5. Start up Linux. When the boot sequence encounters the new drive it will choke and offer to enter a diagnostic, single user mode if you enter the root password. You can choose that option and partition and make file system in that mode, or continue to the normal boot and perform those operations under your normal environment.

6. Partitioning should only be done on an unmounted file system, so verify that the drive is not on the list provided in df.

# df

As root, use fdisk to create Linux partitions on the new drive. I made only one partition with all the available space on the new drive. NOTE: Substitute the appropriate drive designation for hdc in the following lines or you will wipe out data on other drives. You are root!

# fdisk /dev/hdc

I use the "m" command under fdisk to review the commands and I use "p" to review my changes before I use "w" to write and exit. You could also catch errors in drive designation by observing unexpected values in the partition table with "p". For example, the correct drive should show no entries in the partition table when you first start fdisk and use the "p" command.

7. After partitioning the next step is to make a file system. This is termed formatting in the DOS/Windows world. I use the ext2 file system, default for Red Hat Linux 7.1. Again, make sure you have substituted the correct partition designation for hdc1 in the following line. mkfs gives you no verification options like fdisk does, so you could wipe out useful data with a typo. You are root!

# mkfs.ext2 -c /dev/hdc1

Use fsck to verify your work.

# fsck /dev/hdc1

If you created more partitions, make file systems on each of them and check them each in turn.

8. Mount the partition(s). If /etc/fstab has not been modified to reflect new mount points, do so now and create the mount points as required. Mount with the short form of mount, specifying just the device or just the mount point for each device in turn.

# mount /dev/hdc1

Use df to confirm the mounts.

# df

9. Copy data to new locations, adjusting the location and repeating as required. Watch the progress from another terminal with watch df if you like.

# cp -avx data-parking/* /data

# watch df

If you are paranoid, compare the data copied to the original, adjusting the location and repeating as required.

# diff --recursive data data-parking

10. Do whatever other tests you would like to assure the integrity of the data in their new location(s).

11. Delete old data from the old location(s). I like to use Midnight Commander. Double check your efforts; if you make a mistake you could delete useful data. You are root!

# mc

You can observe progress in Midnight Commander or from another terminal with watch df.

# watch df

12. Exit from root prompt. You are done!

# exit

Please send any comments or corrections to Dick through http://www.hodgman.org/contact/.


References:

I used the following to help me wade through this process:

Linux Documentation Project
The Linux System Administrators' Guide
: Chapter 6: Using Disks and Other Storage Media
Categorized List of HOWTOs
Hard Disk Upgrade Mini How-To (a helpful walkthrough covering even more than I needed)
Linux Partition HOWTO
Large Disk HOWTO
Man Pages, All: df watch diff fstab rm man fdisk mkfs fsck mount umount exit
Help: try # su --help or # cp --help. mc has menus and an internal help system.


Last modified on 2003 January 09

Valid XHTML 1.0! Valid CSS!