Hi
First let me thank VolKer for the wonderful project. I am using for a while omv and i am very impressed. The only thing that is missing was backup and restore.
So i was searching for a way to backup and easily restore in case that my cf card was crashing. I saw an article in google that i can mirror a hard disk with rsync. I tried it and it is working very good until now. Let me say that i am not a linux expert and so i am waiting for suggestions or improvements. I am testing this in virtualbox with two disk 2GB each
So how did i do it. We assume that the omv is installed it in /dev/sda disk and the new disk is /dev/sdb. You will have to change the disks accordingly your setup. I advise everyone to remove the storage disks before doing anything and make a full bakup.
We plugin the second disk to the computer
We copy the partition table from the first disk to the new one for example.
Zitatsfdisk -d /dev/sda | sfdisk /dev/sdb --force
Format the root partition on the new disk
Zitatmkfs.ext4 /dev/sdb1
Format the swap partition on the new disk
Zitatmkswap /dev/sdb5
make a directory /mirror
Zitatmkdir /mirror
We find the uuid for the disk /dev/sdb1 with the following command. We are going to use the uuid from the second disk to mount it in the mirror directory
Zitatblkid
The output of the above command should be
Zitat/dev/sda1: UUID="e950ee97-27fd-4596-b0ce-b85d8480eacd" TYPE="ext4"
/dev/sda5: UUID="93d5cd61-cc4f-4251-8d8d-060adb500b5e" TYPE="swap"
/dev/sdb1: UUID="5b11c396-d08f-4b24-a2ac-081f0a65a7dd" TYPE="ext4"
/dev/sdb5: UUID="eed9ce7f-b2f4-47db-88ae-42e5eeea7b1d" TYPE="swap"
edit fstab and right before
Zitat# >>> [openmediavault]
add the following
ZitatUUID=5b11c396-d08f-4b24-a2ac-081f0a65a7dd /mirror ext4 errors=remount-ro 0 1
Be sure that you change the uuid with yours.
mount the second disk
Zitatmount -a
we make a file excudes.cfg in root directory with the name excudes.cfg. This is the file that we are going to use to exclude some directories in the rsync process.
Zitatvi /excludes.cfg
Zitat/mirror/
/tmp/
/sys/
/proc/
/mnt/
sync the disks with the following command
Zitatrsync -ax --exclude-from=/excludes.cfg --delete / /mirror/
make the directories that we have excluded in the excludes.cfg
Zitatmkdir /mirror/tmp
mkdir /mirror/sys
mkdir /mirror/proc
mkdir /mirror/mnt
Edit the fstab file in the mirror disk
Zitatvi /mirror/etc/fstab
and change the uuid to much the uuid for sdb1 and sdb5 and remove the mount point that we have created for the /mirror in my case the fstab looked like this
ZitatAlles anzeigen# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# / was on /dev/sda1 during installation
UUID=e950ee97-27fd-4596-b0ce-b85d8480eacd / ext4 errors=remount-ro 0 1
UUID=5b11c396-d08f-4b24-a2ac-081f0a65a7dd /mirror ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=93d5cd61-cc4f-4251-8d8d-060adb500b5e none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
tmpfs /tmp tmpfs defaults 0 0
# >>> [openmediavault]
UUID=eba12385-d7f9-434f-8f4a-e4a37aff4356 /media/eba12385-d7f9-434f-8f4a-e4a37aff4356 ext4 defaults,acl,user_xattr,noexec,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 0 2
/media/eba12385-d7f9-434f-8f4a-e4a37aff4356/ftp /home/ftp/ftp none bind 0 0
/media/eba12385-d7f9-434f-8f4a-e4a37aff4356/nfs /export/nfs none bind 0 0
# <<< [openmediavault]
after the changes looked like this
ZitatAlles anzeigen# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# / on /dev/sdb1
UUID=5b11c396-d08f-4b24-a2ac-081f0a65a7dd / ext4 errors=remount-ro 0 1
# swap on /dev/sdb5
UUID=eed9ce7f-b2f4-47db-88ae-42e5eeea7b1d none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
tmpfs /tmp tmpfs defaults 0 0
# >>> [openmediavault]
UUID=eba12385-d7f9-434f-8f4a-e4a37aff4356 /media/eba12385-d7f9-434f-8f4a-e4a37aff4356 ext4 defaults,acl,user_xattr,noexec,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 0 2
# <<< [openmediavault]
Now we have to make some changes to grub2 so we can boot from the other disk
We edit /etc/grub.d/40_custom to add a menu list in grub
Zitatvi /etc/grub.d/40_custom
and we add at the bottom the following. Be careful and change this statement set root=(hd1,1) and uuids accordingly with your setup. You can see the device map if you edit the /boot/grub/device.map.
ZitatAlles anzeigen#!/bin/sh -e
echo "Adding my custom Linux to GRUB 2"
cat << EOF
menuentry "My Backup OMV" {
set root=(hd1,1)
search --no-floppy --fs-uuid --set e950ee97-27fd-4596-b0ce-b85d8480eacd
echo 'Loading Linux 2.6.32-5-amd64 ...'
linux /vmlinuz root=UUID=5b11c396-d08f-4b24-a2ac-081f0a65a7dd ro quiet
echo 'Loading initial ramdisk ...'
initrd /initrd.img
}
EOF
Then update grub2
Zitatupdate-grub2
After that edit again the excludes.cfg and add the following in the bottom
Zitat/etc/grub.d/
/boot/grub/grub.cfg
in the end excludes.cfg should be like this
ZitatAlles anzeigen/mirror/
/tmp/
/sys/
/proc/
/mnt/
/etc/fstab
/etc/grub.d/
/boot/grub/grub.cfg
Now we should be able to reboot and boot from the backup disk
After you boot from the backup disk you will make the following changes so the backup disk should work even if the first disk is destroyed complete and you have to boot the backup disk without the first disk.
edit the 40_custom file
Zitatvi /etc/grub.d/40_custom
and change the statement set root=(hd1,1) to set root=(hd0,1)
Again change this accordingly your setup
Last thing update the grub2 on the backup disk
Zitatgrub-mkdevicemap
update-grub
grub2-install /dev/sdb
Now you should be able to boot from your backup device even if you remove your primary disk. You could also make cron job in your primary setup to sync your setups.
One thing is missing if you make a change in omv that involves the fstab you will have to manual edit the fstab in the mirror disk and add the values. I hope that someone gives us a script that we can include with rsync and make it fully automated.
I don t know if i am asking to much and if this possible but it could be a nice if someone could make a plugin that does the same thing.
Thanks an sorry if my English are bad