Mark's Blog

de arte technologiæ
  • Tech Related (en)
  • my musings (de)
  • About Me

Gentoo on a linux-vserver partition with wrong initstyle

Posted by mark on 2010-02-25, 16:02 under technology related

Recently I’ve rented a server partition from a German provider which turned out to be a linux-vserver partition. About five or six years ago I have experimented with linux-vserver myself, still have headaches when it comes to its security implications…

Unfortunately the provider has not offered any Gentoo images. Despite that and by the means of the rescue shell, I have installed Gentoo on it. Here is how:

Keep in mind that you will not be able to run commands such as mount or mknod. Therefore neither udev will work (you won’t need it on servers anyway) nor will you be able to re-create an broken /dev directory.

WordPress destroys > and < signs in the following instructions. Click on “<>” of the code highlighter to view the commands.

Gentoo and linux-vserver with wrong initstyle, howto:

  1. Backup your data.
  2. Pick a system image for using its populated /dev directory. I have chosen Ubuntu 9.04.
  3. Launch the rescue system, log into it.

For the sake of brevity I will assume your main system will be mounted on /vserver.

  1. Install any tools you’re going to use during installation. E.g.:
    apt-get install less bzip2 lzma tar wget
    alias dir='ls -al --color'
    alias ls='ls -a --color'
  2. Now save nameserver settings. Network card IP and the such will already be provided by the host.
    cp /vserver/etc/resolv.conf /tmp/
  3. After that you will have to delete the old system (preserving /dev) and extract Gentoo stage 3 tarball, restore resolv.conf:
    rm -r /vserver/{bin,boot,etc,home,lib,lib64,media,mnt,opt,proc,root,sbin,selinux,srv,sys,tmp,usr,var}
    wget http://.../current-stage3/stage3-amd64-20100121.tar.bz2 -O - \
    | tar --exclude dev -xjp -C /vserver
    cp /tmp/resolv.conf /vserver/etc/

You’re almost done. Now come some modifications for your Gentoo system to be able to be launched by vserver start of the host.

  1. Get linux-vserver utils. You will need some of its scripts:
    wget http://ftp.linux-vserver.org/pub/utils/util-vserver/util-vserver-0.30.215.tar.bz2 -O - \
    | tar -xj -C /tmp
  2. Following is adapted from distrib/gentoo/initpost:
    rm /vserver/etc/runlevels/boot/{clock,consolefont,keymaps,modules,net.lo}
    rm /vserver/etc/runlevels/default/{hdparm,netmount}
    echo "/dev/hdv1 / ufs defaults 0 0" > /vserver/etc/fstab
    
    cat /tmp/util-vserver-0.30.215/distrib/gentoo/net.vserver > /vserver/etc/init.d/net.vserver
    chmod 0755 /vserver/etc/init.d/net.vserver
    ln -s "/etc/init.d/net.vserver" /vserver/etc/runlevels/boot/net.vserver
    
    cat /tmp/util-vserver-0.30.215/distrib/gentoo/reboot.sh > /vserver/etc/init.d/reboot.sh
    chmod 0755 /vserver/etc/init.d/reboot.sh
    cat /tmp/util-vserver-0.30.215/distrib/gentoo/shutdown.sh > /vserver/etc/init.d/shutdown.sh
    chmod 0755 /vserver/etc/init.d/shutdown.sh
  3. Now comes the command, which is actually ran by vserver start. We will make it a wrapper to Gentoo‘s /sbin/rc. The partition will start with errors because mounting and the such will fail, but it will start.
    The RC script can be downloaded here.

    wget http://.../rc.bash -O /vserver/etc/init.d/rc
    chmod 0755 /vserver/etc/init.d/rc
  4. Change into the partition and enable SSH daemon. That way you will be able to continue Gentoo installation on the next “normal” boot. Do this:
    chroot /vserver /bin/bash
    passwd
    rc-update add sshd default
    exit

That’s all! Start in “normal” mode and continue Gentoo installation as usual. To get you going, the next steps are:

cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime
sed -ie 's:#TIMEZONE="Factory":TIMEZONE="Europe/Berlin":g' /etc/conf.d/clock

emerge --sync
emerge -1 mirrorselect && mirrorselect -D -s3 -b10 -o
# ...

Let me hear your success stories!

Tags: Gentoo, know-how, linux-vserver

