Showing posts with label Gparted. Show all posts
Showing posts with label Gparted. Show all posts

Monday, June 25, 2012

Installing Windows after Ubuntu while dual-booting

    If you ever want to install windows on your system and dual boot with your current ubuntu installation, you don't have to get rid of your current installation. You can do it without re-installing ubuntu all-over again. 

Note : You need to have a working internet connection for the same or you need to have following five files correspong to your system architecture ( amd64 or i386 ) to proceed.
a) grub2-common_1.99-12ubuntu5_<architecture>.deb
b) grub-gfxpayload-lists_0.5_<architecture>.deb
c) grub-pc-bin_1.99-12ubuntu5_<architecture>.deb
d) grub-common_1.99-12ubuntu5_<architecture>.deb
e) grub-pc_1.99-12ubuntu5_<architecture>.deb
     You can download these from :

If your system satisfy the above condition then just do as in the following steps :

1) Back-up whatever you want to preserve. ( for worst-case scenario )

2) Have a Ubuntu CD / DVD / bootable USB disk with you. You will need it later on.

3) Create a partition for your windows installation from your ubuntu installation ( if you don't have one ) . The partion need-not to be formated as NTFS for now as you can do the same while installing windows. Just make a unformatted partition or simply create a blank free space (partition ) . You can do it via Gparted partition editor. If you don't have it installed , you can have it by entering following command in the terminal :
                       sudo apt-get update && sudo apt-get install gparted

4) Install Windows on the new partition.Remember not to touch the partition(s) containing your ubuntu installation or swap area.

5) At this point of time you won't be able to see or use your current ubuntu installtion as the system will straight boot into the new Windows installation.

6) Boot from your Ubuntu CD / DVD / bootable USB disk .

7) Open the terminal and enter the following command :

 i) sudo mkdir /mnt/temp ( creates a temporary directory for mounting your ubuntu partition )
ii) sudo mount /dev/sda2 /mnt/temp ( here /dev/sda2 is the partition where your ubuntu installation lies )
iii) Also mount some miscellaneous file-systems for proper working of chroot command : 
        for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt/temp$i; done
iv) Now chroot into your ubuntu Installation :
                                  sudo chroot /mnt/temp
v) If the above commands run successfully, the terminal prompt should include "root" ( root@ubuntu:/# ), which indicates you are in the chroot environment.
vi) Confirm you have working net connection in the chroot environment ( for downloading the grub installation files if you have not already downloaded it ) :
                               ping archive.ubuntu.com
vii) Update your package list : This step is optional if you have already downloaded the grub files.
                                sudo apt-get update
viii) Purging the Grub Loader : Do not proceed to next command if you don't have a working internet connection or you do not have access to downloaded grub files . The next command will remove grub, grub-pc (Grub 2) and grub-common. If you are sure you have never had Grub legacy on the current installation you may omit "grub" from the next command.
                             apt-get purge grub grub-pc grub-common
Here is what you will have to do:
  • Press ENTER to continue.
  • Read the warning during the install about removing the bootloader. TAB to highlight "<Yes>" and press ENTER.
viii) Re-install the grub packages : 
                   Command :
                           apt-get install grub-common grub-pc
Here is what will happen:
  • You will be given the opportunity to add extra kernel options to the kernel line. If you don't know, you probably don't need them ; TAB to highlight "<OK>" and press ENTER.
  • Read the installation notes. TAB to "<OK>" to continue.
  • When presented with the device option, use the Up/Down keys to select the correct drive ( /dev/sdX ).
  • Make sure the installation drive [*] /dev/sdX has an asterisk next to it ( example: [*] /dev/sda ). 
  • If it doesn't, highlight it and press the SPACE bar to select it. Do not select a partition ( example: [ ] /dev/sda5 , etc). 
  • TAB to "<OK>" and press ENTER. When it has finishing the installation, you should have Grub 2 installed.
ix) Update the Grub Loader files
                     update-grub
x)- Exit the chroot environment
                       exit
If you have successfully exited chroot, the terminal prompt should return to the Ubuntu Live CD prompt ( ubuntu@ubuntu:~$ ).

8) Reboot your system and you will be presented a grub based boot-menu containing the choice of operating systems ( including Windows ) you want to boot.There it goes ....

Have a happy Ubuntu Experience...

Wednesday, October 12, 2011

