Skip to content

Instantly share code, notes, and snippets.

@arantius
Last active April 6, 2019 12:38
Show Gist options
  • Save arantius/4093406 to your computer and use it in GitHub Desktop.
Save arantius/4093406 to your computer and use it in GitHub Desktop.
How To Install Gentoo Onto Any OpenVZ VPS
# vzctl create 200 --config unlimited --ostemplate \
> debian-6.0-x86 --ipadd 192.168.202.200 --hostname guest
Creating container private area (debian-6.0-x86)
Performing postcreate actions
CT configuration saved to /etc/vz/conf/200.conf
Container private area was created
# vzctl start 200
Starting container...
Container is mounted
Adding IP address(es): 192.168.202.200
Setting CPU units: 1000
Container start in progress...
# vzctl set 200 --userpasswd root:root
# vzctl set 200 --nameserver 8.8.8.8
#!/bin/sh
set -e
if [ `whoami` != "root" ]; then
echo "This script must run as root!"
exit 1
fi
if [ ! -f /root/stage3-*.tar.bz2 ]; then
echo "Could not find stage3 tarball!"
exit 1
fi
echo "Extracting stage3 tarball ..."
rm -fr /root/gentoo
mkdir /root/gentoo
tar xjpf /root/stage3-*.tar.bz2 -C /root/gentoo
echo "Patching Gentoo installation ..."
# Fix mtab.
rm -f /root/gentoo/etc/mtab
ln -s /proc/mounts /root/gentoo/etc/mtab
# The host, not the container, mounts file systems.
echo "proc /proc proc defaults 0 0" > /root/gentoo/etc/fstab
echo "none /dev/pts devpts rw 0 0" >> /root/gentoo/etc/fstab
# The container has no terminals, don't run agetty.
sed -i -e '/agetty/d' /root/gentoo/etc/inittab
# Force a password to be set.
sed -i -e '/^root/s/\*/!/' /root/gentoo/etc/shadow
# Tell RC that we're running inside OpenVZ.
sed -i -e 's/#?rc_sys=.*/rc_sys="openvz"/' /root/gentoo/etc/rc.conf
# Update PAM so that the host can set passwords.
sed -i -e \
'/^password/s/include.*/required pam_unix.so md5 shadow/' \
/root/gentoo/etc/pam.d/chpasswd
# Add the network to the default run level.
ln -s net.lo /root/gentoo/etc/init.d/net.venet0
ln -s /etc/init.d/net.venet0 /root/gentoo/etc/runlevels/default/net.venet0
# Start SSH at boot.
ln -s /etc/init.d/sshd /root/gentoo/etc/runlevels/default/sshd
echo "Activating Gentoo ..."
mount | grep -q /root/new && umount /root/new
rm -fr /root/new
mkdir /root/new
mount --bind / /root/new
rsync -aH --delete-after \
--exclude=/dev \
--exclude=/lib/init \
--exclude=/root \
/root/gentoo/ /root/new/
echo "Setting root password ..."
passwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment