Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have a number of Xen virtual machines that use disk image files.

disk = ["file:/xen/vbd/something.vbd,sda1,w"]

We'd like to use DRBD to replicate these files for backup (as opposed to the mess of MySQL replication and nightly rsyncs we have at the moment). But I don't seem to understand how to make it work.

We can bind a file to a loopback device with losetup:

# losetup /dev/loop0 /xen/vbd/something.vbd

And point DRBD to that device:

device  /dev/drbd1;
disk    /dev/loop0;

But the loopback isn't stable - it isn't there on reboot, and could easily have been attached to loop1, loop2 etc. It isn't exactly a valid option for a server if it needs human interaction to recover with a power interruption.

What am I missing?

share|improve this question

4 Answers 4

What do you mean with the "the loopback isn't stable"? What if you just create a shell script containing something like

losetup /dev/loop0 /xen/vdb/something.vdb
losetup /dev/loop1 /xen/vdb/something2.vdb
losetup /dev/loop2 /xen/vdb/something3.vdb

and put that at system startup before the xen guests start (or use some more official way to setup permanent loopback images, haven't done that)? Wouldn't the /dev/loop0 always point that the same image then? What am I missing? :)

share|improve this answer
    
I guess what I'm asking is, is there a recommended way? Am I doing it wrong by just hooking up the loopback myself? –  Marcus Downing Jul 30 '10 at 12:04
    
By not "stable", what I mean is that there's nothing stopping some other program from grabbing loop0 simply because it's the next one. If there was a way to make loop devices that were named rather than numbered, that would help. –  Marcus Downing Jul 30 '10 at 15:38

you can create a init script that creates the loop device at startup. Something like this.

share|improve this answer
    
Broken link... stackoverflow and friends recommend you copy/paste the relevant portions. –  cmc Mar 1 '13 at 14:10

There is always the old-fashioned way:

mknod /dev/loop255 b 7 255
losetup /dev/loop255 mydisk.img

Use a high random number to avoid a potential conflict.

share|improve this answer

Here's my bare bones loop device init script. Tested on Debian Squeeze.

### BEGIN INIT INFO
# Provides:          drbd_loopbacks
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

XEN_PATH=/home/xen/domains
DRBD_PATH=/home/drbd

case "$1" in
start)
  losetup /dev/loop45   $XEN_PATH/int/disk.img
  losetup /dev/loop63   $DRBD_PATH/meta.img
  ;;

stop)
  losetup -d /dev/loop45
  losetup -d /dev/loop63
  ;;
*)
  echo $"Usage: $0 {start|stop}"
  exit 1
esac
share|improve this answer

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.