How to: Update (re-install) grub while merging partitions and still be able to boot

I like to play around and see how things work. So I did with Ubuntu, first I added the 32Bit version of the Gutsy Gibbon (7.10) Ubuntu to my Computer, which came out of the box with Vista Business. And than I added the 64Bit version of Gutsy Gibbon to it, just to see how they differentiate and if I still can get most of the stuff running. I actually did most, but not all, so use the 32Bit version and have a fine system (now 8.04 ‘Hardy’ Ubuntu) working with Thunderbird sharing files and profiles with Vista, Eclipse and some MySQL tools. So far, so good. Running smooth enough to decide I don’t need the 64Bit Ubuntu right now, since I don’t have time to play around test. And once it’s gone I want to merge the partition it has been on with the NTFS data partition to get some more space.

Preparations and planning

Ubuntu is using grub as boot loader and so far that worked like a threat. But grub was installed from the 32Bit Ubuntu that now has to go. So grub has to be moved. And after the partitions have been merged, it has to be updated to reflect the new partition layout. Here is the process we will be going through:

  1. backup the MBR (Master Boot Record)
  2. backup current configuration files and setup
    1. /etc/fstab
    2. /boot/grub/menu.lst
    3. /boot/grub/
    4. output of fdisk -l
  3. merge partitions
  4. install/update grub
  5. make sure everything still works fine, otherwise restore MBR

The assumption is that the system itself is smart enough to either recognize partitions have change and grub is automatically updated or if that is not the case, grub is smart enough to update itself when newly installed.


Now let’s get it on.

  1. Backing up the MBR into my home folder of the 64Bit Ubuntu:
    sudo dd if=/dev/hda of=~/Grub_backup.mbr bs=512 count=1
  2. All the other files to backed up as well. Here I will just display the information important to that post.
    1. the menu.lst is important to figure out which OS is installed on what partition, because we do not want to
    2. fdisk -l actually gives some interesting information about the way my hard disk is set up. The same information you get from GParted in a visual way (see below):
      Device Boot      Start         End      Blocks   Id  System
      /dev/sda1               1         815     6545408   27  Unknown
      Partition 1 does not end on cylinder boundary.
      /dev/sda2   *         816        6424    45050040    7  HPFS/NTFS
      Partition 2 does not end on cylinder boundary.
      /dev/sda3           10248       14594    34905088    7  HPFS/NTFS
      Partition 3 does not end on cylinder boundary.
      /dev/sda4            6424       10248    30716280    5  Extended
      Partition 4 does not end on cylinder boundary.
      /dev/sda5            6424        8248    14651248+  83  Linux
      /dev/sda6            8248        8613     2933248+  82  Linux swap / Solaris
      /dev/sda7            8613       10248    13131688+  83  Linux GParted showing my harddisk partitions
    3. Here the summary of what the information tells us:
      • /dev/sda1 – NTFS formatted, this is the Rescue&Recovery partition of Lenovo
      • /dev/sda2 – NTFS formatted, this is the actual Windows Vista system partition
      • /dev/sda3 – NTFS formatted, this is my DATA drive I used to share data between Vista and Linux
      • /dev/sda4 – is the extended container for the linux partitions (these are logical partitions no primary). That way you can have more than four partitions, because four (4) is the limit of primary partitions. Linux has no problems using logical partitions, Windows might be a bit picky when it comes to booting off them.
      • /dev/sda5 – ext3 formatted, the current root and since I’m in working system, that is where Ubuntu 8.04 32Bit is installed – my working system
      • /dev/sda6 – swap partition, shared between both Ubuntu systems
      • /dev/sda7 – ext3 formatted, the 7.10 64Bit Ubuntu installatio
  3. merge partitions with GParted.
    Deleting the partition I can do out of my running system, but to allocate the space I have to run GParted from a live CD or the GParted standalone Live CD (Available as ISO Download)
  4. update grub:
    daniel@t61:~$ sudo update-grub
    Searching for GRUB installation directory ... found: /boot/grub
    Searching for default file ... found: /boot/grub/default
    Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
    Searching for splash image ... none found, skipping ...
    Found kernel: /boot/vmlinuz-2.6.24-16-generic
    Found kernel: /boot/vmlinuz-2.6.22-14-generic
    Found kernel: /boot/memtest86+.bin
    Updating /boot/grub/menu.lst ... done

    If you don’t have grub installed on the currently active system, you can install grub using:

    sudo grub-install
  5. totally incredible, but that’s already it! I tested it by restarting, booting Ubuntu, Windows and back again. Only thing still not working is booting both the same time. 😀
    To get a proper differentiation for the Rescue&Recovery and the actual Vista system I update the menu.lst to:

    # This entry automatically added by the Debian installer for a non-linux OS
    # on /dev/sda1
    title        Windows Vista/Longhorn (Rescue&Recovery)
    root        (hd0,0)
    chainloader    +1

    # This entry automatically added by the Debian installer for a non-linux OS
    # on /dev/sda2
    title        Windows Vista/Longhorn
    root        (hd0,1)
    chainloader    +1

That’s it. There might be quicker ways, but I wanted to be sure ot take all precautions I could think of. So, if you have suggestions and comments, feel free to leave them.


2 Responses

  1. Hi,

    I have a laptop (Dell xps m1530) that dual boots from Vista and Ubuntu 8.04. I want to delete my Vista partition and merge it with my Ubuntu partition. Which partition is Vista? Which is Ubuntu? How will your instructions change?

    Here is what fdisk -l gives me:

    Device Boot Start End Blocks Id System
    /dev/sda1 * 30075 30402 2620416 c W95 FAT32 (LBA)
    /dev/sda2 13 1318 10485760 7 HPFS/NTFS
    /dev/sda3 * 1318 23379 177204216 7 HPFS/NTFS
    /dev/sda4 23380 30402 56405528 f W95 Ext’d (LBA)
    /dev/sda5 30075 30402 2620416 dd Unknown
    /dev/sda6 23380 29795 51536488+ 83 Linux
    /dev/sda7 29796 30074 2241036 82 Linux swap / Solaris

    Thanks in advance!

  2. Hi, I assume you are using grub as Boot Manager, therefore you should just be able to delete the NTFS and FAT32 partitions and merge them with the Linux partition. You can for example use a gparted Boot disk to do so.

    If you don’t use grub you should install it in Ubuntu first with ‘sudo grub-install’.

    It’s been a while for me since I did that myself, so try to check for example the Ubuntu forums for confirmation.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: