Newbie - CP Question


How can I make a backup of my whole linux drive, I've got hda2 and hda5 which has data, how can I back these up to a local hard drive set as slave (hdb1) I don't need compression at all, can I use cp or dd? If I copy my data back will my linux work again if I backed up the mbr as well?

Just another thing, how can I show a picture in another tty session while cp or dd or copy process runs on tty1?


Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

jlevieConnect With a Mentor Commented:
> The machine I'm booting it on is an OS/2 box

You should have said that in the question, because it changes everything. From a linux boot you'll only be able to use dd to do this backup.

What you'd want to do there is 'dd if=/dev/hda of=/dev/hdb1/disk.img which will get everything (the MBR, hda2, & hda5). That means of course that /dev/hdb1 must be at least as large or larger than hda. The restore would simply be the inverse of that (dd if=/dev/hdb1/disk.img of=/dev/hda).

I'd recommend that you test the restore onto a a different disk before wiping out your OS/2 system.
The best way would be to use dump (see 'man dump' for details). You can write the dump image to a file(s) on hdba1, or by using a pipe to restore write each file system to a separate partition on hdb. The MBR won't be copied using that method, but it is easy to reset it from a floppy or rescue boot.

Linux supports multiple consoles (Ctrl-Alt-F2, Ctrl-Alt-F3, etc) so you can run the backup in in one session and do something else in another.
reaper_11Author Commented:
can you maybe gove me an example of how dump works? how long will dumpp take on an 8 gig drive...

The diffrent session thing: I want to automate it and not push alt+F2 etc. while dump runs in tty1 I want to write "echo hello" in tty2 atomatically?
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Since dump only operates on the actual data in use how long it would take depends on how much of that 8Gb is actually used. When I do this on my laptop across the network (100Mbps) to another system it takes a few of hours. That's a total of about 15Gb.

I don't know what Linux version you have and whether it & dump supports large files (greater than 2Gb) or not. But in its simplest form you might do something along the lines of:

mkdir /mnt/backup
mount /dev/hdb1 /mnt/backup
dump 0af /mnt/backup/root-fs.dump /
dump 0af /mnt/backup/home-fs /home

To avoid the "open files" problem where a file changes during a backup I like to do my backups with the system in single mode when using dump or tar. Commercial products like Legato Networker can do backups that are valid even if a file changes during the backup.
reaper_11Author Commented:
Thanks for the help!!!

So if I have a HDA2(Primary) and a HDA5(Logical) and another drive local HDB1(set as slave) I can do the following:

mkdir /mnt/src2
mkdir /mnt/des
mount /dev/hda2 /mnt/src1
mount /dev/hda5 /mnt/src2
mount /dev/hdb1 /mnt/dest

dump 0af /mnt/dest/backup /mnt/src1

What does the 0af do?

Thanks again!
I presumed that hda2 & hda5 are already mounted, probably as / & maybe /home or /usr. So all you need to do is mount hdb1, do the dumps, and then unmount it. You can take the system down to run level 1 (single user mode) and back up to 3 or 5 without even rebooting. If it's done that way the Linux file system will remain mounted. Done this way you can script this process so that it is run from cron when it won't interfere with normal use.

0 - do a level zero dump, which is a full dump of all data
a - write until end of media is seen, i.e., don't assum the media is of fixed (known) length
f - the output filespec for the dump follows
reaper_11Author Commented:
so all I do is mount hdb1 mount /dev/hdb1 /mnt/dest and then dump it
dump 0af /mnt/dest/image.img /

how can I extract the above image.img? if my drive fails, how can I copy the data back to hda1 (new drive), will it wirk if I dump the data back to the nw hda1 and restore the boot record then restart?

Thanks again
Restoring things gets a little more interesting. The worst case is if hda dies. In that case the first step is to boot into rescue mode from a distro CD or any of the mini-linuxen (Knoppix, tomsrtbt, etc) and partition the new disk, make file systems and swap (see 'man mke2fs' & 'man mkswap'), and then restore the data. For that you use, surprisingly, 'restore'. As an example assuming that we are in rescue mode and the file systems have been created you could do:

mkdir /mnt/disk
mount /dev/hda2 /mnt/disk
mkdir /mnt/backup
mount /dev/hdb1 /mnt/backup
cd /mnt/disk
restore rvf /mnt/backup/root-fs.dump
rm restoresymtable

When all of the data has been restored you'd do:

chroot /mnt/disk

to re-create the MBR.
reaper_11Author Commented:
Hi jlevie  

Thanks alot for your time and patients! This will be the last post then I will accept your answer. Please try helping me out as much as you can. The reason I asked the question in the first place is becaause I want to do the following:

Background: I've got a live linux cd, ISO Linux that just boots and extracts, no install. The machine I'm booting it on is an OS/2 box with 1 physical drive that's split into 2 partitions both 7.98 Gb (HDA2 - Physical) and (HDA5 - Logical) with the filesystem as HPFS. Like I said before, I want to do the following:

1.) Make a backup of the whole hard drive (the 2 partitions) I think I can use dump, onto another local disk (HDB1)
2.) I want to back up the partition tables and mbr onto another local disk (HDB1.) I then want to FDISK the whole drive, then with my ISO linux make a script that runs on startup and creates 2 partitions on the drive as above (HDA2) and (HDA5) and format the 2 partitions as HPFS and then restore the data, I can prob. do this with the restore command like you said.
4.) I want to restore the partition tables and MBR

Every thing gets backed up onto the extra local physical drive (HDB1), So basically a breakdown would be to back the drive as is, fdisk it so there's no filesystem and restore everything so that it operated like normal before I did the back up with dump...

I've read up and I think I can back up the partition table and MBR with:
cd /root
mkdir partition-backup
cd partition-backup
dd if=/dev/hda of=backup-hda.mbr count=1 bs=512

sfdisk -d /dev/hda > backup-hda.sf

And restore the partition tables and MBR with:
dd if=backup-hda.mbr of=/dev/hda

sfdisk /dev/hda < backup-hda.sf

Thanks again for your time, please help me as far as you can, I appreciate it. I will accept your answer.

reaper_11Author Commented:
Thanks alot!
All Courses

From novice to tech pro — start learning today.