Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know very little when it comes to linux but I'm looking to construct a cheap disk duplicator out of an old server that we have. The server is currently running Ubuntu 12.04LTS and has 8 hot swappable disk bays. Ideally this is what I would like to happen.

I would like to have any new disk that is plugged into the server imaged from a master disk, lets say /dev/SDB. I know I can run the following command to initiate the copy but I would like to know if there is a way to automate it. If a new drive is connected/detected, have it run the command to image using a variable for the new drive. The source drive will always be sdb and the destination would theoretically be /dev/sdc to /dev/sdg depending on how many drives are in the server at that time.


dd if=/dev/sdb of=- | tee >(dd of=/dev/sdc) >(dd of=/dev/sdd) >(dd of=/dev/sde)

If an action/script could run on new hardware/hard drive detections, could it do something like this...

if /dev/sdc/ connected/detected
sleep 5 minutes     -gives time to connect multiple drives before imaging
Check for /dev/sdc   (if /dev/sdc not exist)
-if not connected goto exit
Check for /dev/sdd   (if /dev/sdd not exist)
-if not connected command1
Check for /dev/sde   (if /dev/sde not exist)
-if not connected command2
and so on

dd if=/dev/sdb of=- | tee >(dd of=/dev/sdc)
goto exit

dd if=/dev/sdb of=- | tee >(dd of=/dev/sdc) >(dd of=/dev/sdd)
goto exit

any and all help would be appreciated. I don't know if there is a way to execute a script on new hardware/drive detection.

share|improve this question
I don't know about auto-detection except it is related to udev. However, here is some food for thought. Why duplicate the whole hard drive including the empty space as this wastes incredible amounts of time. Software like Clonezilla can copy just the used portions. Second, have you thought of a real imaging server with the ability to clone without removing the hard drive over the network? I do this all the time. Using multicast you can clone 25 pc at almost the same time as 1-1.5 computers. Are you interested in learning more? – cybernard Aug 29 '13 at 3:31
Well we have a normal imaging service in place over our network. I'm now looking into a solution to where I can image a drive and ship them offsite. This way a machine does not have to come back in house for repairs. A tech can also bring these drives with them to, more or less, plug and play. Arrive onsite, plug in the imaged drive, join domain and leave. Machine doesn't need to leave the clients office. I've looked into clonezilla before and there doesn't seem to be an option to image 1 disk to many. Its more of a 1:1. You can go from 1:many using images. I also don't see any automation. – Mpit52 Aug 30 '13 at 11:46

You can use udev rules to accomplish this (see man 7 udev). First create a file called 10-disk-imaging.rules in /etc/udev/rules.d/, then add this line to it:

KERNEL=="sd[c-g]" RUN+="/path/to/dd/script %k"

This line will match any disk with kernel name sdc-g and then run /path/to/dd/script %k, where %k is the device name given by the kernel (i.e. sdc). Then, just create a script that takes a device name and performs the actual duplication.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .