# Reinstalling Ubuntu from the command line

I recently upgraded my HTPC to 11.04 and since it comes with the Unity dock I decided to get rid of Cairo dock. Unfortunately, while trying to uninstall Cairo dock I ended up removing too many packages (I even saw some NVidia packages being removed) and Ubuntu won't run anymore. I get to a black screen which lists a bunch of daemons that have started and then it goes no further, not even a command prompt. I can get to the command prompt if I start in recovery mode.

I have tried running the following commands but none of them fixed the problem:

sudo apt-get install ubuntu-desktop


This one completed successfully but did nothing.

dpkg-reconfigure -phigh -a


This failed, I don't have the exact error message right now, but it complained about an unrecognized image or some such thing.

dpkg-reconfigure xserver-xorg


This didn't seem to do anything.

I can reinstall the OS without any loss of data because all of it is on a second drive, the only changes I'd made to the OS were installing XBMC, Samba and Cairo dock. However, to complicate things further, I can't boot off of a USB drive anymore! I know that used to work because that was how I'd installed Lucid in the first place, but now, even though the BIOS list an attached storage device, Grub (or maybe it's the BIOS? not sure which one) won't recognize that the USB drive is bootable. I've tried creating the bootable USB using UNetbootin and Universal USB Installer, with both 11.04 and 10.04, but no combination is working. The PC does not have an optical drive, so USB is the only option.

Is there a command-line command to reinstall the OS? Or do I need to pull the hard drive and wipe it?

EDIT 1

Running ls /var/log/dpkg.* lists the following files:

• /var/log/dpkg.log
• /var/log/dpkg.log.1
• /var/log/dpkg.log.2.gz

...

• /var/log/dpkg.log.10.gz

I tried to upload the first log file to pastebin using pastebinit /var/log/dpkg.log but it fails with the following error:

IOError: [Errno socket error] [Errno 104] Connection reset by peer


dpkg-reconfigure -phigh -a


fails with the following error:

update-initramfs: Generating /boot/initrd.img-2.6.35-22-generic-pae
cron stop/waiting
dpkg-maintscript-helper: error: couldn't identify the package

-
Have you checked the boot sequence in the BIOS? Or do does it give a "Boot menu" option on boot. If it has booted to USB before, I can't see why it won't now. Other than that, you might want to check what got removed. It should have been logged. Run ls /var/log/dpkg.* to see what's available. –  Oli May 31 '11 at 16:23
@Oli: yes, removable storage device has the highest boot priority in the BIOS. I'll look at the log and list the available packages, but won't be able to do it several hours. –  Praetorian May 31 '11 at 16:35
pastebinit is a useful tool for getting big log files out of a headless system (it posts the whole file to paste.ubuntu.com so you can either get at it from a graphical system or share it with us. –  Oli May 31 '11 at 16:38
Thanks for the pastebinit tip, that should save me a whole bunch of typing :) –  Praetorian May 31 '11 at 18:11

Fixed the problem by reinstalling the nvidia drivers:

sudo apt-get install nvidia-current
sudo modprobe nvidia-current
sudo lsmod | grep -i nvidia
sudo nvidia-xconfig


Followed the instructions on this website.

-
Glad you got it working! –  Oli Jun 1 '11 at 10:40
Bluetooth is still dead, but I've read some bug reports suggesting bluez may be broken in Natty. I'll post that in another question if I can't get it working tonight. –  Praetorian Jun 1 '11 at 15:06