Recovery of a deleted partition ( Part - 3 )

         As I have written in my last post ( http://meandmyubuntulinux.blogspot.com/2011/10/recovery-of-deleted-partition-part-2.html ) that the Ubuntu Live disk was able to detect all of my partitions and all my data but still I was unable to boot into the system.

        So, I tried to re-install the Ubuntu Grub Loader and see if that works . So, as per the post on ubuntu forum ( http://ubuntuforums.org/showthread.php?t=1581099 ) , I proceeded as follows :

1) Boot into the Live USB disk.
  
3) Created a directory for mounting my Ubuntu partition :
                 sudo mkdir /mnt/temp
3) Mount the Ubuntu Installation :
              sudo mount /dev/sda9 /mnt/temp

4) Mount miscellaneous filesystem for proper working of chroot command :
      for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt/temp$i; done

5) chroot into the Ubuntu installation :
                        sudo chroot /mnt/temp
If the above commands run successfully, the terminal prompt should include "root" ( root@ubuntu:/# ), which indicates you are in the chroot environment.

6) Confirm that I have an working internet connection in the chroot environment : 
                                apt-get update
As I was having a working internet connection , I moved forward to the next step.

7) Purging the Grub Loader : Do not proceed to following command if you don't have a working internet connection. The next command will remove grub, grub-pc (Grub 2) and grub-common. ( If you are sure you have never had Grub legacy on the current installation you may omit "grub" from the next command else keeping that in the command does no harm. ). Here is what you will do when you enter the command :

         a) Press ENTER to continue.

         b)Read the warning during the install about removing the bootloader. TAB to highlight "<Yes>" and press ENTER.

Command :

                            apt-get purge grub grub-pc grub-common

8) Re-install the grub packages : Here is what will happen:
         a) You will be given the opportunity to add extra kernel options to the kernel line. If you don't know, you probably don't need them ; TAB to highlight "<OK>" and press ENTER.

         b) Read the installation notes. TAB to "<OK>" to continue.
         
         c) When presented with the device option, use the UP/DN keys to select the correct drive ( /dev/sdX ).
    • Make sure the installation drive [*] /dev/sdX has an asterisk next to it ( example: [*] /dev/sda ). If it doesn't, highlight it and press the SPACE bar to select it.
    • Do not select a partition ( example: [ ] /dev/sda5 , etc). 
       d) TAB to "<OK>" and press ENTER. When it has finishing the installation, you should have Grub 2 installed.
Command :
                       apt-get install grub-common grub-pc
  This is the point where I got stuck again, as it refuesd to install the Grub Loader onto my Hard Disk ( /dev/sda ).

