Hi mbertrand
OK, first of all, you will need some way to uniquely identify the target drive, otherwise all bets are off. I'm betting
you are going to say that adding a volume label to drive is inconvenient and that when you perform a restore
the drive may or may not already be partitioned. So here are some sample commands with results from my
machine which uses IDE drives. If you have SATA, you may have to make some changes. Either way, the
target drive must always be on the same port.
tc@box:~$ ls -l /dev/disk/by-path/*
lrwxrwxrwx 1 root root 9 Aug 10 11:42 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 Jun 6 09:50 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jun 6 09:50 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:0:0-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Jun 6 09:50 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:0:0-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Aug 10 11:42 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:0:0-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 Aug 2 12:06 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:0:0-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10 Aug 10 11:42 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:0:0-part6 -> ../../sda6
lrwxrwxrwx 1 root root 9 Aug 10 11:42 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:1:0 -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug 10 11:41 /dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:1:0-part1 -> ../../sdb1
lrwxrwxrwx 1 root root 9 Jun 6 09:50 /dev/disk/by-path/pci-0000:00:1f.1-scsi-1:0:0:0 -> ../../sr0
lrwxrwxrwx 1 root root 9 Jun 6 09:50 /dev/disk/by-path/pci-0000:00:1f.1-scsi-1:0:1:0 -> ../../sr1
lrwxrwxrwx 1 root root 9 Aug 10 12:09 /dev/disk/by-path/pci-0000:00:1f.2-usb-0:1:1.0-scsi-0:0:0:0 -> ../../sdd
lrwxrwxrwx 1 root root 10 Aug 10 12:09 /dev/disk/by-path/pci-0000:00:1f.2-usb-0:1:1.0-scsi-0:0:0:0-part1 -> ../../sdd1
lrwxrwxrwx 1 root root 9 Aug 10 11:42 /dev/disk/by-path/pci-0000:00:1f.2-usb-0:2:1.0-scsi-0:0:0:0 -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug 10 11:36 /dev/disk/by-path/pci-0000:00:1f.2-usb-0:2:1.0-scsi-0:0:0:0-part1 -> ../../sdc1
tc@box:~$
To retrieve the first IDE drive:
tc@box:~$ ls -l /dev/disk/by-path/* | grep -v "usb" | grep "0:0:0:0" | cut -d ">" -f 2 | cut -d / -f 3 | grep -v [1-9]
sda
tc@box:~$
The ls -l /dev/disk/by-path/* command lists all the drives including the link to their device name.
The first grep excludes any lines containing the word usb
The next grep includes any remaining lines containing the string 0:0:0:0
The first cut command splits those lines into two fields using > as a delimiter, returning the second field (the link)
The next cut splits what remains into three fields using / as a delimiter, returning the third field (the device name)
The last grep eliminates any results containing the number 1 through 9, which in this case leaves sda