How do I delete my most recent Ubuntu installation?

Asked by Uwe Geuder

I have several Ubuntu installations on the same hard drive. (Plus XP plus other proprietary stuff for system recovery)

During booting I get the choices from /boot/grub/menu.lst. This works all nicely

However, If I think once more and check a bit, there is a different /boot/grub/menu.lst in each installation. It looks like the menu.lst from the most recently installed Ubuntu is really used (displayed on boot)

How does this work? I understand grub is in the MBR. Is the menu.lst file copied there or does the MBR contain a pointer to the menu.lst in the right partition?

Now I intend to delete my most recently installed Ubuntu. If grub had a pointer to menu.lst in my most recently installed partition, this might have fatal consequences.

So how do make sure that grub can still find a valid menu.lst after I have deleted my last partition?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu grub Edit question
Assignee:
No assignee Edit question
Solved by:
Uwe Geuder
Solved:
Last query:
Last reply:
Revision history for this message
Andre Mangan (kyphi) said :
#1

You will have to edit your menu.lst.

sudo gedit /boot/grub/menu.lst

Rather than deleting entries in that list, place ## in front of each line that you no longer require - that way it is easier to undo in case something goes wrong. The entries start after "end default options".

Don't forget to save the altered menu.lst.

To find where grub stage 1 is, use:

sudo grub
find /boot/grub/stage1

That will identify the drive and partition.

Revision history for this message
Uwe Geuder (ubuntulp-ugeuder) said :
#2

Thanks for your reply.

>To find where grub stage 1 is, use:

Not sure what stage1 means. I've read this term also in documentation, but still don't know what it is.

>That will identify the drive and partition.

That reports 2 locations

(hd0,4)
(hd0,6)

I understand in Linux-speak this means /dev/sda5 and /dev/sda7.

These are indeed the partitions where I have Ubuntu root file systems containing /boot/grub.

So how does grub decide, which one to use? Does it just use the newest one (hd0,6)? And if I delete that partition it uses (hd0,4) because it's the newest = only one?

(I know it uses the one from from (hd0,6), because the menu.lst files are different)

That would be nice, but I'd rather be sure, before I render my machine non-booting.

Revision history for this message
Andre Mangan (kyphi) said :
#3

(Quote) "The MBR is in the first 512 bytes of the first sector of the first partition of the drive. It contains the partition table and the first-stage bootloader. The first-stage loader is a wee bit of code stored in the first 446 bytes of the MBR, which points the way to the second-stage loader, which is stored in the /boot directory. The remaining 66 bytes are for the partition table."(/Quote) ... from Carla Schroder's Linux Cookbook, 2005, O'Reilly Media, Inc.

Revision history for this message
Uwe Geuder (ubuntulp-ugeuder) said :
#4

Thanks Andre, this makes sense.

>which points the way to the second-stage loader, which is stored in the /boot directory

but I have two /boot directories, (I can see them and grub find reports them, so there is no doubt about that). And I want to delete the one that is currently in use.

So the question remains: How do I do that without ending up with a machine that does not boot?

Revision history for this message
Andre Mangan (kyphi) said :
#5

First step:
Everone should have some rescue tools such as a Super Grub Boot Disk.
You can make a boot rescue floppy via StartUp Manager (sudo apt-get install startupmanager) as well as restore your original boot settings.

Second step:
Edit /boot/grub/menu.lst and place ## before the boot option no longer required.

If everything works out the way you want it, you can delete the whole entry.

If you get stuck, use the rescue floppy.

Revision history for this message
Uwe Geuder (ubuntulp-ugeuder) said :
#6

Well, I'd prefer to understand what I do before starting doing it. At least when critical functionality like booting is involved. Trial and error might be more suitable in "normal" user space applications.

> Everone should have some rescue tools

I agree. More or less stupid errors still happen, although one assumed to know exactly what one is doing... Admittedly I don't have a boot disk, but I have another machine where I could create one, should it become necessary.

