Newbie - CP Question

Posted on 2004-09-15
Last Modified: 2010-04-21

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?


Question by:reaper_11
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
LVL 40

Expert Comment

ID: 12070129
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.

Author Comment

ID: 12070258
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?
LVL 40

Expert Comment

ID: 12070822
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.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 12071391
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!
LVL 40

Expert Comment

ID: 12071526
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

Author Comment

ID: 12071633
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
LVL 40

Expert Comment

ID: 12072028
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.

Author Comment

ID: 12078734
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.

LVL 40

Accepted Solution

jlevie earned 325 total points
ID: 12080329
> 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.

Author Comment

ID: 12086510
Thanks alot!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question