Candidate for Deletion
We will be describing how to install Ubuntu from within your current distribution, replacing your current distribution ON THE SAME PARTITION. Anytime you do a major re installation you run the risk of losing data. The programs used in installation are quite reliable and most have seen years of use; but they are also quite powerful and a false move can cost you.
You would use this procedure when you have no boot Ubuntu install disk, and no cd burner. It can also be useful for saving your old homedirs when you have no way to back them up, and your file system is of a type that can't be resized to allow for a new partition.
Before We Begin
Things You Will Need
- Any linux boot/rescue cd with standard utilities for your filesystem (often the install disk for your current distribution will work fine, as long as you can get to a shell)
- A network connection. There's no need for the Ubuntu install disk.
- The package "alien", to convert the install package to your own distribution's format, from that of Ubuntu. You should install this now, if it isn't already on your system.
- To verify that Ubuntu supports your current file system.
- To convert your current distribution's bootloader to "grub", unless it already uses it.
We will be assuming RPM as the package management for the original OS in this howto, but alien converts between quite a few formats.
Summary of Actions to be taken
The following is a summary of the steps involved.
Get debootstrap(w/install scripts), convert with the "Alien" package converter, and install to original system.
- Run the install scripts, wait, configure the new system, and install a few things.
- Configure bootloader and reboot to rescue disk.
Move some things around -- out with the old, and in with the new.
- Boot to Ubuntu
- Install and configure the rest of the system
Install Debootstrap and Ubuntu Debootstrap Scripts
Grab the latest debootstrap_*.deb from http://archive.ubuntulinux.org/ubuntu/pool/main/d/debootstrap/. Make sure it matches your architecture.
- Using alien, convert the package to your distribution's format. For example:
# alien -r debootstrap*.deb
- Now install the new RPM package as you normally would for your distribution. If your distribution already has debootstrap installed (debian?), then uninstall it, and install the package you downloaded.
# rpm -iv debootstrap*.rpm
- Locate the installation directory for the scripts. This should be in /opt or in /usr.
# find /opt | grep debootstrap\/scripts; find /usr | grep debootstrap\/scripts
- This should return the location of pathnames that contain debootstrap/scripts, for example:
/usr/lib/debootstrap/scripts /usr/lib/debootstrap/scripts/sid /usr/lib/debootstrap/scripts/hoary /usr/lib/debootstrap/scripts/sarge /usr/lib/debootstrap/scripts/slink /usr/lib/debootstrap/scripts/warty /usr/lib/debootstrap/scripts/woody /usr/lib/debootstrap/scripts/woody.buildd /usr/lib/debootstrap/scripts/potato /usr/lib/debootstrap/scripts/hoary.buildd /usr/lib/debootstrap/scripts/sid.buildd /usr/lib/debootstrap/scripts/warty.buildd /usr/lib/debootstrap/scripts/sarge.buildd
- Set DEBOOTSTRAP_DIR environment variable and start the install.
- Make sure DEBOOTSTRAP_DIR is set to the path you got above (not including the "scripts" directory).
# export DEBOOTSTRAP_DIR="/usr/lib/debootstrap" # cd /usr/lib/debootstrap/scripts # debootstrap --arch i386 warty /mnt/ubuntu http://archive.ubuntulinux.org/ubuntu warty ^1^ ^2^ ^^3^^
- For 1: Choose your processor architecture (all, including new, pc's are i386).
For 2: Choose the directory to install to. Choose something unique, like /mnt/ubuntu. Don't choose a used directory.
- For 3: Choose an appropriate, up-to-date mirror, or use the above address.
Wait for the install to finish. If your network is unreliable, then you may need to run debootstrap multiple times to complete the installation. It should resume where it left off. If it has successfully installed, you should see the message "Base system installed successfully" near the end of its output. If you run into a problem unrelated to networking, you may need to delete all of the installed files and directories and restart.
Set up Fstab
- Create your fstab. You can copy your current one, but you may need to make a couple changes.
# cp /etc/fstab /mnt/ubuntu/etc/fstab # nano /mnt/ubuntu/etc/fstab
You can use your favorite text editor in place of nano above.
- Change the mount points on the partition(s) you set up in step 1
- Change their options to "defaults"
- Change the Type to whatever Filesystem is on that particular partition.
- Change /mnt/auto/floppy to /mnt/floppy. Do the same for /mnt/cdrom.
- Add "sync" to the options for /mnt/floppy.
- Remove the /dev/pts line -- not needed?
Here is a decent fstab file:
#FileSystem MountPT FSType Options Dump fsck-order #System Mounts.. /proc /proc proc defaults 0 0 /sys /sys sysfs defaults 0 0 #Hard Drives.. ..edit these if necessary /dev/hda2 none swap defaults 0 0 /dev/hda3 / ext3 defaults 0 1 /dev/hda6 /home ext3 defaults 0 2 #Uncomment and edit the following line if you have a boot partition #/dev/hda1 /boot ext2 defaults,noauto 0 0 #Removable Media.. /dev/fd0 /mnt/floppy auto user,noauto,sync,exec,umask=000 0 0 /dev/cdrom /mnt/cdrom auto user,noauto,exec,ro 0 0
Make sure your / entry has options set to 'defaults', otherwise sudo may not function: "Sorry, sudo must be setuid root."
Set up Hostname and Networking
You should replace HOSTNAME in the command below with the desired name for your machine. You may need to remove /mnt/ubuntu/etc/hostname first, because it may be a symbolic link to your current /etc/hostname by default, due to a bug in some versions of debootstrap.
# rm -f /mnt/ubuntu/etc/hostname # echo $HOSTNAME > /mnt/ubuntu/etc/hostname
- If you are running a debian-based distribution already, you can copy /etc/network.interfaces.
- Copy the resolv.conf, as in the second line below:
# cp /etc/network/interfaces /mnt/ubuntu/etc/network/ # cp /etc/resolv.conf /mnt/ubuntu/etc/ # nano /mnt/ubuntu/etc/network/interfaces
Here is my Ubuntu /etc/network/interfaces setup (in /mnt/ubuntu/etc/network/).
auto lo iface lo inet loopback auto wlan0 iface wlan0 inet dhcp
You also need to set up the hosts file to include your machine name.
# cp /etc/hosts /mnt/ubuntu/etc/ # nano /mnt/ubuntu/etc/hosts
Here is an example /etc/hosts file for cowflavors.dyndns.org.
127.0.0.1 localhost 127.0.0.1 cowflavors.dyndns.org cowflavors
Enter the Install Environment
Chroot puts you in the new Ubuntu environment. "mount /proc" mounts proc in the new environment. You may also need to mount /sys, if you are on a 2.6 kernel. Finally if you run into errors accessing devices, mount /sys.
If you have a separate boot partition, mount /boot before you do the other three commands.
# mount /boot #If you have a separate boot partition. # mount -o bind /boot /mnt/ubuntu/boot # chroot /mnt/ubuntu # mount /proc
Set up Base System
Setting up your locale and keyboard.
"""***If you do not do this then dpkg, may have problems, due to a bug in certain versions of dpkg."""
I use en-US ISO 8859-1, as I don't often type international characters, and can use a character selector in X when I do. en-US ISO 8859-15 contains mapping to type international characters. ("u becomes ü, etc)
# dpkg-reconfigure locales console-data
Install the Kernel and Botloader
When installing the linux kernel below, you have the option of installing one specifically for your particular processor.
Your options are: linux-image-386 Safest linux-image-686 Optimized for Intel PPro/Celeron/PII/PIII/PIV linux-image-686-smp Intel multiprocessor or hyperthreading machines. linux-image-k7 AMD K7, Athlon, AthlonXP etc. and higher. linux-image-k7-smp AMD K7, etc. Multiprocessor systems
# apt-get install linux-image-386 # apt-get install grub
Configuring Grub for Both Systems
As was mentioned initially, your original distribution should be using Grub. Grub is much more flexible than Lilo, and works very well for our purposes. Since your present/original system should already boot from Grub, all we have to do here is edit the menu.lst file to add Ubuntu.
Because Linux starts numbering at hda1, but grub starts at (hd0,0), you must subtract 1 from the partition number. (hd0,2) is equivalent to hda3, and (hd1,0) is equivalent to hdb1.
Edit /boot/grub/menu.lst (and/or /boot/grub/grub.conf). If you have both, check and see if they are identical. If so, do the following.
rm menu.lst ln -s grub.conf menu.lst
If they are not identical, either edit them both or determine which one your system boots from normally, keep that one, and make a link by the name of the original file which points to the file you kept (as above).
Insert the following into the file, with the following caveats.
- "root (hd0,0)", replacing (hd0,0) with the device that contains your kernels. This is usually either your root or boot partition. B. "kernel /vmlinuz root=/dev/hda3" and "initrd /initrd.img"
- If you have no boot partition, using the /vmlinuz and /initrd links should be fine.
If those do not work, use "kernel /boot/<YourCurrentKernel>" and "initrd /boot/<YourCurrentInitrd", I.e. vmlinuz-22.214.171.124-3 and initrd.img-126.96.36.199-3, respectively. You'll need to update these if and when you update your kernel in the future.
- BE SURE to update the "root=/dev/hda3" part to whatever partition is your root partition! If you don't, it will not boot past loading the kernel and initrd. It will panic and suggest using a proper device in the root= line.
title=Ubuntu root (hd0,0) kernel /vmlinuz root=/dev/hda3 initrd /initrd.img
Example of modified /boot/grub/menu.lst
default 0 timeout 4 title=Ubuntu root (hd0,0) kernel /vmlinuz root=/dev/hda3 initrd /initrd.img title=My Old Distribution root (hd0,0) kernel /bzImage.customYopper initrd /initrd.customYopper title=Memtest86 root (hd0,0) kernel /boot/memtest86+.bin
The version of Grub which your current distribution installed is in the bootsector, and will read the changes on bootup.
Now unmount the drives, and exit the subshell.
# exit <-- exits the chroot subshell # umount /mnt/ubuntu/boot
If you want, you can do an optional reinstall of grub, but it should be unnecessary. Replace hda with your system's default boot disk.
# grub-install /dev/hda
Insert the recovery CD-ROM and reboot.
Swapping in Your New Ubuntu
Once your recovery CD is done booting, first make a directory to mount the disk to.
If that doesn't work, type "mount" by itself, and look at the feedback. You're looking for a directory which has a read-write ramfs mounted.
# mount none on /example1 type ramfs (rw)
There, the directory /example1 is mounted! What a surprise.
If there is no mounted ramfs, try:
# mount -t ramfs none /mnt
Feel free to change /mnt to some other non-essential directory of your choice.
Now, to mount your root partition -- Do the following, but change /dev/hda3 to whatever your root partition is:
# mkdir /mnt/hd # mount /dev/hda3 /mnt/hd
Move your old distribution into a backup dir. If you have a boot partition, do not mount it.
# cd /mnt/hd # mkdir OldDistro # mv * OldDistro/ # ls -a
If the ls -a shows any files other than OldDistro, ., and .., move them into OldDistro. Then, move Ubuntu into the present directory. If the ls -a shows any files, move them into the current directory (/mnt/hd): Restore original boot directory (containing files to boot both distributions): Now, what you should have in /mnt/hd (your hard drive): Standard linux directories, but not the ones you want. Now, unmount and reboot. Eject the rescue cd before next bootup. Set up timezones, users, and apt. This is a lengthy process that will try to launch GDM at the end. Once that's done, if you're not in your new desktop, then reboot again, and all should be started. http://archive.ubuntulinux.org/ubuntu/dists/warty/main/installer-i386/current/doc/manual/en/apcs03.html . Another page that might prove helpful is http://www.inittab.de/manuals/debootstrap.html .
# mv .hiddenfiles OldDistro/
# mv OldDistro/mnt/ubuntu/* ./
# ls -a OldDistro/mnt/ubuntu/
# mv OldDistro/mnt/ubuntu/.dev ./
# mv boot boot.bak #This file should be empty anyways.
# mv OldDistro/boot ./
shutdown -r now
# /usr/sbin/base-config new
If the ls -a shows any files, move them into the current directory (/mnt/hd):
Restore original boot directory (containing files to boot both distributions):
Now, what you should have in /mnt/hd (your hard drive):
Standard linux directories, but not the ones you want.
Now, unmount and reboot.
Eject the rescue cd before next bootup.
Set up timezones, users, and apt. This is a lengthy process that will try to launch GDM at the end. Once that's done, if you're not in your new desktop, then reboot again, and all should be started.
http://archive.ubuntulinux.org/ubuntu/dists/warty/main/installer-i386/current/doc/manual/en/apcs03.html . Another page that might prove helpful is http://www.inittab.de/manuals/debootstrap.html .