Additionally everybody should have backup of all valuable data, before starting to work with partitions. I have backup of all important user data. But I don't have a full disk image, so I don't have backup of many hours installation work that I have invested in this machine and wouldn't like to lose either. But the machine in question has only one 160 GB disk. And that's the biggest disk I have available at all. So I'm not sure how to take disk image. Maybe that would be the topic of another question.

>Edit /boot/grub/menu.lst and place ## before the boot option no longer required.

Hmm, I don't understand that advice. The menu.lst, which is currently in use will be deleted (because I want to remove that whole partition). So I can't see what purpose editing it before deleting it should serve.

The menu.lst, which is not in use should be perfect as far as its contents is concerned. The question is just, will it be used automatically after the last partition is gone, or do I need any manual step to make it happen.

Revision history for this message
Andre Mangan (kyphi) said :
#7

The difficulty with your question, Uwe is that if I tell you step by step what I would do in similar circumstances, I may make an error of judgement or I may have missed some critical aspect of your setup. The end-result would be, if something goes wrong, that I would be to blame and I am not going to risk that.

You must act on the information that you already had and what I have given you - in other words, bite the bullet and make an informed guess.

All I can do is wish you success.

Revision history for this message
Andre Mangan (kyphi) said :
#8

A boot disc belongs to the machine that created it so you cannot use a boot disc from another machine.

The menu.lst file to edit is the one that you boot into when accessing your total system, not the individual files.

Revision history for this message
Uwe Geuder (ubuntulp-ugeuder) said :
#9

> A boot disc belongs to the machine that created it so you cannot use a boot disc from another machine.

I don't think so.

http://www.supergrubdisk.org/wiki/SGD_Howto_make

According to the instructions the ready ISO image is downloaded and directly burned.

The original question is still open.

Revision history for this message
Andre Mangan (kyphi) said :
#10

You can make a boot rescue floppy via StartUp Manager (sudo apt-get install startupmanager) as well as restore your original boot settings.
This boot disc belongs to the machine that created it so you cannot use a boot disc from another machine.

The URL http://www.supergrubdisk.org/wiki/SGD_Howto_make refers to creating a Super Grub Boot Disk which is a general boot disc for any machine whether it is Linux, Mac or Windows.

As mentioned above, "comment out (##)" in menu.lst the entry you no longer need. If everything else still functions then delete.
If something does not function then remove the ## from the menu.lst item.

You loose nothing by trying this method.

Revision history for this message
Uwe Geuder (ubuntulp-ugeuder) said :
#11

I can now answer my own question (just in case somebody hits it when searching)

Grub is installed to the master boot record (MBR) (at least typically, I don't go into other cases here). But not all functionality fits
into the MBR, so it always points to a file system where its additional files (e.g menu.lst for grub or grub.cfg for grub2) reside.

Example:

1.) You install Ubuntu to sda1. grub is in the MBR and it points to it's additional files in sda1

2.) Now you install another Ubuntu to let's say sda6. By default grub will get installed again to the MBR (overwriting the previous one and it will point to its additional files in sda6

If you intend to wipe sda6, you first need to make sure that the reference in the MBR goes to sda1 again. You do this by running grub-install from the installation in sda1.

That's the answer to my original question.

Additional info:

1. If you install a second (or third, ...) Ubuntu and you know it's only temporary, you can skip its grub installation. This is done in the "Advanced" dialog of the last installation step in the LiveCD. In order to be able to boot to this second installation you first need to run update-grub in the first installation. (The kernel command line will be empty and it will boot slightly different. But for a temporary installation you can probably live with that. If not you need to edit manually) When you wipe such a second installation grub remains fully functional, because it uses only sda1

2. if you have several Ubuntus and the kernel ABI is upgraded, update-grub may need to be run twice. The first time in the system where the kernel is upgraded. This happens always automatically if you install standard Ubuntu kernel. If that system is not the one with the current grub installation an additional manual step is needed. Boot to the system owning grub and run update-grub. It will now pick up the changes from the system just upgraded. (Tested only with grub2)