ubuntu dual boot illustrated site ubuntu dual boot windows 7 maverick meerkat
Back Up & Restore

Edited Thursday, July 21 2011 Document made with KompoZer
This web-page is part of a larger site giving examples of how to install Windows+Ubuntu Linux operating systems 'dual boot' in a computer.  Illustrated Dual Boot HomePage

Just like any other operating system, it's very important to be able to back up and restore your Ubuntu files and installed software and settings.

Backup Media: CDs, DVDs or USB? Or a Second Hard Disk Drive?
The old way was to write files to CDs and DVDs but I'm not sure if many people do it that way anymore.
Hard disks have increased in capacity and come down in price per GB. Files and file systems have grown and technology has progressed. Many people take more pictures than they use to and even make home movies now.  Most people are saving  more files than we used to and also large files. Burning them all to optical media would be time consuming.
If you just want to make a backup of your regular files, then you'll probably need a spare hard disk drive or an external USB drive at least as large as the hard disk you have Ubuntu installed in. They're not expensive these days.

One thing to be careful of is to make sure your external USB drive or other hard disk drive or whatever you're going to use is formatted with a good Gnu/Linux file system.
That could be worth thinking about if you need file ownership and permissions to be preserved, which can be important for some kinds of files especially if your backup will include software files like bash scripts and python programs and so on.

Security Reminder - even if you don't think you have anything private included in your backups, you probably do have a lot of personal and/or business information. You really should consider creating a fully encrypted file system using Linux Unified Key Setup, (LUKS for short) to store your backup files in. See the bottom of this page for more, (down).

Regular user files
KISS (Keep It Simlpe Stupid) - The simplest way to do things is often the best. That is, you just create an new empty directory in the other drive and then copy all of the contents of your entire /home/username directory into it. Documents, Pictures, Video, Downloads, Backups, whatever.
This makes a plain ordinary simple backup of your regular files and it can be very convenient. If you make a mistake and delete a file or something silly you can easily just go browsing through your backup files and find the file you're looking for and copy it back again. That's better than having everything bundled up in some kind if a tar ball that only some special program can open and that you can't just fish through looking for just the one file or paragraph you need in a hurry.

If you give the each new directory you are making backup copies of your files in after the year, month, and day, something like '2011-07-14_backup' and '2011-08-21_backup', the directories will automatically remain sorted for you in chronological sequence. If you have your own ideas about how they should be named, that's okay, you can always just use nautilus's  'View', 'Arrange Items by' menu to sort them any way you want, but I like to use this naming by date method as well.
Most of the time I use a more descriptive word after the number than 'backup', I make frequent small backups of all kinds of things and I replace the word 'backup' with something more specific to help me locate things again later.

If you want to be a little bit fancier,  you can make a back up your firefox bookmarks and include that in your collection of backed up files as well.
To make a backup of your firefox bookmarks, open firefox and click 'ctrl'+'shift'+'o', or click 'Bookmarks', 'Show all Bookmarks'.
Whichever way you did it, you should end up with a window called 'Library', and near the top you should see an menu called 'Import and Backup'.
When you click on your 'Import and Backup' menu, a drop-down box should offer you the options to make a Backup, Restore from a backup , or import HTML or restore HTML.
  • The 'Backup,  option will create a .json file named after the date it was made. When you Restore with a .json file, it will overwrite whatever bookmarks you have, which will cause existing bookmarks  to be deleted and completely replaced with the backup file. In some circumstances that's good, but other times that's not what we want.
  • The Export HTML  options will result in a html file being created containing all your bookmarks and when you Import another HTML file it will append to your current bookmarks, which is sometimes good and at other times not so good, depending on what you're trying to do.
You may copy and paste your bookmarks.html or your bookmarks-yyyy-mm-dd.json anywhere you like as required for storage until you need it someday. With the rest of your backups somewhere will be fine.
Obviously, restoring such a backup is simply the reverse process and shouldn't require any more explanation.

If you use Evolution Email, you'll want to make a backup of your addressbook, calendar, mail, memos, and tasks.

Open Evolution and go to the 'File' menu and click 'Backup Evolution Settings'.
This will offer to create for you a file called something like 'evolution-backup.tar.gz', and you can edit the name if you need to and navigate to choose the diretory you want it saved to.
Evolution will close to make the backup, and reopen again.

Again, restoring such a backup is simply the reverse process and shouldn't require any more explanation.

Other Softwares (Settings)
Many other softwares we use have their user configurable settings stored in hidden files inside your /home/username directory.

I use a program called 'Password Manager', which stores all my account details passwords in an encrypted file.
Backing up my Password Manager is easy, I just open my /home/username directory and click 'View',  'Show Hidden Files'.
A lot of files will then appear with file names beggining with a dot. The dot before the file name tells Linux not to display the files we don't need to see most of the time, and 'show hidden files' over-rides that rule.

