Skip to content

Instantly share code, notes, and snippets.

@unixfox
Forked from trimsj/alpine.sh
Last active November 8, 2022 23:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unixfox/1bac8706734fed769f8a2e1a3946abe6 to your computer and use it in GitHub Desktop.
Save unixfox/1bac8706734fed769f8a2e1a3946abe6 to your computer and use it in GitHub Desktop.
Converts LXC VPS to Alpine Linux (Only works with Debian)
#!/bin/sh -e
# Converts LXC VPS to Alpine Linux
# WARNING: This script will wipe any data in your VPS!
# GPLv2; Partly based on https://gitlab.com/drizzt/vps2arch
# Original work by trimsj
server=http://images.linuxcontainers.org
path=$(wget -O- ${server}/meta/1.0/index-system | \
grep -v edge | awk '-F;' '($1=="alpine" && $3=="amd64") {print $NF}' | tail -1)
cd /
mkdir /x
wget ${server}/${path}/rootfs.tar.xz
tar -C /x -xf rootfs.tar.xz
sed -i '/getty/d' /x/etc/inittab
sed -i 's/rc_sys="lxc"/rc_sys="openvz"/' /x/etc/rc.conf
# save root password and ssh directory
sed -i '/^root:/d' /x/etc/shadow
grep '^root:' /etc/shadow >> /x/etc/shadow
[ -d /root/.ssh ] && cp -a /root/.ssh /x/root/
cp /etc/network/interfaces /x/etc/network/interfaces
cp /etc/resolv.conf /x/etc/resolv.conf
# remove all old files and replace with alpine rootfs
find / \( ! -path '/dev/*' -and ! -path '/proc/*' -and ! -path '/sys/*' -and ! -path '/x/*' \) -delete || true
/x/lib/ld-musl-x86_64.so.1 /x/bin/busybox cp -a /x/* /
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
rm -rf /x
apk update
apk add openssh bash
echo PermitRootLogin yes >> /etc/ssh/sshd_config
rc-update add sshd default
rc-update add mdev sysinit
rc-update add devfs sysinit
#sh # (for example, run `passwd`)
sync
reboot -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment