LDP/LDP/guide/docbook/abs-guide/add-drive.sh

42 lines
1.1 KiB
Bash

#!/bin/bash
# Adding a second hard drive to system.
# Software configuration. Assumes hardware already mounted.
# From an article by the author of the ABS Guide.
# In issue #38 of _Linux Gazette_, http://www.linuxgazette.com.
ROOT_UID=0 # This script must be run as root.
E_NOTROOT=67 # Non-root exit error.
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
# Use with extreme caution!
# If something goes wrong, you may wipe out your current filesystem.
NEWDISK=/dev/hdb # Assumes /dev/hdb vacant. Check!
MOUNTPOINT=/mnt/newdisk # Or choose another mount point.
fdisk $NEWDISK
mke2fs -cv $NEWDISK1 # Check for bad blocks (verbose output).
# Note: ^ /dev/hdb1, *not* /dev/hdb!
mkdir $MOUNTPOINT
chmod 777 $MOUNTPOINT # Makes new drive accessible to all users.
# Now, test ...
# mount -t ext2 /dev/hdb1 /mnt/newdisk
# Try creating a directory.
# If it works, umount it, and proceed.
# Final step:
# Add the following line to /etc/fstab.
# /dev/hdb1 /mnt/newdisk ext2 defaults 1 1
exit