Home > Gentoo > Installing Gentoo 2008.0 amd64 on a Linode VPS

Installing Gentoo 2008.0 amd64 on a Linode VPS

February 9th, 2009

Today I signed up for a Linode VPS. Linode appeared to have great reviews and very reasonable prices. I had originally looked at Host Virtual, primarily because they are planning to offer native ipv6 (something I’ve been wanting to play with) later this month.  I ended up with Linode because they have a Dallas datacenter which makes my connections from Austin pretty fast.

One advantage that Host Virtual provided was a more recent Gentoo image.  Linode only offers a Gentoo 2007.0 install, which it doesn’t even list as a current distribution.  No worries, in this post I describe the steps I took to install a fresh Gentoo 2008.0 amd64 image on my new Linode!

Update: On April 4 2009, Linode released a Gentoo 2008.0 x86_64 image, which somewhat obsoletes this post. I haven’t tried it, but if your looking to try 64-bit Gentoo on a Linode, try that image instead of these instructions.

Before we get started, some of the things I wanted on my system:

  • x86_64 kernel running natively compiled 64-bit applications
  • ReiserFS filesystem instead of ext3
  • Basic LAMP server and no more
Note: Currently, Linode does not provide a 64-bit recovery option, so we’ll have to install a small 64-bit environment to use when setting up our new Gentoo environment. This can be done with only 300MB of disk space so it is best to leave it installed in case your Gentoo environment gets screwed up.

1. Create recovery configuration profile

  1. From the Linode Manager Dashboard, click Deploy a Linux Distribution
  2. Select an Unbuntu 8.10 64-bit (or similar 64-bit OS) with a 300MB disk drive. If you want swap space, you should configure that here.
  3. Click Create Profile
  4. Change the name of the profile to “Recovery Ubuntu 64bit”

2. Create the Gentoo disk image

  1. From the Linode Manager Dashboard, click Create a new Disk Image
  2. Give your disk a label (you can change this later) and size (most likely all the remaining disk space on your Linode)
  3. Pick Unformatted / raw for the filesystem, we’ll format using ReiserFS later
  4. Click Create Disk
  5. Edit your Recovery Unbuntu 64bit profile: set /dev/xvdc to the disk image you just created.
  6. Click Save Profile

3. Boot the recovery profile

  1. From the Linode Manager Dashboard, boot your recovery profile
  2. Log in with your favorite ssh client: root@<linode vps IP> and the root password you set up in section 1
  3. Install some tools required in later steps:
    root@li # apt-get update
    root@li # apt-get install reiserfsprogs wget

4. Set up Gentoo

