Forked from arantius/create-test-container.script
Last active
December 23, 2015 05:39
-
-
Save zavorka/d82fd536820369048de9 to your computer and use it in GitHub Desktop.
How To Install Gentoo Onto Any OpenVZ VPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 \ | |
--exclude=/var/lib/nfs \ | |
/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