Installing Gentoo 2008.0 amd64 on a Linode VPS
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!
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
1. Create recovery configuration profile
- From the Linode Manager Dashboard, click Deploy a Linux Distribution
- 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.
- Click Create Profile
- Change the name of the profile to “Recovery Ubuntu 64bit”
2. Create the Gentoo disk image
- From the Linode Manager Dashboard, click Create a new Disk Image
- Give your disk a label (you can change this later) and size (most likely all the remaining disk space on your Linode)
- Pick Unformatted / raw for the filesystem, we’ll format using ReiserFS later
- Click Create Disk
- Edit your Recovery Unbuntu 64bit profile: set /dev/xvdc to the disk image you just created.
- Click Save Profile
3. Boot the recovery profile
- From the Linode Manager Dashboard, boot your recovery profile
- Log in with your favorite ssh client: root@<linode vps IP> and the root password you set up in section 1
- 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.
- Create the ReiserFS filesystem:
root@li # mkreiserfs /dev/xvdc
- Mount the filesystem:
root@li # mkdir -p /mnt/gentoo
root@li # mount /dev/xvdc /mnt/gentoo
root@li # cd /mnt/gentoo - 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* - 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* - 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 - 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 - 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 - 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
- Edit
/etc/inittab.
To ensure the lish console works if you ever need it, edit theterminalssection of/etc/inittabto 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
- 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 - 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 - 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
- From the Linode Manager, shutdown the recovery Linode.
- Create a new profile by clicking Create a new Configuration Profile
- 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
- From the Linode Manager, click the Boot button for your new Gentoo profile
- 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) - 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 - 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 - 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.confEdit 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 worldand decide what USE variables you want to include in your make.conf file. - Define locales:
mybox ~ # nano -w /etc/locale.gen
(Uncomment the first two en_US lines)
mybox ~ # locale-gen - 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
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…
you forgot to add gentoolkit
emerge -va gentoolkit
without it you cannot do revdep-rebuild
Excellent tutorial.
Worked very well and fast.
thanks a lot…
and Linode Rocks!
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.
My only suggestion is to go for 32 bit so you processes don’t eat as much memory
-=r
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
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.