Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Here is my current recipe for mounting 2 external USB 2.0 drives using the udev system and the rc script rc.local in Ubuntu 10.04 LTS.

# Become root
su

# Find USB devices.
# Search for sd
# :/sd
dmesg | less

# Find out what partitions are currently mounted
df -h | less

# Find out where the different(i.e. Windows,NTFS,ext3) volumes are in the partition table
fdisk -l | less
#  
#  Disk /dev/sda: 160.0 GB, 160041885696 bytes
#  255 heads, 63 sectors/track, 19457 cylinders
#  Units = cylinders of 16065 * 512 = 8225280 bytes
#  Sector size (logical/physical): 512 bytes / 512 bytes
#  I/O size (minimum/optimal): 512 bytes / 512 bytes
#  Disk identifier: 0x00062bd5
#  
#     Device Boot      Start         End      Blocks   Id  System
#  /dev/sda1   *           1       19269   154778211   83  Linux
#  /dev/sda2           19270       19457     1510110    5  Extended
#  /dev/sda5           19270       19457     1510078+  82  Linux swap / Solaris
#  
#  Disk /dev/sdb: 500.1 GB, 500107862016 bytes
#  255 heads, 63 sectors/track, 60801 cylinders
#  Units = cylinders of 16065 * 512 = 8225280 bytes
#  Sector size (logical/physical): 512 bytes / 512 bytes
#  I/O size (minimum/optimal): 512 bytes / 512 bytes
#  Disk identifier: 0x00000000
#  
#     Device Boot      Start         End      Blocks   Id  System
#  /dev/sdb1               1       60801   488384001   83  Linux
#  
#  Disk /dev/sdc: 500.1 GB, 500107862016 bytes
#  255 heads, 63 sectors/track, 60801 cylinders
#  Units = cylinders of 16065 * 512 = 8225280 bytes
#  Sector size (logical/physical): 512 bytes / 512 bytes
#  I/O size (minimum/optimal): 512 bytes / 512 bytes
#  Disk identifier: 0xde504d75
#  
#     Device Boot      Start         End      Blocks   Id  System
#  /dev/sdc1               1       60801   488384001   83  Linux

# See properties of sd. devices
udevadm info --attribute-walk --name /dev/sdb1
udevadm info --attribute-walk --name /dev/sdd1

udevadm info -a -p `udevadm info -q path -n /dev/sdb1` | grep -e "SUBSYSTEM==" -e "KERNEL==" -e "ATTR{partition}==" -e "ATTR{size}==" -e "ATTRS{serial}==" 
#   KERNEL=="sdb1"
#   SUBSYSTEM=="block"
#   ATTR{partition}=="1"
#   ATTR{size}=="976768002"
#   ATTRS{serial}=="2HA4DF8P    "
#   ATTRS{serial}=="0000:02:0a.2"
udevadm info -a -p `udevadm info -q path -n /dev/sdc1` | grep -e "SUBSYSTEM==" -e "KERNEL==" -e "ATTR{partition}==" -e "ATTR{size}==" -e "ATTRS{serial}==" 
#   KERNEL=="sdc1"
#   SUBSYSTEM=="block"
#   ATTR{partition}=="1"
#   ATTR{size}=="976768002"
#   ATTRS{serial}=="2HA16NDX    "
#   ATTRS{serial}=="0000:02:0a.2"

# External hard drives
# d - delete all existing partitions
# n - add a new partition
#     p  - primary partition 
#     1  - partition number 1
#     83 - partition type: 83 Linux
# w - write table to disk and exit  
fdisk /dev/sdb
fdisk /dev/sdc

# Create ext2 filesystems on USB drives and format them
# I create ext2 not ext3 because for a while there was
# only ext2 filesystem support on Windows.
# I wanted to be able to read the filesystem from a
# Windows machine.
# Your needs may be different.
mkfs.ext2 /dev/sdb1
mkfs.ext2 /dev/sdc1

# Determine kernel version (see below)
uname -r

# Instruct udev to make symlinks for the drives based on the manufactor,
# size, or any number of properties about the device. That symlink will
# always point to that device regardless of what device node
# (ie /dev/sda, /dev/sdb) it ends up getting assigned. Then you can modify
# your fstab to use the symlink vs the device node, which in turn allows
# you to always address the device the same way.
# Put a hard return at the end so it would print
cat > /etc/udev/rules.d/85-usb-hd-fix.rules <<'EOF'
# Udevadm info starts with the device specified by the devpath and then
# walks up the chain of parent devices. It prints for every device
# found, all possible attributes in the udev rules key format.
#
# A rule to match, can be composed by the attributes of the device 
# (first paragraph or block of rules)
# and the attributes from one single parent device.
# (any paragraph or block of rules following the first paragraph or block of rules)
#
# For example, below we see some of the attributes of the device listed first
#   SUBSYSTEM
#   KERNEL
#   ATTR{partition}
#   ATTR{size}
# and the attribute from one single parent device listed last
#   ATTRS{serial}