:-(

       When this problem persisted no matter what I do to resolve it, I finally figured out that the Mini iso image which I was trying to write on the Pen-drive using the dd command ( Refer to my post : http://meandmyubuntulinux.blogspot.com/2011/10/recovery-of-deleted-partition.html ) was almost 25 MB in size so it must have over written the Master Boot Record , the partition table as well as some other important Windows files ( remember that I had Windows Xp installed in my 1st Partition ) and hence corrupting the Windows installation.
          So, I decided to format that partition and do a fresh re-install of the Ubuntu Grub Loader. I back-up everything that was important for me from the Xp partition via the USB live disk and formatted the /dev/sda1 partition using GParted Partition Editor . Next I repeated the above steps from 1 to 8. This time it successfully installed the Grub Loader without a hitch. So I could proceed further.

Step 9:- Update the Grub Loader files
                         update-grub

Step 10:- Exit the chroot environment
                      exit
If you have successfully exited chroot, the terminal prompt should return to the Ubuntu Live CD prompt ( ubuntu@ubuntu:~$ )

Step 11:- Unmout whatever you previously mounted :
                           sudo umount /mnt/temp
           for i in /dev/pts /dev /proc /sys; do sudo umount /mnt/temp$i ; done

                 When I finally re-booted the system. I was able to boot into my only left Operating System i.e. my loving Ubuntu. Windows is gone ( as such also I was rarely using it and was thinking to remove it and put it into the Virtual-Box.). It was a very tiring but learning experience to do all this. I actually never imagined that I could bring back my system into this working condition and that too without loosing a single important file . But I did it !!! All thanks to the Ubuntu forum ( http://ubuntuforums.org ). One very important thing that I learned is cross-check each command twice before firing it especially when you are in root privilage else you may land into a series of problem that you never imagined and may be never able to recover from the damage that it inflict.

Have a Good Day and a happy Ubuntu experience.....

Saturday, October 8, 2011

Recovery of a deleted partition ( Part - 2 )

                Starting from where I left in my previous post 
(http://meandmyubuntulinux.blogspot.com/2011/10/recovery-of-deleted-partition.html  )  , Testdisk has done wonderful job in revealing my HD's partitions and thus correcting the partition table. But..... still something was missing out there as I was still not able to boot into the system. It simply displayed a cursor which keeps on blinking forever and no other error message. 

               So, I had to again boot with the help of the Lucid Lynx ( Ubuntu 10.04 LTS ) live usb to figure out what is happening. Interesting or say luckily, when I booted the live system, It easily discovered all my partitions and and I was also able to access all of my data !!!


             This was quite confusing situation as the Ubuntu live disk was able to detect partitions properly but still my system was not able to boot at all. So, I checked with GParted Partition editor to see if there is still any problem in the partition table. Yes there was.......... it says “A disk cannot have partitions outside the disk”.


So, I dumped my partition table to a file called PT.txt for editing :

                                 sudo sfdisk -d /dev/sda > PT.txt


The output was :


--------------------------------------------------------------------------------------------
# partition table of /dev/sda
unit: sectors
/dev/sda1 : start= 63, size= 62926542, Id= 7, bootable
/dev/sda2 : start= 62926605, size=425481525, Id= f
/dev/sda3 : start= 0, size= 0, Id= 0
/dev/sda4 : start= 0, size= 0, Id= 0
/dev/sda5 : start= 62926668, size= 31471272, Id= 7
/dev/sda6 : start= 94398003, size=136323528, Id=83
/dev/sda7 : start=230723584, size= 41947136, Id= 7
/dev/sda8 : start=272671308, size=104872257, Id= 7
/dev/sda9 : start=377544704, size=107634360, Id=83
/dev/sda10: start=485179128, size= 3215608, Id=82
---------------------------------------------------------------------------------------------

              Now let me explain the above output. The 1st column containing /dev/sd? are the partitions. If sfdisk doesn't find a partition corresponding to any number it simply put start, size and id = 0 for that partition. Its not an error. Start and size given here are in units of sectors. A particular Id corresponds to a particular partition type. For example, here, Id=7 is NTFS , Id=f is extended partition , Id=83 is EXT4 and Id=82 is Linux Swap partition.






Now time for some maths.......



As per the link in the reference post link that I gave above :

  1. There is a 63 sector gap between the start of an extended partition and the start of a logical partition.
  2. There is a 63 sector gap between the end of a logical partition and the start of the next logical partition.
  3. There is no gap at all between primary partitions.
  4. It is possible to have larger gaps between partitions, but never smaller than 63 sectors for logical partitions, (and obviously) never smaller than 0 for primary partitions.
  5. Partitions must not overlap.

         In my case, /dev/sda1 is a primary partition, /dev/sda2 is a primary extended partition and /dev/sda5 to /dev/sda10 are logical partitions.

               Now, checking the above conditions with my partition table.

  1. /dev/sda1 is ok as it starts at sector 63. No problem in that.
  2. Considering /dev/sda1 end range is ok, /dev/sda2 ( being a primary partition ) should start at sector=63+62926542=62926605 and so is the case . So, the start range of /dev/sda2 is also ok. Leaving aside the end range of /dev/sda2 as that will be the end of disk.
  3. Now, for /dev/sda5 ( which is a logical partition ), the start range ( as per condition 1) should be sector=62926605+63=62926668 and therefore , /dev/sda5 is also ok.
  4. For /dev/sda6 start sector= 62926668 + 31471272 + 63 = 94398003 implies that /dev/sda6 is ok.
  5. Similarly checking start sector of all the partitions are found ok.
  6. Now, time for the last check i.e. end sector of last partition i.e. /dev/sda10 and end sector of the extended partition /dev/sda2. Both should be same.
    End sector of /dev/sda2 will be sector = 62926605 + 425481525 =488408130
    End sector of /dev/sda10 will be sector = 485179128+ 3215608 = 488394736

                 So, here is a difference. So, either of two range is wrong. So, had to go with hit and trial with both the possibilities as I couldn't find a way to determine the total sector size of my HD :-( .

At first backing up the dump of original partition table.

                                            cp PT.txt PT.txt_bkp


and transferred it to the external hard disk for backup.


                 Now, trying to go with lesser of two range. So, end of /dev/sda10 will be ok but end sector of /dev/sda2 will have to be changed.


New Size of /dev/sda2 will be=end sector of /dev/sda10–start sector of /dev/sda2
                                               = 488394736 - 62926605

                                               = 425468131


                  So, editing the PT.txt file using vi editor and using the obtained value , the new partition table looked like following :

-------------------------------------------------------------------------------------------
# partition table of /dev/sda
unit: sectors
/dev/sda1 : start= 63, size= 62926542, Id= 7, bootable
/dev/sda2 : start= 62926605, size=425468131, Id= f
/dev/sda3 : start= 0, size= 0, Id= 0
/dev/sda4 : start= 0, size= 0, Id= 0
/dev/sda5 : start= 62926668, size= 31471272, Id= 7
/dev/sda6 : start= 94398003, size=136323528, Id=83
/dev/sda7 : start=230723584, size= 41947136, Id= 7
/dev/sda8 : start=272671308, size=104872257, Id= 7
/dev/sda9 : start=377544704, size=107634360, Id=83
/dev/sda10: start=485179128, size= 3215608, Id=82
------------------------------------------------------------------------------------------


Please note the change in size of /dev/sda2.



                      Now time to write the new partition table using the new file PT.txt . It can be done by :


                     sudo sfdisk --no-reread -f /dev/sda -O PT.save < PT.txt


here, "--no-reread" means don't check if disk is unmounted

           -f force

          "-O PT.save" means save a backup of original partition table in PT.save.


( PT.save is in binary format. To restore the partition table using PT.save:


                           sudo sfdisk --force -I PT.save /dev/sda )



                           Now lets reboot and see if the problem is resolved. Still no luck as the cursor still blinks forever. Now at least , the GParted doesn't detect any error in the partition table and all the error messages are gone and I am able to easily access my all data using the Live USB disk.



                            So, will I have to re-install my operating systems all over again or still something can be done ???



To be continued............




Saturday, September 24, 2011

Installing a 1 GB swap without partitioning

              Some software that you install e.g. oracle database XE requires you to have greater than one GB swap space. So, if you have not created a swap partition of greater than 1GB just because you have lot of RAM, you may land in a fix so as what do now . Although  , in ubuntu , you can easily use GParted to create a new swap space but some times you don't have enough free space or don't want to take risk of using GParted . Also , GParted is not installed by default ( u can get it from Ubuntu Live Disk ). So, we need some process by which we can have some extra swap space without using GParted.

To install a 1 GB swapfile named swapfile in /  ( root directory) , use the following steps in the terminal :

1) sudo -s 

   ( to gain root privilage, its optional , but if you don't do this then you have to append sudo to each of the following commands )

2) dd if=/dev/zero of=/swapfile bs=1024 count=1048576  

   (this may take a while)  ( 1048576 == 1 x 1024 x 1024 , 1GB == 1048576 KB)

3) mkswap /swapfile

    ( ignore any error )

4) swapon /swapfile
 
    ( to turn on the swap )
 
5) cp /etc/fstab /etc/fstab.orig


    ( back-up the fstab before editing )

