Problem restoring from tar backup: why are there /dev/disk/by-id/ symlinks and how can I avoid them?
- by SK.
Hello,
I'm trying to make a bare-bone backup system with the most basic tools available on openSUSE 11.3 (in this case: bash, fdisk, tar & grub legacy)
Here's the workflow for my scripts:
backup.sh:
(Run from external system, e.g. LiveCD)
make an fdisk script ($fscript) from fdisk -l's output [works]
mount the partitions from the system's fstab [works]
tar the crucial stuff in file.tgz [works]
restore.sh:
(Run from external system, e.g. LiveCD)
run fdisk $dest < $fscript to restore partitioning [works]
format and mount partitions from system's fstab [fails]
extract from file.tgz [works when mounting manually]
restore grub [fails]
I have recently noticed that openSUSE (though I'm sure it has nothing to do with the distro) has different output in /etc/fstab and /boot/grub/menu.lst, more precisely the partition name is for example "/dev/disk/by-id/numbers-brandname-morenumbers-part2" instead of "/dev/sda2" -- but it basically is a simple symlink.
My questions about this:
what is the point of such symlinks, especially if we're restoring on a different disk?
is there a way to cleanly prevent the creation of those symlinks and use the "true" /dev/sdx everywhere instead?
if the previous is no, do you know a way to replace those symlinks on the fly in a text file? I tried this script but only works if the file starts with the symlink description (case of fstab, not menu.lst):
### search and replace /dev/disk/by-id/... to /dev/sdx
while read oldVolume rest; do # get first element, ignore rest of line
if [[ "$oldVolume" =~ ^/dev/disk/by-id/.*(-part[0-9]*$)? ]]; then
newVolume=$(readlink $oldVolume) # replace pointer by pointee, returns "../../sdx"
echo /dev/${newVolume##*/} $rest >> TMP # format to "/dev/sdx", write line
else
echo $oldVolume $rest >> TMP # nothing to do
fi
done < $file
mv -f TMP $file # save changes
I've had trouble finding a solution to this on google so I was hoping some of the members here could help me.
Thank you.