# backup500
SUBSYSTEM=="block", KERNEL=="sd?1", ATTR{partition}=="1", ATTR{size}=="976768002" , ATTRS{serial}=="2HA4DF8P    ", SYMLINK+="backup500", GROUP="disk", MODE="0660"
# backup501
SUBSYSTEM=="block", KERNEL=="sd?1", ATTR{partition}=="1", ATTR{size}=="976768002" , ATTRS{serial}=="2HA16NDX    ", SYMLINK+="backup501", GROUP="disk", MODE="0660"

EOF

# Change the attributes of the udev rules file
chmod 644 /etc/udev/rules.d/85-usb-hd-fix.rules

# Test udev
udevadm test /sys/block/sdb block
udevadm test /sys/block/sdc block

# Test udev
restart udev

# Install kernel for PentiumPro
sudo apt-get install linux-686

# Create the mount points
mkdir -p /mnt/backup500
mkdir -p /mnt/backup501

# Make sure that the external USB drives (identified by the udev system) 
# are not referenced in /etc/fstab
# 
# The current /etc/fstab file looks like:
cat /etc/fstab
# Should look like
# # /etc/fstab: static file system information.
# #
# # <file system> <mount point>   <type>  <options>       <dump>  <pass>
# proc            /proc           proc    defaults        0       0
# # /dev/sda1
# UUID=fb518094-0d3b-42f4-a1cc-a3fa659fcd8a /               ext3    relatime,errors=remount-ro 0       1
# # /dev/sda5
# UUID=b04dba06-114e-0fa5-f823-75a116ae2fc0 none            swap    sw              0       0
# /dev/scd0        /media/cdrom0    udf,iso9660 user,noauto,exec,utf8 0       0
# /dev/fd0         /media/floppy0   auto    rw,user,noauto,exec,utf8 0       0

# Install sdparm
apt-get update
apt-get install sdparm

# See the current state of the STANDBY drive flag
sdparm -al /dev/backup500
# This should be 1 (on/true/enabled)

# Set STANDBY to 0 (off/false/disabled)
sdparm --clear STANDBY -6 /dev/backup500

# See the current state of the STANDBY drive flag
# This should be 0 (off/false/disabled)
sdparm -al /dev/backup500

# Modify script /etc/rc.local to mount all filesystems in /etc/fstab
cat > /etc/rc.local <<'EOF'
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Set STANDBY to 0 (off/false/disabled) only on the Maxtor OneTouch enclosures
sdparm --clear STANDBY -6 /dev/backup500
sdparm --clear STANDBY -6 /dev/backup501

# Mount USB drives
mount -t ext2 -o rw,auto,user /dev/backup500 /mnt/backup500
mount -t ext2 -o rw,auto,user /dev/backup501 /mnt/backup501
exit 0

EOF

# Change the attributes of the udev rules file
chmod 755 /etc/rc.local

# Reboot
shutdown -r now

# The following should already be mounted automatically after the reboot
# If not mounted, mount manually
# mount /mnt/backup500
# mount /mnt/backup501

# Create or rename directories
# mkdir -p /mnt/backup501/backup501/files
# mkdir -p /mnt/backup500/backup500/files

# Create symbolic links
# /home/backup500  -> /mnt/backup500/backup500
# /home/backup501  -> /mnt/backup501/backup501
ln -s /mnt/backup500/backup500 /home
ln -s /mnt/backup501/backup501 /home
# To remove the links
# unlink /home/backup500
# unlink /home/backup501

This will detect the external USB drives on boot every time and assign them as /dev/backup500 /dev/backup501

I'd like to upgrade from exteral USB 2.0 backups to firewire backups. Maybe, I'll take the drives out of the existing cases and get external firewire cases to use with these SATA drives.

You see, I'm backing up about 64GB of data daily and I need a faster data transfer rate. Also, internal drives are not an option as I had a bad experience (my primary HD crashed and the other internal drive used for backup at the time also crashed)

How can I modify the script above for a firewire interface? Does the Ubuntu udev system support firewire devices? Should I wait for USB 3.0 to be implemented and save my money?

share|improve this question

2 Answers 2

Have you considered eSata instead of firewire? Its the fastest solution if your motherboard has a spare sata socket. There are several adapters available that let you physically hot-swap sata drives (if your OS has that option enabled).

share|improve this answer
    
eSata is really awesome! I've read somewhere that it's three times as fast as USB 2. That's probably what I'll use in the future for backups to external hard drives. –  Dean Toader Feb 13 '12 at 23:58

FW drives will be sd*, so no change needed in your scripts. One single disk reaches about the speed of USB 2.0, no gain from the switch except the profit of your vendor...

iscsi over gigabit ethernet will jump around the firewire in circles... (and buy you a car for money saved)

Also consider tape backup. Media is not renaming then.

There must be better way to LABEL disk media for your puprose.

share|improve this answer
    
You are absolutely right about tape backups. I can't afford them though. The external hard drives will crash every once in a while but they're cheap to replace and have big capacity. Also, Ubuntu will run autofsck on these drives on boot up allowing me to be lazy. My uptime has to be short with weekly reboots but oh well... I'd rather reboot often and know that my backup media is good than not reboot and have a long uptime. –  Dean Toader Feb 13 '12 at 23:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.