# Remote Arch Linux Install

This is a guide to replace a running Linux system on a remote server. While Arch makes a good server system, it is not usually the pre-installed distribution of choice.

Warning: Please make sure you understand each step before proceeding. It is easy to destroy your system or to lose critical data, and your service provider will likely charge a lot to help you recover.

## Introduction

Many providers offer systems called rescue systems or remote consoles, which is often just a bootdisc stored on a network card. This boots into a rudimentary system which just exists in your RAM. Thus you will have the ability to partition your harddrive as you like.

This document outlines the solution for servers without a rescue systems but have a swap partition. You can disable the swap partition and set up your intermediate system there. When you finish this tutorial you will have a base Arch Linux, which can be accessed via SSH.

## Backup and Preparation

During the procedure you WILL ERASE ALL DATA on your former server. Backup all your data including mails, webservers, etc. Have all information at your fingertips. Preserve all your server configurations, hostnames, etc.

Here is a list of data you will likely need:

- IP address
- hostname(s), (note: rootserver are mostly also part of the providers domain, check or save your `/etc/hosts` before you delete)
- DNS server (check `/etc/resolv.conf`)
- SSH keys (if other people work on your server, they will have to accept new keys otherwise. This includes keys from your Apache, your mail servers, your SSH server and others.)
- Hardware info (network card, etc. Refer to your pre-installed `/etc/modules.conf` )
- Grub configuration files.

In general, it is a good idea to have a local copy of your original `/etc` directory on your local hard drive.

## Prepare the intermediate system

The intermediate system is the system which is used as a place where you setup your new disc layout and install the final system. There is no need to install more then the absolutely necessary packages in it. In addition to the base system you will need wget to fetch some software and an ssl server.

### Create a new swap file

If you're paranoid or have very little RAM available you might want to add a swap file as swapspace before you disable the swap partition. Note that you do not need running daemons such as mailserver, http-server etc. When you stop them you can free memory at the remote machine.

The following commands create a file filed with zeros, formats it as swap space, activates the swap file, forces writing of the buffer cache to the disk, and then checks for active swap files.

    # dd if=/dev/zero of=/swapfile bs=1024 count=512288
    # mkswap /swapfile
    # swapon /swapfile
    # sync
    # cat /proc/swaps

### Set old swap partition as new root partition

Check `cfdisk`, `/proc/swaps` or `/etc/fstab` to find your swap partition. Assuming your hard drive is located on sdaX (X will be a number).

Do the following:

Disable the swap space:

    # swapoff /dev/sdaX

Create a filesystem on it

    # fdisk /dev/sda
    (set /dev/sdaX ID field to "Linux" - Hex 83)
    # mke2fs -j /dev/sdaX

Create a directory to mount it in

    # mkdir /mnt/newsys

Finally, mount the new directory for installing the intermediate system.

    # mount -t ext4 /dev/sdaX /mnt/newsys

### Install the intermediate system

Setup the intermedia system environment for pacman following a method in Install from existing Linux.

### Things to check before you reboot

Before rebooting, chroot into the newly-installed system.

Set a root password so that you can log in with ssh later:

    # passwd

Install ssh and enable it to start automatically at boot.

Configure the network connection to start automatically at boot.

Set up a boot loader and configure it to use the swap partition you appropriated earlier as the root partition. You might want to configure your bootloader to be able to boot into your old system; it is helpful to re-use the server's existing /boot partition in the new system for this purpose.

It is now safe to reboot.

### Prepare a home for your new production server

Give the server time to reboot and then ping it to ensure you can access it.

SSH into your new Arch system. Make sure you understand where you are - at your former swap partition.

Now that you have a working intermediate Arch install, you repartition and/or format your server's original root partition as desired. Presuming that the server's original root partition is sdaY (where Y is the partition number)...

    # mkfs.ext4 /dev/sdaY
    (Answer yes when prompted to overwrite existing partition)
    # mkdir /mnt/newsys
    # mount -t ext4 /dev/sdaY /mnt/newsys

## Set up your new system

Copy your intermediate Arch install into the production root directory.

    # cp -a /etc /home /opt /root /srv /usr /var /mnt/newsys
    # cd /mnt/newsys
    # ln -s usr/bin bin
    # ln -s usr/bin sbin
    # ln -s usr/lib lib
    # ln -s usr/lib lib64

Edit your bootloader configuration to use the newly-reformated partition as the root partition.

### Final Remarks

Now you have Arch Linux running at your server. More things need to be done to turn it into something useful.

Category:

- Getting and installing Arch