Comments on Ghosting The Machine
Ghosting The Machine This is a short but potentially extremely handy guide to ghosting one Linux box to another (or simply making a full backup of a desktop/server). You might have a small office where you customise one desktop just how you like it and need to roll this out to N other PC's or simply want a backup of a server or desktop to another machine or even to an image file. The main tool here is netcat which is extremely powerful and has a multitude of other great uses that won't be covered here.
23 Comment(s)
Comments
pv is a program that graphically displays the progress/status of data going through a pipe. install it and try "pv cat /dev/random > /dev/null"
Many thanks for this. So neat and simple!
Even better - thanks;)
I prefer Clonezilla for server/desktop backups. It can backup to usb drive, ssh server, nfs server or local disk. One of the best features is it can restore an image to a different size hardrive, bigger or smaller as long as the data fits. It also only copies "used space" whereas the dd command will copy the entire drive including empty space. Clonezilla is very easy to use, similar to the windoze Ghost program but open source and free :) To learn more checkout http://clonezilla.org cheers -m
If you zero out the unused space (aka dd if=/dev/zero of=/loc/of/mounted/drive/to/be/cloned/zero; rm zero;) THEN compress the image through gzip, you will essentially be making a clone of just the used space. I've done this to drives that were 500gb with only 30gb being used and the resulting image was 24ish gbs. Works like a charm...
Hi,
Yes the target is booted from CD. Unless you just want the image file then no CD required of course. The target just needs nc which comes with most distros.
Cameron
You could always throw in a pv, as in
dd if=/dev/sda | pv | nc 192.168.0.20
What does the | pv | stand for? Thanks
If one ghost a Debian linux from a server to a harddisk, will this work if the harddisk be simply plug into another server, regardless of configuration and make, since the mother board, CPU, RAM and other components may be diffrent?
Thanks
Hi,
Should work. I have ghosted to different hardware fine. Only sometimes there might be xorg issues which can be fixed.
Debian has awesome hardware dtection so should be fine:)
Cameron
There are no guarantees, but I have noticed Linux does a good job of booting on a different machine configurations. What I have seen is that I can usually move a hard drive from one machine to another and Linux boots fine.
With Windows the installation ends up being pretty specific to the machine configuration it is installed on, though I have multiple times done "repair installations" that have allowed me to move a drive to a new PC and keep the old installation (it seems to mostly just update the drivers.)
So to answer your question, with Linux (Debian) you probably would have good luck with this but I can't say for sure.
Why not just use mkcdrec? Get a backup onto CD/DVD/network, etc. and allows you to do a bare-metal recovery as well? Don't have to worry about size of disk, or machine. As long as the machine is in the same "family", works fine. Much better for roll-outs, IMHO.
http://sourceforge.net/projects/mkcdrec/files/
and
http://mkcdrec.ota.be/
This is pretty slick. Simple and easy. Question though - is the target PC's OS booted off the hard disk or a CD?
Ability to transfer files between different filesystem types (as well as different disk/partition sizes, depending purely on available space).
My tool of choice for bulk backup/restore and transfer of files is rsync. It does file-level backups, not image backups. But Linux is such that you can do a file-level transfer of an OS installation and still have it work. Only people who spend too much time with Windows think that an image backup is necessary for this!
Advantages of file versus image backups:
* Automatic support for all filesystem types that your kernel will support.
* Ability to transfer files between different filesystem types (as well as different disk/partition sizes, depending purely on available space).
* Ability to confirm the copy was successful just by running the command again; in this case, rsync will do an incremental transfer, and if it reports nothing to do, then you know you got everything.
* Fast incremental transfers over a network .
Your right, but...
You'll have to install grub into the boot sector of the new box, I usually do this with a command like:
dd if=/dev/hda bs=512 count=1 | {netcat}
Or, you could chroot the the mount point on the new box and run grub-install.
Assuming you have an ssh server running, which is more secure than opening a port to anyone:
If the target machine or network is the limiting factor:
dd if=/sourcepath/sourcefilename | gzip | ssh user@desthost "dd of=/targetpath/backup.img.gz"
If the source machine is the limiting factor:
dd if=/sourcepath/sourcefilename | ssh user@desthost "gzip > /targetpath/backup.img.gz"
If you are wanting to use netcat, just break up the commands above and use the netcat commands from the original post.
eg
dd if=/sourcepath/sourcefilename | gzip | nc 192.168.0.20 30 if the target or network are the limiting factors
or
nc -l -p 30 | gzip | dd of=mybackup.img.gz
only compress it at one end as compressing something twice is generally little gain over compressing once.
How can you compress it on the fly ?
What about using clonezilla and drbl? just do the initial image creation, not the push from the server to the clients.
or pxe boot into clonezilla live, plug in a usb drive and go from there.
Can nc be used to ghost/backup/image a live server?
Thanks
Can I use this to make a copy of all OS from one server to another without shutting down/umount the source? Is this safe to do dd if=/dev/sda on a running source server ? I have some critical servers that i need to replicate without downtime.
This is a very very very handy How to! Thanks :)
Can i send the ghost image to another system through the internet?? What if the back up server is not on my LAN??
If the target system has a disk of different size, with bigger partitions for example, you can use:
http://positon.org/clone-a-linux-system-install-to-another-computer