Your trail: RemotelyConvertDedicatedServerToDebian
How to Convert your dedicated server to Debian GNU/Linux
There are many hosting companies offering all-inclusive dedicated server packages for a low monthly fee. Unfortunately, few of these companies pre-install Debian. Debian fans were often excluded from some of the best hosting deals - until now. This howto will show you how to convert your hosted server to Debian, even if you don't have physical access to the machine.
WARNING: Trying to convert a remote server from one operating system to another can be a risky process. You may not be able to gain access to the machine's console. You should not do this on a machine that is in production use, as there could be several hours of downtime. Your hosting provider may charge you a fee if they have to enter any commands for you at the console. You will probably lose all data stored on the server.
WARNING: For those of you who didn't read the last paragraph: Follow these instructions to the letter and the only guarantee I make is that YOU WILL LOSE EVERYTHING THAT IS ON YOUR DEDICATED SERVER. This is a normal consequence of installing a new operating system.
That said, if you have just purchased the machine/hosting contract, and there is just a default installation on the hard disk, then you've got nothing to lose.
The good news is, you can do all of this before breakfast if you are confident with Debian administration. If not, I recommend you practice installing at least three times onto a machine that you have physical access to before trying to install Debian onto a remote server.
Analyse the machine's hardware and network configuration
You will need the following information. The dmesg command will help you.
- What CPU does the machine have?
- Does it have multiple CPU's?
- How much memory is in the machine?
- What hard disk is there?
- What is the hard disk interface (IDE, SCSI or a hardware RAID)?
- What Linux drivers are needed for the hard disk?
- How is the hard disk partitioned?
- What network controller is in use?
- Which Linux driver is required for that network controller?
- How is the bootloader configured? The bootloader is probably grub or LILO.
- If using LILO, what is in the file /etc/lilo.conf?
- If using grub, see /boot/grub
The lilo/grub configuration is quite important - you may need details from this file to boot if your dedicated server has an obscure hard disk subsystem (ie anything other than IDE). Seriously consider printing out the contents of this file!
Prepare a Debian kernel
On an existing PC that you already have running Debian, prepare a kernel for the dedicated server. Make sure the kernel you prepare has got the network and hard disk subsystem drivers built in (not as modules).
Use the following commands to build a kernel package and a zImage kernal file:
make-kpkg binary-arch
make zImage
Use the swap partition
The swap partition will give you the leverage you need to get the machine into Debian. On the dedicated server, log in as root. Disable all swap with the command:
swapoff -a
Use fdisk to change the type of the swap partition from 82 (Linux swap) to 83 (Linux). Then format the partition with this command:
mkfs -t ext2 /dev/hdaXXX
Where XXX is the number of the swap partition (assuming you have an IDE hard disk).
Prepare a temporary filesystem
Using a local machine, prepare a small Debian installation that has the following properties:
- Includes sshd server and an account that you can log in with over ssh (ie not root)
- Has the same network parameters as your dedicated server
- Has lilo.conf/grub configuration identical to your dedicated server, except for one change: the root partition is now the partition that was formerly used for swap
- Has a few basic utilities like scp, tar, bunzip2, wget, netcat, fdisk, mkfs.ext2/mkfs.ext3
- Contains the kernel you have just compiled
- No swap partition specified in /etc/fstab
- No partitions except / and /proc specified in /etc/fstab
For more details on how to prepare such a filesystem, see the debootstrap command, it is described here .
Tar and bzip2 that entire filesystem into a single archive file:
cd /tmp/bootfs
tar cf ~/bootfs.tar.bz2 --bzip2 .
Upload the file to the dedicated server. Mount the former swap partition under /mnt and extract your temporary filesystem there:
mount /dev/hdaXXX /mnt
cd /mnt
tar xf /tmp/bootfs.tar.bz2 --bzip2
Now do the following. This will mean that on your next boot, your dedicated server will boot into the temporary Debian install on the swap partition:
chroot /mnt /bin/bash
lilo
If using grub, you would type this instead:
chroot /mnt /bin/bash
grub-install
Now you are ready to reboot the dedicated server:
shutdown -r now
Within 3 minutes, you should be able to log into your temporary Debian using ssh. If not, you have made a mistake and will need to either:
- go into the data center and complete the install onsite, or
- call the ISP and get them to tell you what is on the console and then get them to bring it up again for you. They might charge a fee for doing this. They should be able to just boot it with a boot disk, manually edit lilo.conf back to the way it was, run lilo and reboot and everything will be back to the point just before you ran lilo before. You can then try again.
Once you have been able to connect to the server, you are ready to continue.
Do a proper Debian install
Now you are running off a filesystem within the swap partition. So you can safely erase and repartition the rest of the hard disk as you see fit. Just remember not to delete or erase the swap partition under any circumstances, until everything is working and rebooted.
Once you have got the partitions the way you want them, format them with mkfs
Now mount your intended root (/) partition under /mnt. Again, upload your temporary Debian filesystem into that root. And again, chroot into that filesystem, configure lilo.conf (or grub), run lilo, type shutdown -r now and wait. If you have followed the steps precisely, your server comes up in Debian, running off the real root partition and not the swap partition this time.
Re-create the swap
Now use fdisk to turn the swap partition back into a type 82 swap partition. Then run
mkswap /dev/hdaXXX
where XXX specifies your swap. Finally, you can put the swap into /etc/fstab and type
swapon /dev/hdaXXX
Complete your Debian install
The temporary filesystem probably didn't have many goodies in it (like Postfix, Apache, or your favorite servlet container). Now you can start installing these things.
|
|