Code Library
Home Submit Free Hosting Link To Us Contacts

Bash Adding a second hard drive to system

Bash Adding a second hard drive to system Bash Bash Adding a second hard drive to system Download (.zip)



#!/bin/bash

# Adding a second hard drive to system.
# Software configuration. Assumes hardware already mounted.
# From an article by the author of this document.
# 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 0






Bash Adding a second hard drive to system