This section roughly follows the Gentoo Quick Install Guide.

  1. Create the ReiserFS filesystem:
    root@li # mkreiserfs /dev/xvdc
  2. Mount the filesystem:
    root@li # mkdir -p /mnt/gentoo
    root@li # mount /dev/xvdc /mnt/gentoo
    root@li # cd /mnt/gentoo
  3. Set up the stage:
    root@li # wget http://gentoo.osuosl.org/releases/amd64/2008.0/stages/stage3-amd64-2008.0.tar.bz2
    root@li # tar xjpf stage3*
    root@li # rm stage3*
  4. Install latest portage snapshot:
    root@li # cd /mnt/gentoo/usr
    root@li # wget http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2
    root@li # tar xjf portage-lat*
    root@li # rm portage-lat*
  5. Chroot into the new Gentoo environment:
    root@li # cd /
    root@li # mount -t proc proc /mnt/gentoo/proc
    root@li # mount -o bind /dev /mnt/gentoo/dev
    root@li # cp -L /etc/resolv.conf /mnt/gentoo/etc/
    root@li # chroot /mnt/gentoo /bin/bash
    li50-172 / # env-update && source /etc/profile
  6. Set your timezone:
    li50-172 / # ls /usr/share/zoneinfo
    (Using US/Central as an example)
    li50-172 / # cp /usr/share/zoneinfo/US/Central /etc/localtime
    li50-172 / # nano -w /etc/conf.d/clock
    (Change value of TIMEZONE variable, e.g. TIMEZONE=”US/Central”)
    li50-172 / # date
    Mon Feb 9 14:41:50 CST 2009
  7. Set host and domain name
    li50-172 / # cd /etc
    li50-172 etc # echo “127.0.0.1 mybox.at.myplace mybox localhost” > hosts
    li50-172 etc # sed -i -e ‘s/HOSTNAME.*/HOSTNAME=”mybox”/’ conf.d/hostname
    li50-172 etc # hostname mybox
    li50-172 etc # hostname -f
    mybox.at.myplace
  8. Configure fstab mount points
    li50-172 etc # nano -w fstab

    Edit the fstab file similar to:

    /dev/xvda     /       reiserfs     noatime,notail  0 1
    /dev/xvdb     none    swap         sw              0 0
    
  9. Edit /etc/inittab.
    To ensure the lish console works if you ever need it, edit the terminals section of /etc/inittab to look like:

    # TERMINALS
    c1:12345:respawn:/sbin/agetty 38400 hvc0 linux
    #c2:2345:respawn:/sbin/agetty 38400 tty2 linux
    #c3:2345:respawn:/sbin/agetty 38400 tty3 linux
    #c4:2345:respawn:/sbin/agetty 38400 tty4 linux
    #c5:2345:respawn:/sbin/agetty 38400 tty5 linux
    #c6:2345:respawn:/sbin/agetty 38400 tty6 linux
    
  10. Configure networking and SSH:
    li50-172 etc # rc-update add net.eth0 default
    * net.eth0 added to runlevel default
    li50-172 etc # rc-update add sshd default
    * sshd added to runlevel default
    li50-172 etc # passwd
    New UNIX password: type_the_password
    Retype new UNIX password: type_the_password_again
    passwd: password updated successfully
  11. Install system tools:
    li50-172 etc # emerge logrotate syslog-ng vixie-cron reiserfsprogs dhcpcd
    li50-172 etc # rc-update add syslog-ng default
    * syslog-ng added to runlevel default
    li50-172 etc # rc-update add vixie-cron default
    * vixie-cron added to runlevel default
  12. Prepare to reboot:
    li50-172 etc # exit
    root@li # umount /mnt/gentoo/proc /mnt/gentoo/dev/ /mnt/gentoo
    root@li # exit

5. Set up Gentoo profile

  1. From the Linode Manager, shutdown the recovery Linode.
  2. Create a new profile by clicking Create a new Configuration Profile
  3. Set the following options:
    • Label: Gentoo 2008.0 amd64
    • Kernel: a 64-bit kernel, e.g. 2.6.27.4-x86_64-linode3
    • Drive: /dev/xvda: The disk image you set up in section 2 (not the small Ubuntu recovery disk)
    • Drive: /dev/xvdb: Swap Image