8 Comments so far

  1. vmk on February 26th, 2010

    Your howto gave me some important hints for gentoo at netcups. I had to patch some more file the get rid of all errors/warnings while booting. I replaced mainly original scripts like checkfs, etc with the dummy init script.

    Little bug: The rc-script in part 9 has not the normal unix linebreaks. I had to convert the script with dos2unix after downloading with wget. I first doesn’t convert it and the controlpanel said to me: “execvp(“/etc/init.d/rc”): No such file or directory”.

    Great work!

  2. Markus Effinger on March 13th, 2010

    First of all thanks very much for this great tutorial!! I just noticed a small syntax error in the shell script on http://cdn.eu.ossdl.de/wp-content/uploads/2010/02/rc.bash. Instead of

    3)
    default)

    it should be

    3|default)

    otherwise you get the following errors when starting up in normal mode

    /etc/init.d/rc: line 21: syntax error near unexpected token `)’
    /etc/init.d/rc: line 21: `default)’

    An error occured while executing the vserver startup sequence; when
    there are no other messages, it is very likely that the init-script
    (/etc/init.d/rc 3) failed.

    Common causes are:
    * /etc/rc.d/rc on Fedora Core 1 and RH9 fails always; the ‘apt-rpm’ build
    method knows how to deal with this, but on existing installations,
    appending ‘true’ to this file will help.

  3. Erfahrungen mit Gentoo auf Linux-VServer « Abraxas on March 15th, 2010

    [...] Image verfügbar (@netcup:  hier besteht noch Verbesserungspotential), aber dank der Anleitung von Mark habe ich die Installation auch so geschafft (siehe auch mein Kommentar dort). Soweit lief alles [...]

  4. Jochen on March 18th, 2010

    Very big thanks for this guide! Finally I can run Gentoo on my vserver.

    I’m at netcup too. I had to migrate to baselayout-2 to get rid of some boot errors with mounting sys and proc fs. Also I had to comment out the line: file(“/proc/kmsg”); in syslog-ng’s config to run it.

  5. mark on March 18th, 2010

    I am happy to hear my instruction helped. And as your feedback is my motivation, its fruits are a Gentoo Binhost with packages optimized to my best knowledge:

    Alter your /etc/make.conf by adding:

    FEATURES="getbinpkg parallel-fetch userfetch userpriv"
    PORTAGE_BINHOST="http://binhost.ossdl.de/x86_64-pc-linux-gnu-nocona/"

    This should spare you a lot of compile-time, at least with the base system and dev-db/mysql-community, GCC, glibc, boost and the such. On troubles get and install the latest glibc by hand:

    cd /tmp
    wget http://binhost.ossdl.de/x86_64-pc-linux-gnu-nocona/sys-libs/glibc-2.11-r1.tbz2
    tar -xjvpf glibc-2.11-r1.tbz2 -C /

    (CHOST is still “x86_64-pc-linux-gnu”, I just had to point out that the packages are optimized for the Intel CPU family and thus rename that directory.)

    See also my Gentoo overlay and its mirror at gthub.

  6. HelAu on April 14th, 2010

    Hello,
    I just ordered my vServer at netcup and I also want to install gentoo on it.
    Do you also use SyCP under Gentoo ? If yes have you made a new installation or have you just saved the original installation ad restored this one ?
    Bye
    Helmut

  7. mark on April 18th, 2010

    Helmut, I do administer my server completely by hand. But you might find my modified version of VHCS2 for Gentoo useful.

  8. Waiting for vServer | eXeTech on August 30th, 2010

    [...] now I have ordered the vServer (its 1 a.m. here in germany) and have to wait until tomorrow. I hope, netcup will work fast on the morning and I get the vServer quickly. After that Unclefragger trys to install a gentoo on the vserver by using the rescue mode. The full methode is described here: http://mark.ossdl.de/2010/02/gentoo-on-a-linux-vserver-partition-with-wrong-initstyle/ [...]

Posting your comment.

  • Subscribe in a reader
    or get notified by email

    Add to Technorati Favorites

    Follow me on Twitter

  •  

    February 2010
    M T W T F S S
    « Jan   Mar »
    1234567
    891011121314
    15161718192021
    22232425262728
  • Tags

    Gentoo know-how linux-vserver

Copyright © 2008-2012 W-Mark Kubacki
WordPress Theme . Design

2008789101112
2009123456789101112
2010123456789101112
2011123456789101112
201212345