这是我目前在 Ubuntu 10.04 LTS 中使用 udev 系统和 rc 脚本 rc.local 安装 2 个外部 USB 2.0 驱动器的方法。
# 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
这将在每次启动时检测外部 USB 驱动器并将其指定为 /dev/backup500 /dev/backup501
我想从外部 USB 2.0 备份升级到 FireWire 备份。也许,我会将驱动器从现有机箱中取出,然后使用外部 FireWire 机箱来与这些 SATA 驱动器一起使用。
你知道,我每天备份大约 64GB 的数据,我需要更快的数据传输速率。此外,内置驱动器不是一个选择,因为我的体验很糟糕(我的主硬盘崩溃了,当时用于备份的另一个内置驱动器也崩溃了)
我该如何修改上面的脚本以用于火线接口?Ubuntu udev 系统是否支持火线设备?我是否应该等待 USB 3.0 实施并节省资金?
答案1
您是否考虑过使用 eSata 代替火线?如果您的主板有备用 SATA 插槽,那么它是最快的解决方案。有几种适配器可供您物理热插拔 SATA 驱动器(如果您的操作系统启用了该选项)。
答案2
FW 驱动器将是 sd*,因此您的脚本无需更改。单个磁盘达到 USB 2.0 的速度,除了供应商的利润外,切换不会带来任何好处...
千兆以太网上的 iscsi 将在火线上绕圈跳跃……(并用省下的钱给你买一辆车)
还请考虑磁带备份。媒体不会重命名。
必须有更好的方法来标记磁盘介质以满足您的目的。