6. Boot Gentoo and finish installation

  1. From the Linode Manager, click the Boot button for your new Gentoo profile
  2. Log in via ssh: root@<Linode VPS IP>
    (You may have to delete the old ssh key out of your known_hosts file on your local machine)
  3. Add a non-root user, install sudo and disable root logins via SSH:
    mybox ~ # useradd -m -G wheel username
    mybox ~ # passwd username
    New UNIX password: type_the_password
    Retype new UNIX password: type_the_password_again
    passwd: password updated successfully
    mybox ~ # nano -w /etc/ssh/sshd_config
    (Add a line: PermitRootLogin: no)
    mybox ~ # emerge sudo
    mybox ~ # visudo
    (Uncomment the line: “%wheel ALL=(ALL) ALL“, around line 24)
    mybox ~ # /etc/init.d/sshd restart
  4. Install a simple conservative firewall:
    mybox ~ # emerge iptables
    mybox ~ # iptables -A INPUT -p tcp -m tcp –dport 22 -j ACCEPT
    mybox ~ # iptables -A INPUT -p icmp -m icmp –icmp-type 8 -j ACCEPT
    mybox ~ # iptables -A INPUT -i lo -j ACCEPT
    mybox ~ # iptables -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
    mybox ~ # iptables -P FORWARD DROP
    mybox ~ # iptables -P INPUT DROP
    mybox ~ # /etc/init.d/iptables save
    mybox ~ # /etc/init.d/iptables start
    mybox ~ # rc-update add iptables default
    * iptables added to runlevel default
  5. Select a Gentoo mirror and update make.conf:
    mybox ~ # emerge mirrorselect
    mybox ~ # mirrorselect -i -o >> /etc/make.conf
    mybox ~ # mirrorselect -i -r -o >> /etc/make.conf
    mybox ~ # nano -w /etc/make.conf

    Edit the file to include the parts in bold:

    # Typical Linode has 4 processors, make use of them when compiling
    MAKEOPTS="-j5"
    
    CHOST="x86_64-pc-linux-gnu"
    CFLAGS="-march=nocona -O2 -pipe"
    CXXFLAGS="${CFLAGS}"
    

    At this point you should also run emerge -vpe world and decide what USE variables you want to include in your make.conf file.

  6. Define locales:
    mybox ~ # nano -w /etc/locale.gen
    (Uncomment the first two en_US lines)
    mybox ~ # locale-gen
  7. Update portage and installed packages:
    mybox ~ # emerge portage
    mybox ~ # emerge -vpuD –newuse world
    mybox ~ # emerge -vUD –newuse world
    (Go grab some lunch, this is going to take a while.)
    mybox ~ # emerge –oneshot libtool
    mybox ~ # emerge gentoolkit
    mybox ~ # revdep-rebuild

7. Reboot and enjoy

At this point I like to reboot the server to ensure that everything comes back up the way I expect it. This isn’t necessary however.

After reboot my server was using just under a GB of data (990264 bytes) and about 60MB of RAM. The server is now ready to install apache, mysql, etc. I’ll be looking at optimizing my memory usage in a later post.

Note: If you found this helpful and are interesting in signing up for Linode, feel free to use my referral code below. I’m only putting this out there if you’d like to use it – you can easily sign up for a Linode VPS without it!
http://www.linode.com/?r=edff465df97bb1e29468836d3700c79a2d24a17e

Gentoo , , ,

  1. March 15th, 2009 at 13:27 | #1

    Excellent tutorial.

    I just installed gentoo on linode, it was a very fast the process.
    Linode servers are really fast.

    Thanks a lot.

    If i had seen your referral code before I signed up…

    ;)

  2. March 16th, 2009 at 01:12 | #2

    you forgot to add gentoolkit

    emerge -va gentoolkit

    without it you cannot do revdep-rebuild

  3. March 16th, 2009 at 01:14 | #3

    Excellent tutorial.

    Worked very well and fast.

    thanks a lot…

    and Linode Rocks!

  4. March 16th, 2009 at 08:00 | #4

    Thanks Fred! I hadn’t called out revdep-rebuild, but I probably should have. I updated the post to do that in the last step.

  5. April 11th, 2009 at 12:28 | #5

    My only suggestion is to go for 32 bit so you processes don’t eat as much memory :)
    -=r

  6. Killer Bee
    January 3rd, 2010 at 19:12 | #6

    Thanks man! That’s wjat I need! Linode is great and has cheap vps offer but I don’t know how to install Gentoo in my system. LOL

  7. July 24th, 2010 at 13:14 | #7

    Well, this is an old entry that looks like it’s been refreshed. In either case, we (www.vr.org) / Host Virtual have offered native ipv6 for the past year+ in multiple locations, and always have the latest Gentoo image available, via both PV or Xen HVM (Fully Virtualized) images. We’ll also meet Linode pricing, so give us a second look if you’re interested.

  1. No trackbacks yet.