How can I Install Alpine Linux on my OpenVZ NAT Server

This knowledge base article explains how to convert your existing OpenVZ VPS to a minimal Alpine Linux installation using a community script.

Alpine Linux Conversion for OpenVZ NAT Servers

This method utilizes a script originally shared on Low End Talk to install a recent version of Alpine Linux on a running OpenVZ container. Alpine Linux is an extremely lightweight and security-focused distribution, making it ideal for low-resource VPS environments.


Important Prerequisites and Warnings

READ THESE CAREFULLY BEFORE PROCEEDING.

  1. Data Loss: The script will wipe all existing data on your VPS. Ensure you have backed up any necessary files before running the command.

  2. Container Type: This script is designed specifically for OpenVZ containers (often referred to as VPS or Container, not KVM/full virtualization). It may not work on all OpenVZ kernels/setups.

  3. OS Requirements: The original script was tested on base installations of CentOS 7, Debian 8, and Ubuntu 16.04. It is also known to work on Debian 12

  4. IPv6: IPv6 is not supported by this script and must be configured manually after installation.

Installation Steps (One-Click Conversion)

You must run this command as the root user on your OpenVZ VPS.

Step 1: Execute the Conversion Script

Log in to your OpenVZ VPS via SSH as root and run the following command. This command fetches the script and pipes it directly to the shell for execution.

wget -O - https://gist.githubusercontent.com/trimsj/c1fefd650b5f49ceb8f3efc1b6a1404d/raw/alpine.sh | sh

Step 2: Await Reboot

The script will automatically download the Alpine Linux root filesystem, configure basic network settings (using your existing IPv4 address), install OpenSSH and Bash, and then forcibly reboot the container (reboot -f).

Note: The script attempts to preserve your current root password and SSH keys/configuration by copying /etc/shadow and /root/.ssh/ into the new system.

Step 3: Log In to Alpine Linux

Your VPS should reboot into Alpine Linux. Wait a few minutes, then try to SSH back in using your existing IP address and root password.

If the script was successful, your system is now running a minimal, systemd-free Alpine installation, typically using around 8MB of RAM and 36MB of disk space.


Post-Installation Notes

Package Management

Alpine Linux uses apk for package management.

  • Update repositories: apk update

  • Install a package: apk add <package_name>

  • Upgrade packages: apk upgrade

Service Management

Alpine Linux uses OpenRC for service initialization. The script automatically adds sshd, mdev, and devfs to the startup runlevels.

  • Start a service: rc-service <service_name> start

  • Enable a service on boot: rc-update add <service_name> default
Please rate this article to help us improve our Knowledge Base.

0 0