Short Attention Span Theatre

Arch and ext4 on prgmr.com

Getting Arch installed on a prgmr.com VPS is not insanely complex, but I wanted to make sure my method is documented somewhere I could find it again. The goal of this is to document the steps taken, then flesh it out into a full set of scripts to install Arch on a VM. Ideally this would be relatively simple, and provide an in­stal­la­tion with two separate partitions for the file systems (/boot and /). Having /boot in a separate partition will allow me to upgrade / to btrfs when prgmr.com upgrades to grub2 in a few months.

This method is based on the old guide that details installing Arch, with some changes for my particular re­quire­ments. I needed a bit more space than specified, so I created a VM with 2.5 GiB on the hard drive. Use the Arch Linux ISO to boot in the VM from the "Boot Arch Linux (x86_64)" grub menu item (should be first).

Perform the Arch install on the VM. To create a set of scripts for the install paste the commands below into two separate scripts (they are marked 1 and 2 for easy use). Note that the provided scripts and commands are separated by commands you must execute manually, assume a connection to the Internet, require you to actually change the values assigned to some variables to make them work properly, set your timezone to PST, and may kill kittens.

In the first set of commands the hard drive is prepared with an MBR, an ext4 /boot and /, a base Arch install with wget and base-devel installed as well, and an au­to­mat­i­cal­ly generated /etc/fstab.

#!/bin/sh
# Script 1 (pre-chroot)
echo -e 'o\nn\np\n1\n2048\n+256M\nn\np\n2\n\n+512M\nt\n2\n82\nn\np\n3\n\n\nw' \
  | fdisk -u /dev/sda
mkfs.ext4 -F -L boot /dev/sda1
mkfs.ext4 -F -L root /dev/sda3
mkswap -L swap /dev/sda2
swapon /dev/sda2
mount /dev/sda3 /mnt
mkdir -p /mnt/boot
mount /dev/sda1 /mnt/boot
pacstrap /mnt base wget base-devel openssh
genfstab -p /mnt >> /mnt/etc/fstab

Next, enter the Arch chroot en­vi­ron­ment in your new system.

arch-chroot /mnt

Now, to the minimal things needed to prepare the system for actual use. Replace all the "CHANGE_THIS_????????" values below with those that apply to your VPS. Once run the commands below will

#!/bin/sh
# Script 2 (post-chroot)
export THEUSER=CHANGE_THIS_USERNAME
export THEHOST=CHANGE_THIS_HOSTNAME
export THEDOMN=CHANGE_THIS_DOMNNAME
export THEIPVF=CHANGE_THIS_IPVFADDR
export THEGATE=CHANGE_THIS_GATEIPVF
export THEPORT=CHANGE_THIS_PORTNUMB
echo $THEHOST > /etc/hostname
perl -0777 -pi \
  -e 's/me\>\n/me\>\nTHEIPVF    THEHOST.THEDOMN THEHOST\n/' \
  /etc/hosts
perl -0777 -pi -e "s/THEIPVF/$THEIPVF/" /etc/hosts
perl -0777 -pi -e "s/THEHOST/$THEHOST/g" /etc/hosts
perl -0777 -pi -e "s/THEDOMN/$THEDOMN/" /etc/hosts
-e 's/me\>\n/me\>\nTHEIPVF
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
perl -0777 -pi -e 's/\n#en_US/\nen_US/g' /etc/locale.gen
locale-gen
echo LANG=en_US.UTF-8 > /etc/locale.conf
cat > /etc/systemd/network/eth0_static.network <<EOF
[Match]
Name=eth0

[Network]
Address=$THEIPVF/24
Gateway=$THEGATE
DNS=71.19.145.215
DNS=71.19.155.120
DNS=208.67.222.222
DNS=208.67.220.220
EOF
systemctl enable systemd-networkd
systemctl enable systemd-resolved
mkdir -p /etc/systemd/system/sshd.socket.d
cat > /etc/systemd/system/sshd.socket.d/sshd_new_port.conf <<EOF
[Socket]
ListenStream=
ListenStream=0.0.0.0:$THEPORT
FreeBind=true
EOF
perl -0777 -pi -e 's/\nMODULES="/\nMODULES=" xen-netfront xen-fbfront/' \
  /etc/mkinitcpio.conf
