Disclaimer: Try this at your own risk. We are not responsible if your install gets messed up, this is just one of the many methods available to back up your linux install. Please make sure you read and understand the man pages related to the tools mentioned in this article before attempting.
My latest exploration of the linux world was backups. In light of recent events I decided to find out how good of backup utilies there are within the Ubuntu world. I have used Ghost in the past for all my backup needs, but what else is there available for the guy like me who just wants to back up his linux install? Well, there’s plenty of options out there and I’m not going to go into detail but after testing, none of them worked in the manner I wanted. I wanted to be able to go from a /dev/sda5 to /dev/sda1 install that worked.
Every program I tested left an inoperable system or one that was absolutely instable at best. One booted up completely with most of my custom theme set but half of the applications like conky, AWN, and screenlets had problems during startup. Not to mention one of the applications that gave me a bootable install didn’t bring over the 180 nVidia driver and I was stuck in 800×600 mode.
The good news is that I got one to work properly and without any major side effects. I will explain after I show the process of what I did to get this to work. I was browsing the Ubuntu forums when I found a post all about “tar”. “tar” is similar to WinZIP for windows or winRAR. It’s simply an archiving tool that can compress and store many files into one spot. To be able to complete this with a file of a decent size I would have to remove plenty of things from my hard disk to reduce the size. This included removing my Virtual Box hard drives, Music folder, Videos folder, and all of my stored ISO’s on the drive in question.
The biggest thing I’ve learned about the process, unlike windows, linux has the capability for a super user to read and/or write to any file on the system, even when it’s in use by another application. This is capable from the command line and in theory you could literally delete the entire hard disk while the system is in operation.
“tar” became my new favorite tool in the process of working with my adventure. I would accomplish this before I reinstalled just to prove that it is possible by an “average” Ubuntu user like myself. An excellent tool for new users to get into using is called “man”. This tool used in conjunction with certain commands used in the terminal can be extremely helpful for the learning process. For example, “man sudo” will show you the manual for the sudo command. Using “man tar” I learned what I would need and how I would need to use it. I finally came up with a plan of attack in how this could be possible. A long with this process I learned which directories I could omit and which were absolutely necessary to have for linux to run properly. Once I had all this information saved and listed in a text editor I started my terminal to build my backup. Starting with an amount of data equalling 11.6GB, I was expecting a big file from the following process. Total time was about 15 minutes.
I first entered Sudo mode by typing in: “sudo su”. This put me into “super user” mode and gave me unrestricted access to the files on the hard drive. I followed this by changing my directory to the root directory with “cd /”. Using the GUI I unmounted all mounted drives that weren’t to be in my backup. You could omit the /media folder but I figured I’d add it either way. Here’s what I came up with.
tar cvpzf linux.tgz –exclude=/proc –exclude=/lost+found –exclude=/mnt –exclude=/sys –exclude=/linux.tgz /
This copies all of the drive excluding the “exclude” options in the list. If you’re going to do this type of backup, make sure to omit the file you’re using or it will loop with errors at the end of the compression process. Using the super user ability it was able to read every file on the disk aside from what I omitted. Windows cannot do this with it’s system files, so this wouldn’t work for windows either way.
So I watched it compress all of the files for about 15 minutes in the background while working on some other stuff I was previously working on. All of the sudden, it was completed. I did recieve an error message about pausing for previous errors but the file passed all the tests I gave it. From 11.6GB down to 4.3GB which is just right for a DVD-R disc.
So, I had my file and was ready to decompress it onto my other drive. Cool thing is that I can extract it to the /dev/sda1 partition from the same terminal window! Simple as a “cd /media/disk” got me there. The simplest thing is uncompressing it. I uncompressed the file on my first partition and it took just about as long as the compression side did.
I used the following very simple command to decompress the file to the disk.
tar xvpfz linux.tgz -C /media/disk
I had to run that from my root directory on my installed linux disk as that is where my file was. After this, I had to install grub on the drive using “grub” and “fdisk -l” to setup the /boot/grub/menu.lst file for the new installs location. Now it was time to try and boot the system from that drive and see if it works. I booted a LiveCD and moved the original install into it’s own folder on the /dev/sda5 partition so it wouldn’t be able to boot from the lack of files. I was ready to test out my new “from backup” copy of Ubuntu. After having to fight with grub for a while, I got it to boot the 28.13 kernel and it started to a login screen.
Come to find out, everything worked perfectly without a flaw at all. A complete backup of my linux install that was completely moved from one partition to another! Perfect. There wasn’t many side effects to the entire process aside from bootup speed. I had to edit some small things, like my .conkyrc file to change up for the new partition, however everything important worked instantly and perfectly as it did before the move. I think it did a very good job in backing up my copy of linux without near the side effects of some of the other test mediums. The worst part about the change was a gain of about 2 seconds of initil loading (while the ubuntu logo and the scrolling line are on the screen).
Overall, I believe this could effectively be a good method of “backup” for my system. Like I said before though, you need to know what you’re doing before attempting this. I had an install that I could care less if it didn’t work for. If I wasn’t going to reinstall anyways, I would have never attempted this type of backup. But the fact that it worked and installed on a totally different partition with a “little” grub work, I was more then happy. All I had to setup with grub was my original windows partition and for those of you who don’t run dual boot, you probably wouldn’t have to tinker with it at all.
A couple of side notes here though:
If you make your tgz file and repartition the hard drive, you will still need a linux based operating system to get to the partition and extract the files to it. Personally, I didn’t need to even leave my install as I was installing to a second partition that was unused in the first place.
Another method of getting to the files is storing the tgz file on another drive and running through a Live CD and mounting both the drive containing the tgz file and the drive you plan on restoring too. Then it is simply a matter of sorting out the mounting locations such as the following…
/dev/sda1 and /dev/sdb1 or whatever they are listed as. You can simply find this out in ubuntu by right clicking the mounted drive icon on the desktop and looking at the properties tab.
Another side note here is the fact that this can potentially cause the loss of data and or ability to even start your operating system. If this is done incorrectly, you could end up destroying your install. This is where I will recommend again to read all you can about the commands used in the process. This could be a beneficial thing to know in the future for you as you learn more and more about linux. I’ve learned one thing about linux so far, and that is that you just never stop learning new things with it.
So, take these words as advice into something new, stray away from the crowd and learn something new. Take your vigilance to the next level and be brave to go the other way. I learned a ton about tar and it’s effects. I also learned quite a bit about grub and partitioning with linux. This is how you discover new things and new abilities. Nine times out of ten, if there’s one way to do something, someone has figured out three more ways to do the same thing!
SX