LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-27-2008, 07:20 PM   #1
Bendude
LQ Newbie
 
Registered: Jan 2008
Location: Australia, Mandurah
Distribution: Fedora Core 13
Posts: 27

Rep: Reputation: 15
Removed kernel using Synaptic manager


My uncle was trying to clean up his Ubuntu installation by removing some old kernels using the synaptic package manager. But he removed them all and now the grub loader only shows a mem test and the windows options.

We used a live cd and we can see his file system still intact.

Is there anyway to recover the kernel or just put it back into the grub options?

i should probably add that when we boot with a live cd the boot directory is empty all but the grub folder. missing vmz, init files etc

Thanks in advance

Ben
 
Old 08-27-2008, 08:01 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
You should be able to chroot into the disk system, then maybe use dpkg.
I got into a bind during testing the beta for Hardy, but I still had cache/status entries that wouldn't allow Synaptic to pull down a kernel it thougt was still there.
Bit of hacking got it working - should be some doco on the Debian site(s) I would think.
 
Old 08-27-2008, 08:20 PM   #3
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by Bendude View Post
Is there anyway to recover the kernel or just put it back into the grub options?
You might be able to use chroot and aptitude to reinstall the kernel after booting from the Live CD. After booting from the Live CD, you would open a terminal window and run
Code:
# chroot /media/whatever bash
# aptitude
where "/media/whatever" is wherever your "/boot" partition got mounted. It may be under "/mnt" or somewhere similar.
 
Old 08-27-2008, 08:37 PM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Hahahahaha! That's almost as good as removing "libc".

Since it's a stock Ubuntu, that makes things very easy:

1. Boot the live CD, but add the "root=/dev/sda1" (or whatever the Linux partition is) option. The machine
should still boot - you just can't load any more drivers when you have the final filesystem because there will be none in the /lib/modules/$(uname -r) directory.

2. If you didn't delete the package files, they will be in /var/cache/apt/archives - find a kernel and install it:
ls -l linux-image*
dpkg -i your_linux_image.deb

And that should be it.

I assume you won't have network access because it may be impossible to load the driver until you've fixed the kernel problem. If the package files were removed ('cleaned') you should still be able to install from a CD repository - worst case is you mount the CD and go to the 'pool' directory then:
find . -name "linux-image-*"
and cd to the directory and install using dpkg -i

Just one note - you will often see packages like these:
linux-image-2.6-686
linux-image-2.6.18-5-686

The first package is a "metapackage" - it depends on the latest 2.6.*-686 kernel and forces a kernel update when one is available. In general this is a nuisance (you should choose when you want to upgrade a kernel - but you should also watch for news of kernel exploits). So if a metapackage was installed, you may want to 'uninstall' it - this will not remove your current kernel, it will just prevent automatic updates.
 
Old 08-27-2008, 08:40 PM   #5
Bendude
LQ Newbie
 
Registered: Jan 2008
Location: Australia, Mandurah
Distribution: Fedora Core 13
Posts: 27

Original Poster
Rep: Reputation: 15
ok thanks for the replies.

i tried

sudo chroot '/media/disk/boot' bash

but i get the error no such file or directory

do i need to point at the drive using another name like hd0?

if so how do i find out which one it is?

Thanks again
 
Old 08-27-2008, 08:59 PM   #6
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by Bendude View Post
i tried

sudo chroot '/media/disk/boot' bash

but i get the error no such file or directory
Ok, sorry. Try
Code:
# chroot /media/disk/root bash
# mount /boot
# aptitude
where "/media/disk/root" is wherever your root file system gets mounted by the Live CD. "mount /boot" will mount your "/boot" partition in the place pointed to by "/etc/fstab".
 
Old 08-27-2008, 09:05 PM   #7
Bendude
LQ Newbie
 
Registered: Jan 2008
Location: Australia, Mandurah
Distribution: Fedora Core 13
Posts: 27

Original Poster
Rep: Reputation: 15
Quote:
Boot the live CD, but add the "root=/dev/sda1" (or whatever the Linux partition is) option. The machine
should still boot - you just can't load any more drivers when you have the final filesystem because there will be none in the /lib/modules/$(uname -r) directory.
i can not get it to boot into his file system doing this it just unrecognized device string.

Quote:
2. If you didn't delete the package files, they will be in /var/cache/apt/archives - find a kernel and install it:
ls -l linux-image*
dpkg -i your_linux_image.deb
nope he did not delete teh package files i can see them if i boot using the live cd. i ran these commands and it worked but i got an error saying

update-initramfs is disabled since running on a live cd
the link /initrd.img is a dangling linkto /boot/initrd.img-2.6.24-19-generic

Thanks for all the help
 
Old 08-27-2008, 11:48 PM   #8
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
You should be able to boot using the LiveCD, find out what device/partition has linux, and set the correct "root=" parameter. The /sys/block virtual directory has a list of 'block devices' on the system; my laptop has an 'hda', 'sda', and numerous 'ram*' devices. A hard disk will be 'hd*' or 'sd*' - since my laptop only has 'hda' and 'sda':

fdisk -l /dev/sda
Device Boot Start End Blocks Id System
/dev/sda1 267 12921 95671800 83 Linux
/dev/sda2 1 266 2010928+ 82 Linux swap / Solaris

I can see that I have Linux installed on /dev/sda1 (well, it just says the filesystem is for Linux but I know that I installed Linux there)

fdisk -l /dev/hda
-- No response - this is because 'hda' is my CD drive.


Once you've identified the Linux root partition, you can reboot the CD, choose "boot CD" but add the correct "root=" line and continue as described previously.

Another option is not to reboot - you can do the "chroot" trick (a little more work):

1. find out where the root filesystem was automounted by Ubuntu:
mount

2. Let's pretend it was '/mnt/hda1' (substitute your real partition here) - if you do 'ls /mnt/hda1' you should see directories like 'etc', 'var', 'dev', 'proc' and so on

3. Remount essential system virtual directories:
mount --bind /dev /mnt/hda1/dev
mount --bind /proc /mnt/hda1/proc
mount --bind /sys /mnt/hda1/sys
Note: if the 'busybox' version of 'mount' is used, then instead of "mount --bind" you need to use "mount -o bind"

4. Do a chroot:
chroot /mnt/hda1 /bin/sh

5. Fix up the system as previously described


I forgot to mention: Ubuntu has an extremely annoying 'feature' - you can't log in as root or use 'su'. The solution is to do "sudo -i" which should act as if you were logged in as root; just use 'exit' when you're finished with your root tricks.

Last edited by pinniped; 08-27-2008 at 11:50 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Synaptic Package Manager kiwipete Linux - Newbie 6 05-17-2008 08:12 PM
synaptic manager problem ambi Linux - Software 1 02-12-2008 08:04 AM
no synaptic package manager unisol Debian 1 01-09-2007 07:23 AM
Removed Xrandr & dpndnts, Synaptic now no go: fear 2 shut down PeteAJ Ubuntu 1 01-30-2006 08:18 PM
Synaptic Package Manager bignester Linux - Software 1 09-08-2005 04:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration