I'm trying to backup a linux system to an IMG file that I can then boot and run in QEMU.
NOTE: I have tested on Lubuntu and tiny core linux.
The process I have followed is:
- I have 2 hard disks,
sda
andsdb
- partition
sdb1
and mountsdb1
partition in/mnt/sdb
dd
an empty file the size ofsda
to IMG file in the mountedsdb
directory.dd if=/dev/zero of=/mnt/sdb/disk.img bs=x count=1
- x being the size ofsda
- I then use
fdisk
onsda
to output the disk layout to a script file and then load that into thedisk.img
file - Then mount it and copy the contents - losetup -P -f disk.img
find the loop device
e.g /dev/loop36 0 0 0 0 /mnt/sdb/disk.img 0 512
created the filesystem on the first partition of the loop device -
mkfs.ext2 /dev/loop36p1
- mount the partitioned loop device -
mount /dev/loop36p1 /mnt/img
- then copy the bootsector -
dd if=/dev/sda of=disk.img bs=512 count=1 conv=notrunc
finally I used rsync to copy over the filesystem to the
/mnt/img
directory, I've had varying success with this. using:$ rsync -aHxv / \ --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \ /mnt/img
I've tried the exact process using Lubuntu as shown above, the rsync
command worked however when I try and run the IMG in QEMU it hangs at booting from the hard disk.
When trying the process above in tcl - the rsync
command fails and when I try to boot in QEMU it says there is no bootable device.
Does anyone have any advice regarding this? or has done similar things and has a better method to achieve the goal?