Tuesday, November 21. 2006Violence is the only solution (sometimes)
Just got a VDS account from Gigahost, because I'm too lazy to keep a box running at home at all times. Their "Lite" VDS plan is decent enough, for the price. (Watch out for their draconian TOS though, if you intend to do anything stupid like BitTorrent hosting, which I don't.) The only problem for me - they have CentOS pre-installed on my VDS, but I'd much rather be running Debian.
So the first thing I did was file a support ticket asking for Debian. They said nope - the only distros offered are CentOS and Fedora Core. Looks like I'll have to take matters into my own clenched fists of fury. >:-) Step 0: Backup everything you'd hate to lose. This is a must! The steps I describe below are crazy stuff. Don't try them without a full backup and/or a promise from your VDS provider to restore your node free of charge when it's absolutely hosed. Step 1: Know your environment. The Gigahost VDS runs on OpenVZ. An OpenVZ VDS (which they call a "virtual environment", VE) gives you just one partition (a simfs shim to the underlying filesystem in the host node) to work with, and the swap partition is also shared from the host node which you can't touch, so the conventional partition switcheroo (i.e. install a rescue distro in a new partition, boot from that partition, wipe out original partition, install Debian there) is out of the question. And this being a VDS and not an actual machine, I do not have physical access to the console or the CD-ROM drive, of course. The only way I can get to my VDS is by ssh. So the only option is to replace the distro in-place, in the same partition, while the old distro is running, which at first sounds like absolute insanity. But if you think about how Linux works, it's entirely doable, with care. I'm going to outline what I did in my specific case (OpenVZ VE, from CentOS to Debian), but I guess the technique can be easily generalised to many other situations where you have no physical access and no extra partition to spare. Step 2: Get Debian. The general idea here is to create an image of an entire Debian installation under some subdirectory in your original VE. I'm going to use /newdist. Just mkdir /newdist and treat it as the root where your Debian distro will reside. (For those familiar with the partition switcheroo operation, this is like mounting a new partition on /newdist and installing Debian into that partition.)You have quite a few options to go about actually creating a Debian installation under /newdist:
Step 3: Prepare the Debian environment. The Debian tree you have just slurped into /newdist is either a fresh base image or an image intended for some other box. At the very least you should look into the following things to make sure the image is set up for your specific environment:
Step 4: Make sure you're not about to be screwed. We're about to switch from CentOS into Debian. Roughly, the game plan for the switch (Don't do it yet! I'm only describing it so I can explain stuff) is: (1) mkdir /olddist; (2) For everything under root except /lib, /proc, /newdist and /olddist, move under /olddist; (3) For every directory under /newdist except /lib and /proc, move up to root; (4) Update /lib using the library files from /newdist/lib.The one problem we absolutely don't want to run into during the process is missing dynamic libraries; if this ever happens, we're irreversibly stranded. (We have no physical access and no alternative rescue distro to boot into, remember.) So we need to make very sure we don't move /lib at point (2), and take extreme care to update /lib in-place at point (4). It's also a good idea to get into the habit of running commands using absolute paths -- between point (2) and point (3), /bin/mv will have become /olddist/bin/mv so you can no longer depend on $PATH to find mv for you.We also don't want non-essential services running, which may give us problems by locking files, writing to the filesystem, and creating extra processes which try to link to dynamic libraries that are no longer there etc.. So identify and stop those services. Do a runlevel to see which level you're in. If in level 3, ls -aF /etc/rc.d/rc3.d and find out which services are started in this level. Terminate all of them except ssh by doing /etc/init.d/the_service stop one by one. If your box was set up by a diabolical hacker, some services might have been set up via a "respawn" entry in /etc/inittab. You need to find these as well, edit out those lines from /etc/inittab, and do a telinit q to re-read /etc/inittab and stop those services.Step 5: Switch! The fun part. Feel the adrenaline rush! I've already laid out the game plan just now, but here's a more detailed breakdown:
init thinks that /etc/inittab is in /olddist/etc/inittab; ssh can't create any pseudo ttys in /dev/pts. If you plan to stay for a while and do some final checking, you'd better do these to make sure you can get back in in case ssh drops your connection:
Step 6: Reboot! Once you're ready to press the big red button, do your /sbin/init 6, or call your tech support, or do whatever your VDS requires you to do in order to reboot.Hopefully, in a few minutes, your new Debianised (civilised!) VDS will be ready for you. You may now retain /olddist for keepsake, backup old data from it, or just blow it away. At this stage, you may also want to compare /lib with /newdist/lib and remove all the extra fluff left around in /lib by the old distro, before you upgrade the libc6 package after which /lib will be mangled beyond recognition. Enjoy your brand new Debian node. Or, if you now find out your host won't boot, enjoy the recovery process. (You have backed up, haven't you?) Assumptions To keep the scenario simple, I'm assuming you don't need to back up any user accounts. If you have such needs, you'll have to setup /newdist/etc/passwd and /newdist/etc/shadow properly before the mass migration, and take care to preserve stuff from /root and /home/* as required. I'm also assuming your existing distro is equipped with the usual stuff in the usual place - /bin/mv, /bin/tar, /(s)bin/mount, dynamically linked to a reasonably modern libc in /lib etc.. Distros that are too old / esoteric may not work. |
What I read / 讀物Loading...
Disgusted? / 作嘔?Try these other blogs. / 由此路逃生。
Syndicate This BlogBlog AdministrationLicensing |

Seriously, I don't understand a goddamn word but I'm sure it's all ace.
Go griff!
Finally I get a VPS in veggiehost to get benefits of international bandwidth, and a fresh new Debian by default
While I will deploy two VPS to gigahost and readyspace later for my company projects, I will try to switch them to Debian Etch .. hehe
Revolution never end!
Clicking the big red button let the system downed for few minutes .. I was so worried coz I have asked the tech supp to refresh the system once and did the checking for an hour to let everything goes smooth .. haha !!
As an update, the following are specific to gigahost's revolution:
1. /etc/network/interface need to append a venet0:0 device at the bottom of the file:
auto venet0:0
iface venet0:0 inet static
address 123.242.XXX.XXX
netmask 255.255.255.255
broadcast 123.242.XXX.XXX
2. Compare debian:/etc/rc2.d and centos:/etc/rc3.d; and debian:/etc/rc6.d and centos:/etc/rc6.d; got a "vzquota" link difference
3. in the lengthy /dev folder, photohunt expert is required, "core", "fd" and "simfs" are that need to take care. I just use a "cp -a /dev/xxx /newdist/dev/xxx" to perform the work. Coz I dunno how to make the MAKEDEV works ... -_-!
4. This time I make use of two network connection in the critical part, one from my working place and one from a remote server. Remote server use "screen" to ensure no disconnection even if my working place network suddenly drop ... a painful experience -____-!!!
Finally, thanks griffinn for detail description! ;D