6) echo '/swapfile swap swap defaults 0 0' >> /etc/fstab
 
    ( adds the entry of  new swap to fstab for mounting the file at boot time )

7) To  Verify:

   swapon -a ; swapon -s


If at anytime u want to delete the swap then :

   sudo swapoff -a
  
   sudo rm /swapfile


   sudo cp /etc/fstab /etc/fstab.changed ; sudo cp /etc/fstab.orig /etc/fstab

   sudo swapon -a ; swapon -s

Friday, September 23, 2011

locating and correcting bad blocks/sectors of pen-drive

              Sometimes, we drop our pen-drive in some water container and our pen-drive either refuses to get detected or files not getting copied to it. We can use our Incredible Ubuntu operating system to get it working. Find below the steps for the same.

Note : 
1) It is a time-consuming process. Use the 2nd steps only if you actually find any bad-block.
2) All steps need Ubuntu live disk and back-up of data to avoid any loss.

3) The process can be well applied to a hard-disk.

 Steps for locating and correcting bad blocks/sectors of the pen-drive :

1) Boot from Ubuntu live disk , open Gparted and check for partition name ( e.g. /dev/sdh1 )  and use the same to replace /dev/sdh1

2) Looking for bad blocks ( via terminal )

The first step is to locate the bad blocks of each partition. Type in the following command to do a search using the non-destructive way (-n), showing the progress (-s) and dumping the bad blocks in the file "badblocks_1GB01.txt" .

sudo badblocks -n -s -v /dev/sdh1 -o badblocks_1GB01.txt

2) Formatting the drive

You have to pass the list of blocks obtained in the previous step, for which the command to use to format in FAT32 is:

sudo mkdosfs -F32 -v -n "1GB" -l badblocks_1GB01.txt /dev/sdh1

Here -F32 is for FAT32 partition and "1GB" is the partition size .

This will render the badblocks un-available for use leaving all the usable blocks on the pen-drive for use.