Tuesday, January 15, 2013

Installing VMware Tools in Ubuntu 12.10 with kernel 3.7.x


Recently I have installed VMware Workstation 9.0.1 inside a vm running on Ubuntu 12.10 with latest kernel 3.7.1.
(Click here to upgrade Ubuntu kernel to latest 3.7.1)
For some reason the vmware-modconfig script for compile/recompile/install seems to be unable to detect the changes in latest kernel 3.7 series. Some header files have been relocated in kernel 3.7 series which go undetected by not so clever VMware.

Installing VMware Tools
In the menu bar of VMware click on VM menu and you would find “Install VMware Tools...” second last option. Click on it and a DVD named “VMware Tools” will automatically mount. Open the DVD from Unity side menu and copy the “VMwareTools-8.8.4-743747.tar.gz” file to your desktop. Open a terminal and extract it using below command.
$ tar -xzvf VMwareTools-8.8.4-743747.tar.gz

You will find a directory named “vmware-tools-distrib” created on the desktop. Run the script “vmware-install.pl” in that directory using the below command
$ sudo ./vmware-install.pl

All I did was to set all the default options. There's a point where the installer asks about the valid kernel header path and will ask you to change it. Due to the relocated kernel 3.7 header files the vmware tools installer isn't able to locate the header files in it's default location. Here just open another terminal copy the relocated header files needed to their default location. Follow the below mentioned instructions.

$ cd /usr/src/linux-headers-3.7.1-030701-generic/include
$ sudo ln -sf ../generated/uapi/linux/version.h
$ sudo ln -sf ../generated/utsrelease.h
$ sudo ln -sf ../generated/autoconf.h

Now in the previous terminal where the installer is running, put the “/usr/src/linux-headers-3.7.1-030701-generic/include/” path for the valid linux kernel header files and the installation shall continue as normal.



As you can see from the above screenshots the VMware Tools 8.8.4 has been successfully configured for kernel 3.7.1-030701-generic.

Saturday, January 05, 2013

Backup and Restore in Ubuntu


There are various strategies for a backup depending on the method that suits your needs. Lastly the “best backup policy” will be the one that is tested and works as per your needs.

METHOD-1 (Manual)
Here we will see how to backup the data, and applications installed from the repositories of Ubuntu.

Step-1 Backup of List of All Applications
Assume if for some reason your system is not able to boot and you dont have any choice other than reinstalling the operating system. There is least possibility for anyone to remember the whole lot of packages and applications that are installed on the system. In that case there is a quick way to store a list of all installed applications and packages in a text file. This text file can be used to install all your packages automatically. This method will help you save an incrdible amount of time, especially when you need to repeat the same task multiple number of times.

So, first you have to retrieve all your installed packages to a list. You can do so by redirecting the output to a file, example – applist.txt. You need to save this file to some place so that you can use it in future for the restore process.

Follow the below mentioned steps to proceed further.
Creating backup
    1. Open the terminal and execute the below command to backup the list of your installed applications.
$ sudo dpkg –get-selections > applist.bkp
Now you can move the applist.txt file to some safe location (CD, DVD, Pendrive, etc.)

Restoring backup
You can restore your packages after a new/fresh installation of Ubuntu by moving into the folder containing your text file and follow the below mentioned steps.
$ sudo apt-get install aptitude
$ sudo dpkg –clear-selections
$ sudo dpkg –set-selections <applist.bkp>
$ sudo aptitude install
Then follow given prompts.
APTonCD, and easy GUI tool serves the same purpose.

Step-2 Backup your Data.
Most of us normally keep our data in /home. Other customizations and settings would also reside in /home. If there is some place other than /home where you keep your data, that should also be included respectively.

Step-3 Backup the System Settings.
It is a good practice to keep a copy of all system critical files like /etc/fstab, /etc/passwd, /etc/shadow, /etc/group, /etc/sudoers, /etc/hostname, and /etc/hosts. As you can see all these files are very important and are all contained in /etc, so it is more convenient to backup all of /etc directory.

Step-4 Backup Partition Table
Partition table backup proves useful in case where we need to replace a damaged hard disk and to replace the old partition table onto the new disk.
To create a copy of partition table using the below mentioned command.
$ sudo fdisk -l > fdisk.bkp
or
$ sudo sfdisk -d /dev/xyz > /<path_to_file>/sfdisk.bkp

To restore the partition table follow the below mentioned steps
$ sudo sfdisk /dev/xyz < /<path_to_file>/sfdisk.bkp
GParted Live-CD can also be very useful to backup the partition table.

Step-5 Backup your MBR
MBR is located in the first sector of hard disk and is commonly known for finding the bootable partitions in the partition table. It loads the boot sector i.e. boot loader. A damaged or corrupted MBR means that the operating system will fail to load. MBR resides in 512 byte boot sector, where 446 bytes is reserverd for bootstrap, 64 bytes for partition table and 2 bytes for signature.
MBR Backup
$ sudo dd if=/dev/xyz of=/<path_to_file>/mbr.bkp bs=512 count=1
Use “bs=446” to copy just the MBR.
Destroy MBR
To clear the MBR including the partition table use the below command. In case if you can to just kill the MBR and keep the partition table intact then simply change the value 512 to 446.
$ sudo dd if=/dev/zero of=/dev/xyz bs=512 count=1
MBR Restore
You can copy the MBR backup file to some pendrive and boot the machine using a live-CD and execute the below command to restore the old MBR.
$ sudo dd if=/<path_to_file>/mbr.bkp of=/dev/xyz bs=512 count=1
Replace xxx with the actual device name such as /dev/sda or /dev/hda. Actual device name can be found using the below command.
$ sudo sfdisk -l
Reinstallation of GRUB using the install CD in rescue mode will also give the same effect, without touching the partition table. There are many other ways to restore the MBR. There are many tools and live-CDs available to do so such as UbuntuSecureRemix, Boot-Repair-CD and TestDisk. You can google out many different ways and implement as per your convenience.

Step-6 Final backup
Finally you can also backup some additional directories like /usr/local, /opt or /usr/share, it may be anything that you have customized and put everything into an archive.
Create an archive
$ sudo tar -cvzfp backup.tar.gz /home /root /etc /<path_to_file>/mbr.bkp /<path_to_file>/sfdisk.bkp /<path_to_file>/applist.bkp
Restore archive
$ sudo tar xvzfp backup.tar.gz -C /

METHOD-2 (Using images)
Backing up data using images is very easy with the help of some tools like Partimage and Clonezilla. Even command line tools like dd, tar and rsync have proved very efficient in backups containing large data. The only disadvantage of image backups is its large size. Since it is very simple to just copy and compress the data to an image, it does backup everything on the partition. Normally everyone needs small backup containing only the data and settings on their machine, because of which this method is rarely used.

Backup tools like deja-dup, sbackup, Pybackpack and Grsync are few that are used widely for simple backup administration.

Note: Always test your backup before you implement it.

Any suggestions are more than welcome.