Install Ubuntu (hardy) 8.04 Remotely via SSH 32 or 64-bit

Published Date: Monday, August 04, 2008

The Story...

I wanted to use Ubuntu. I really liked my current provider, however, they did not offer ubuntu. Finding a provider that offered my current level of service and ubuntu was a real challenge. So, the thought was "if I can figure out how to remotely install ubuntu, then, i would have more options with regard to a provider as I would be able to install my own OS". Fortunately, my dedicated server was equiped with two drives. I decided to simply wipe the second drive clean, partition, format, and install the OS on the second drive.

Honestly, it took me almost ten days of trial and error to figure out all of the details of doing a remote install and to work out all of the bugs prior to actually attempting it remotely on a production server. I developed this process and simulated the remote install on one of my local machines prior to the actual install. The process is broken into three stages and is fully scripted. You should be able to download the scripts, configure them to meet your environment, and remote install via ssh.

Assumptions and prerequisites:
  • You will read everything in this article, the comments in the scripts, and the instructions after each stage
  • You will curse me if I forget something, but, forgive me anyway :)
  • You have a machine running a flavor of linux.
  • You can connect to the machine via ssh.
  • You have all of the mission critical data backed up.
  • You know ALL of your network settings.
  • You have checked with your provider and know that there are no special circumstances (firewall, etc.) that would prevent you from remotely installing an OS via ssh.
  • You are comfortable with resizing and partitioning a drive or you have a partition with enough space to install Ubuntu.
  • You are comfortable with formatting the partition (THE SCRIPTS WILL FORMAT THE PARTITION !!).
  • The "target machine" refers to the machine that Ubuntu is being installed.
  • You have "the archiver" A.K.A. "ar" installed on the target machine. Type ar --version to determine if you have ar already installed on the target machine.

GOTCHAS

Make sure "ar" is installed. the following command will install "the archiver" A.K.A. "ar" on Ubuntu.

apt-get install binutils

The install scripts utilize debootstrap. During the install, a file will be downloaded using wget. If the file does not exist, then, the install will fail. At the time of this writing the debootstrap file being used is: http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_1.0.10_all.deb
If the file does not exist:

  • Look for a newer version at: http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap
  • Make sure you choose one with a similar name and the latest version. i never had a problem when choosing debootstrap_?.?.??_all.deb format
  • Edit the file set-vars.sh and change the line: export DEBOOT_STRAP_DEB="debootstrap_1.0.10_all.deb" to point to the appropriate file.

Mission Critical!! Network settings

Before you do anything, copy all files containing network settings from your remote machine. You need ALL of your network settings, etc. also, a huge gotcha I ran into was the MAC address. I did all of my testing locally and did not use the MAC address in the network settings, however, my provider required the MAC address. Therefore, my first attempt at a remote install worked except for that one minor detail. I would have saved myself a lot of time and aggrevation if I would have determined ALL of my network settings beforehand!

Common files containing some network settings are: /etc/resolv.conf /etc/hostname /etc/hosts Also, you ABSOLUTELY need your network interfaces files. You are on your own to find these. I suggest reading the section about configuring network interface settings to understand the files you will need.

GRUB

You need to have an understanding of GRUB and how to configure it. During the second stage of the install, you will need to configure GRUB. A menu.lst will be configured for you. However, you need to decide if you will writing to the MBR. Notes regarding GRUB are displayed at the end of stage two. The most important item to pay close attention to is the (hd0,0) items. MAKE SURE THEY POINT TO THE CORRECT PARTITION!!! Although the menu.lst is created for you during the second stage, it seems that the (hd) items are always set to (hd0,0)!!

Making space

Here is an excellent doc detailing how to resize a partition: http://www.howtoforge.com/linux_resizing_ext3_partitions Again, I have a second hard drive on one of my remote server, however, I have used this process on machines with one hard drive.

The Install Process

The install process is broken into three stages. The purpose of breaking process into stages is because you will be put into a chroot environment at the end of stage one and I did not know a better way to script the process except breaking it into stages.

  • Stage One - installs a base operating system and puts the system into a chroot environment.
  • Stage Two - performs package installations, configuration, and reboot.
  • Stage Three - performs final package installations, distro upgrade, and reboot.

A brief rundown of the scripts The two most important files you need to pay attention to are set-vars.sh and install-network.sh!!
install.sh is the main script and calls set-vars.sh, then, calls install-os-1.sh. install-os-1.sh will do the work of installing the base system and will call install-network.sh, then, it will put the system into a chroot environment. That is the end of stage one. Instructions will be displayed at the end of each stage. run install-os-2.sh to begin the second stage. Follow all of the instructions as you will be prompted to create a user account, set passwords, etc. Towards the end of stage two, you will need to configure grub. Then, reboot the machine. Since you should still be in a chroot environment, it would be a good idea to check your network settings files and verify that everything looks good.

    Files of interest
  • /etc/fstab
  • /etc/hostname
  • /etc/network/interfaces
  • /etc/hosts
  • /etc/resolv.conf
When the server comes back, you will need to login using your newly created account. Then, cd / and run install-os-3.sh to begin the final stage. At this point the OS is installed and you can continue configuring your server. Don't forget to clean up all of the scripts and text files in the root directory!!

I highly recommend you download the scripts to your local machine and take a look at them to gain a full understanding. The scripts are very small and I seem to remember writing some comments. The scripts can be found at: http://blog.jeffduckett.com/downloads/install_via_ssh/scripts.tar

Also, it would be a very good idea to make some space, create a partition, and try the install on a local machine.

32 or 64 bit

The scripts will run on 32 or 64 bit systems. All you have to do is change a couple of lines in the set-vars.sh script!!

Installation Steps

  1. Connect to your remote machine via ssh
  2. Make space to install Ubuntu
  3. Create a temporary directory and change to that directory
  4. Download the scripts
    wget http://blog.jeffduckett.com/downloads/install_via_ssh/scripts.tar
  5. Make sure you are logged in as root
  6. Extract the scripts
    tar -xvf scripts.tar
  7. edit set-vars.sh
    vi set-vars.sh
  8. edit install-network.sh - don't forget about setting the swap partition!!
    vi install-network.sh
  9. run install.sh and follow the instructions at the end of each stage during the process
    ./install.sh

Good Luck!!

Duck

Problems or Questions??

Feel free to contact me via this page http://www.jeffduckett.com/common/contacts

Posted by Administrator on Monday, August 04, 2008