perl -0777 -pi -e 's/\nMODULES="/\nMODULES=" xenfs xen-kbdfront/' \
  /etc/mkinitcpio.conf
perl -0777 -pi -e 's/\nMODULES="/\nMODULES="xen-blkfront/' \
  /etc/mkinitcpio.conf
mkinitcpio -p linux
perl -0777 -pi -e 's/\n#\[multilib\]\n#Inc/\n\[multilib\]\nInc/' \
  /etc/pacman.conf
pacman -Syu
passwd
useradd -m -G wheel $THEUSER
perl -0777 -pi -e 's/\n# %wheel/\n%wheel/' /etc/sudoers
passwd $THEUSER
sudo -u $THEUSER mkdir -p /home/$THEUSER/aur
cd /home/$THEUSER/aur
sudo -u $THEUSER wget https://aur.archlinux.org/packages/pa/package-query/package-query.tar.gz
sudo -u $THEUSER wget https://aur.archlinux.org/packages/ya/yaourt/yaourt.tar.gz
sudo -u $THEUSER tar xf package-query.tar.gz
sudo -u $THEUSER tar xf yaourt.tar.gz
cd package-query
sudo -u $THEUSER makepkg -s
pacman -U package-query-1.4-*
cd ../yaourt
sudo -u $THEUSER makepkg -s
pacman -U yaourt-1.5-*
sudo -u $THEUSER yaourt -Sa grub-legacy
grub-install /dev/sda
cd /boot
ln -s . boot
rm -f /var/cache/pacman/pkg/*
rm -fr /home/dave/aur
perl -0777 -pi -e 's/sda/xvda/g' /etc/fstab
perl -0777 -pi -e 's/sda/xvda/g' /boot/grub/menu.lst

After that is complete exit the chroot en­vi­ron­ment, link /etc/resolv.conf to the file managed by systemd-resolved (so name resolution will work after boot on the VPS), and unmount the file systems used during in­stal­la­tion.

exit
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
umount /mnt/boot /mnt

Now boot your VPS with the new "Debian Wheezy Live" rescue ISO (it should be the second option on the first grub boot menu). Once logged in as root (no password required), prepare the VPS hard drive with the same partitions as used in the VM.

echo -e 'o\nn\np\n1\n2048\n+256M\nn\np\n2\n\n+512M\nt\n2\n82\nn\np\n3\n\n\nw' \
  | fdisk -u /dev/xvda
mkswap -L swap /dev/xvda2

Next, create a privilege separation directory for sshd, insert a copy of your public ssh key into /root/.ssh/authorized_keys, the run sshd on a particular port (this also only allows one connection at a time).

mkdir /tmp/sshd
ln -s /tmp/sshd /var/run/sshd
/usr/sbin/sshd -d -p PORT -f /etc/ssh/sshd_config

Now, on the VM on your local machine, initiate a connection to copy the local ext3 and btrfs volumes to the VPS using the following commands.

dd if=/dev/sda1 | ssh -p 21773 root@CHANGE_THIS_IPVF "dd of=/dev/xvda1"
dd if=/dev/sda3 | ssh -p 21773 root@CHANGE_THIS_IPVF "dd of=/dev/xvda3"

Once the transfers are complete, the only tasks remaining are to verify the system boots, can connect to the network, and enable/start your sshd.socket service to accept incoming con­nec­tions. Reboot the VPS, then execute the following commands to enable and start your sshd.socket.

systemctl enable sshd.socket
systemctl start sshd.socket

Now ping something off the local network to make sure you can com­mu­ni­cate with the rest of the world, and you should be in business.

Stop gpg-agent from running on login »
sast favicon