Now I just copy my .gpass directory and paste that into my backup files along with all the rest.

To restore, I simply do the reverse, after my new operating system is installed, I just paste the backup copy of .gpass into my new /home/username directory. As soon as I install Password manager again and start the program for the first time it automatically detects the .gpass directory and asks for my master password to unlock the encrypted .gpass folder and loads all my accounts and passwords again. 

You may have other programs that also store their user settings in hidden files in your /home/username folder, so take a look around while you have 'show hidden files' enabled to see if there's anything else much in there you might want to backup in a similar way.
Users settings for many Gnu/Linux programs can be backed up and restored in this way, but I can not promise it will work for all programs. You may need to consult your help menu or other documentation for your specific program to make sure.

Backing Up Installed Software
Software we install in Ubuntu generally comes in files with the .deb file name extension and they are normally stored in a directory called /var/apt/cache/archives.

There are a lot of them, as you will see if you type the following into a terminal,
ls /var/cache/apt/archives/

You can make a backup copy of these, but they're mostly only good for another Ubuntu installation that's the same architecture and the same release as the one you have. You should not attempt to use .deb files from an amd64 (dual core) Ubuntu in an i386 installation or vise-versa, or install .deb files from an older version of Ubuntu to a newer version.

Including these .deb files in a backup can be useful as long as you reinstall and restore them fairly soon, like within a week or two, or within a month or so. It doesn't pay to store these .deb files for too long because they get superceded as new software updates are made on a regular basis.

The reason why you may want to backup your .deb files and restore them again is only to save a few minutes  of downloading and a small amount of internet bandwidth. If you don't care about wasting a some internet bandwidth you might be able to skip this whole idea. On the other hand, if you're on dialup of you live in a country where bandwidth is limited, it might be worthwhile backing up your .deb files.

Some .deb files do take a lot of downloading. Some people, (like me), like to install a lot of fancy fonts and those take a lot of download time and bandwidth. They occupy some hard drive space too. Fonts are worth  keeping and re-using. They don't go out of date and can be used in any Ubuntu or other Gnu/Linux OS.

To back up your .deb files, simply navigate to /var/cache/apt/archives/ and copy and paste them to a folder along with the rest of your regular file backups.

To restore them you will need a sudo command like this,
sudo cp /media/usb-backup/software/*.deb /var/cache/apt/archives/
Where: Your backup is in /media/usb-backup and in a folder named 'software'.

Then you will still need to install them in the regular way. Some people use the Ubuntu Software Center, others use Synaptic Package Manager and some use apt-get commands in terminal. No matter how you do it, the software can be re-installed but it won't need to be re-downloaded from the internet, it will be reinstalled from the .deb files in /var/cache/apt/archives.

Backup installed packages on ubuntu - ubuntugeek

Create backup of all installed packages using APTonCD in Ubuntu - ubuntugeek

about apt-get by ubuntu_demon --> A Concise apt-get / dpkg primer for new Debian users.

Here's another way to do it, (slightly more advanced)
When you have an installed operating system with all of your favorite software added, you might want a list of the programs you installed so you can easily install the same ones again in case you ever need to re-install for some reason.
This is only good for installing in the same version, not for upgrading to a newer version of Ubuntu.

Installed .deb packages are stored in /var/cache/apt/archives, and you can make a backup of all the packages in /var/cache/apt/archives and copy it into another /var/cache/apt/archives in another installation of the same version of Ubuntu so you won't have to re-download the same packages again from the internet.

sudo dpkg --list >> installedI.txt
You might run this command on a fresh installation and then keep a copy of the output file for the future.
This command will output a list of all packages installed by default in a new installation to a text file and call it installedI.txt.

sudo dpkg --list >> installedII.txt
You might run this command on a mature installation.
This command will output another list of all installed packages to a text file and call it installedII.txt.

diff installedI.txt   installedII.txt >> addedsoftware.txt
Now you can run the diff command on the two files to get a list of all added software.

  1. Copy the 'addedsoftware.txt file into a new Ubuntu installation,
  2. Copy your backup of all the packages in your old /var/cache/apt/archives and paste it into your new /var/cache/apt/archives so you won't have to re-download the same packages again from the internet.
  3. run this command, (below),
sudo dpkg --set-selections < addedsoftware.txt

sudo apt-get dselect-upgrade
... and finally your newly re-installed operating system should have all the same software you had in your old installation.
File Compression

When you have a directory full of all the files you want included in a backup, you can easily make it into a compressed archive simply by right-clicking on the folder and clicking 'compress'.
You have a range of choices for various grades or kinds of file compression in Ubuntu.
The standards ones are .tar, (just an archive, no compression), tar.gz (some compression) or .tar.bz2 (takes longer and compresses the file to a smaller size).

Decompressing is just the opposite.

Applications for Performing Backups and Restoring

There are programs you can look for in Ubuntu Software Center which automate all of the tasks I have just described above, and more. It would be investigating and trying a few of them out to decide if there's one that suits you.
Just type a word like 'backup' in the search bar of your Ubuntu Software Center and take your pick.

Whole Partition Back-up and Restore

Sometimes we want to make a backup of an entire operating system, complete with added software and settings.

Copy and Paste the whole partition with GParted

This was the original method I had here, I'll still keep it here for a while in case it's useful to anyone. This was my favorite method for a long time.

Backing up with GParted

It's easy to resize your Ubuntu operating system to as small as possible and just copy and paste the whole thing to an area of spare disk space.
That will be a fast and easy way to back up everything, including added software and system settings, the whole lot. It only takes me about ten minutes to copy and ten minutes to restore.
Most people would want to remove some of their stored data first in order to shrink the partition to a very small size.

Restoring with GParted
You just copy the back-up copy of the partition you made earlier and paste it. Then you re-size it to the size you want again. Be sure to delete the old partition first, though, to make sure you get the same partition numbers as you had before. If you get different partition numbers you will need to re-install GRUB.

Complete Back-up Using File Compression 
Sometimes, using file compression to make one big tar file is the best thing to do. You can get a lot of work done a  faster that way sometimes, and squeeze more onto your back-up media too. Here's a link to a way to make a more complete back-up and restore job, using file compression.  
Here is another link, Howto: Backup and restore your system! - Heliode - Ubuntu Web Forums. 

Partimage Partition Back-up
It would be best to look at aysiu's tutorial, Use PartImage
NOTE: Use your spacebar on your keyboard to move the cursor in Partimage.

GParted LiveCD and Parted Magic both have Partimage in them.
To start Partimage in GParted LiveCD just open a terminal and type: partimage
Following are more links,
Partimage Home Page, http://www.partimage.org/Main_Page
Partimage Manual, http://www.partimage.org/Partimage-manual_Usage
GParted LiveCD also has Clonezilla added to it by LarryT as well.

Partimage is safer for most people to use than the dd command.

dd command

Another way to do things is to copy an entire partition to a file in another hard disk.
Possibly the partition can contain an entire working operating system.

You might find it advantageous to remove most of the users files from the operating system first and back those up seperately, and resize the partition as small as possible with GParted before creating your backup. This will make it easier to restore later.

sudo dd if=/dev/sdb1 ibs=4096 conv=noerror | gzip > partition.image.gz
Where: The partition you would like to make a backup of is called '/dev/sdb1' by Linux, use 'sudo blkid' or 'sudo fdisk -lu' or look with GParted to make sure and change that part of the command as needed.
sudo gunzip partition.image.gz | dd of=/dev/sdb1 ibs=4096 conv=noerror
Where: The partition you want to restore to is called '/dev/sdb1' by Linux, use 'sudo blkid' or 'sudo fdisk -lu' or look with GParted to make sure and change that part of the command as needed. You don't need to restore to the same partition or the same partition number, it can be any partition as long as it's big enough.

  • You will need to restore GRUB if this is your main operating system, or run 'sudo grub-mkconfig -o /boot/grub/grub.cfg' in your main operating system after restoring. See GRUB2 Pages.
  • You will probably want to resize the file system to fill the partition after using this command, see: What to do if your file system doesn't fit your partition - resize2fs
We can just as easily use the dd command to make a 'carbon copy' of our entire operating system into another partition, but now that file system UUID numbers are used for booting it can confuse GRUB so now it's best to make our backups to a file instead. It is possible to edit the file system UUID number with a tune2fs command if you really want to, and then update grub.

Note: Windows 7 and Vista users, you should consider also making a backup of your original hard disk's MBR. See MBR backup and restore. Also, check your EULA.

CAUTION: Be very careful with the 'dd' command, if you accidentally run it backwards and copy the damaged operating system to the good one you will destroy your good copy of the operating system!  Please double check and then check again before running the command.

Entire Hard Disk

Clonezilla - Clonezilla is safer for most people to use than the dd command.
Link: Clonezilla Imaging By Raymond Siudak.pdf

dd command

Copy an entire hard disk to another hard disk,
dd if=/dev/sda of=/dev/sdb bs=4096 conv=notrunc,noerror
Where: 'sda' is the hard disk with the data in it and 'sdb' is an empty hard disk which is equal or larger in capacity than 'sda'.

This command is useful when you want to replace a hard disk with a larger one, or if a hard disk is on it's way out but still readable, and you want to copy the contents to a new hard disk in time before the old one deteriorates too much further.

You would need to issue this command from a Linux operating system running in another media, such as a Live CD or USB operating system, or an operating system installed in another different hard disk.

CAUTION: Be very careful with the 'dd' command, if you accidentally run it backwards and copy the blank disc to the one with the data you will erase all your data!  Please double check and then check again before running the command.

  backup security
Security Reminder

It's always recommended to keep making regular backups to some other media than the hard disk your operating system is running in.

Naturally, if you store your backups anywhere where others can get ahold of them, you potentially have a huge security loophole.

In case you haven't thought of it already, if could be a good idea to keep your backup media in a locked box of some kind or even in a safe if the backups might contain any kind of sensitive data.

If you don't want to do that and security is any concern, (and that would mean almost everyone), it's easy to make an encypted LUKS file system in a partition for storing your backup files in.

Make a Linux Unified Key Setup  Encrypted File System
For Backup Storage

WARNING: If  wrongly applied, some of the commands shown below here can be dangerous to your files and systems. If a person following this how-to makes a mistake and types a wrong partition number they can lose data and/or an operating system.
  • Please make sure you are fully alert and in a calm state of mind in an environment free of distractions and not mentally impaired in any way before using the following commands.
  • Some Linux experience required. If you're not practiced with following Linux tutorials and confident with your ability to get the partition numbers correct then it would be better if you do not attempt the following commands, get help or just have a rest and leave this for later some time.
1. You need to create a partition first or have one empty somewhere, it should be in some other disk than the partition containing the original files and possibly in a removable disk.

2. You will need to install the necessary software,
sudo apt-get install lvm2 hashalot cryptsetup
You only need to run this command once. After that you can make more encrypted volumes and you don't need to repeat it again unless you re-install your Ubuntu operating system.

3. Run this command,
sudo modprobe dm-crypt
Once this command has been run once, it does not need to be run again for the life of the operating system.

4. This command is just to take a look at which partitions are which, you could use GParted to take a look if you prefer,
sudo blkid
Make a note of exactly what /dev/sdx,y number the partition is that you want to encrypt, this is very important!

5. Be extremely careful with this command and make sure you use the correct /dev/sdx,y number the partition is that you want to encrypt, this will set the password and write the LUKS header to the first sector of the partition !!!
sudo cryptsetup --verbose --verify-passphrase luksFormat /dev/sdb1
Where: '/dev/sdb1' is the partition which is to contain  the encrypted file system.

Note: Later on it might be a good idea to create a dd backup of the first two sectors of this partition as this now contains unique information that can be vital to the recovery of your data in the event that something should go badly wrong in the future. (unless you make another encrypted copy of the same backups).

6. This is to unlock the partition so we can work on it,
sudo cryptsetup luksOpen /dev/sdb1 sdb1

7. Create a new device called /dev/mapper,
ls -al /dev/mapper

8. Create the encrypted file system,
sudo mkfs.ext4 /dev/mapper/sdb1

9. Make a mount point,
sudo mkdir /mnt/encrypted

10. Relax the file permissions on the mount point so you can write to the new partition as a regular user,
sudo chmod 777 /mnt/encrypted/

11. Mount the encrypted file system for the first time,
sudo mount -t ext4 /dev/mapper/sdb1 /mnt/encrypted

Note: I don't think it's a good idea to trust any important data to this file system just yet, you could copy a few unimportant test files to it first if you like. Wait until you have rebooted and used the partition a few times before adding your serious backups to it.

12. Unmounting it afterwards,
sudo umount /mnt/encrypted

After the first time, and after a reboot, your operating system will start listing the encrypted partition in your places menu automatically and you can just click on the icon for it and it will be mounted in /media.

Cryptsetup - LUKS

Encrypt a partition with Dm-crypt and Linux Unified Key Setup - Linux Instruction

HowTo: Setup and Benchmark Encrypted Partitions in Ubuntu - www.fsckin.com

Tip: You might find it worthwhile to make two (duplicate) encrypted LUKS file systems in different hard disks since if anything goes wrong, file encryption can make recovery quite a bit more complicated.

Tip: File system encryption doesn't give you any protection against network based intrusions. Ubuntu is secure by default and does not come with any open ports. Most people have nothing to worry about.
If you have installed programs in Ubuntu that open networking ports then it is possible for somebody to see your encrypted files whenever your encrypted file system is mounted. You should use File Ownership and Permissions in addition to file encryption if you will have guests logged into your computer via any network connection.

Tip: Use only SSH (Secure Shell) Networking between your computers, with SSH, data is encrypted while it is enroute between computers. See this website's SSH Network Page.

Whatever you decide to do, just make sure you remember to think about security when you think about keeping backups of your files.



Back to Top