Difference between revisions of "Remote installation"

From ArchWiki
Jump to: navigation, search
(Prepare a home for your new production server)
(update link(s) avoid redirect)
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[Category:Getting and installing Arch]]
 
[[Category:Getting and installing Arch]]
 
[[zh-CN:Remote Arch Linux Install]]
 
[[zh-CN:Remote Arch Linux Install]]
{{out of date}}
 
{{merge|Install from SSH|3=Talk:Remote Arch Linux Install#Merging}}
 
 
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.  
 
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. }}
 
{{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. }}
Line 28: Line 26:
 
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.
 
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==
+
===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.
 
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.
  
Line 57: Line 55:
 
  # mkdir /mnt/newsys
 
  # mkdir /mnt/newsys
  
Finally mounts the new directory for installing the intermediate system.
+
Finally, mount the new directory for installing the intermediate system.
 
  # mount -t ext4 /dev/sdaX /mnt/newsys
 
  # mount -t ext4 /dev/sdaX /mnt/newsys
  
Line 73: Line 71:
 
  # chroot /mnt/newsys /bin/bash
 
  # chroot /mnt/newsys /bin/bash
  
Make sure you have a network and check by [[Network Configuration#Check the connection|this]] method.
+
Make sure you have a network and check by [[Network configuration#Check the connection|this]] method.
  
 
Now you should have pacman available to manage your system. You will need a kernel and an ssh server to reboot into your rescue system. Once you are installing stuff also consider the editor of your choice (nano, joe) if you dislike vi.
 
Now you should have pacman available to manage your system. You will need a kernel and an ssh server to reboot into your rescue system. Once you are installing stuff also consider the editor of your choice (nano, joe) if you dislike vi.
 
  # pacman -S linux openssh
 
  # pacman -S linux openssh
  
Set up a bootloader following guide in [[Installation Guide]]. Set up your bootmanager to the new system
+
Set up a bootloader following guide in [[Installation guide]]. Set up your bootmanager to the new system
  
 
Before proceeding double check that you:
 
Before proceeding double check that you:
Line 95: Line 93:
 
   # mount -t ext4 /dev/discs/disc0/part3 /mnt/newsys
 
   # mount -t ext4 /dev/discs/disc0/part3 /mnt/newsys
  
===Set up your new system===
+
==Set up your new system==
 
+
At this point, follow the normal steps of [[Installation guide]]. Probably the {{ic|genfstab}} script won't work. In that case, you'll need to edit the {{ic|/mnt/etc/fstab}} file by hand. You can use the content of {{ic|/etc/mtab}} as reference.
We need archbootstrap again and this uses {{pkg|wget}}, so make sure you install it.
+
 
+
Copy archbootstrap from your old home, which you will have to mount, or copy it again via scp. Alternatively you can extract the original Arch setup script from the cd or from the floppy images. I assume you used archbootstrap again and have the base installed to {{ic|/mnt/newsys}}. You can edit your {{ic|/etc}} stuff manually again, or you can copy:
+
 
+
  # cat /etc/fstab > /mnt/newsys/etc/fstab
+
  # cat /etc/pacman.conf > /mnt/etc/pacman.conf
+
  # cat /etc/hosts > /mnt/etc/hosts
+
  # cat /etc/hosts.allow > /mnt/etc/hosts.allow
+
  # cat /etc/rc.conf > /mnt/etc/rc.conf
+
  # cat /etc/modprobe.d/modprobe.conf > /mnt/etc/modprobe.d/modprobe.conf
+
  # cat /etc/resolv.conf > /mnt/etc/resolv.conf
+
 
+
When you're done set up your final {{ic|/mnt/newsys/etc/fstab}} (Edit to suit your system):
+
 
+
{{bc|
+
#
+
# /etc/fstab: static file system information
+
#
+
# <file system>        <dir>        <type>    <options>        <dump> <pass>
+
none                  /proc        proc      defaults            0      0
+
none                  /dev/pts      devpts    defaults            0      0
+
none                  /dev/shm      tmpfs    defaults            0      0
+
tmpfs                  /tmp          tmpfs    defaults            0      0
+
#sysfs                  /sys          sysfs    defaults            0      0
+
usbdevfs              /proc/bus/usb usbdevfs  defaults            0      0
+
 
+
/dev/cdroms/cdrom0    /mnt/cd      iso9660  ro,user,noauto,unhide  0      0
+
/dev/cdroms/cdrom0    /mnt/dvd    udf      ro,user,noauto,unhide  0      0
+
/dev/floppy/0          /mnt/fl      vfat      user,noauto,unhide      0      0
+
 
+
# the production system
+
/dev/discs/disc0/part1 swap        swap      defaults                0      0
+
/dev/discs/disc0/part2 /            ext3      defaults                0      1
+
/dev/discs/disc0/part3 /home        ext3      defaults                0      1
+
 
+
# the backup system
+
/dev/discs/disc0/part5 /mnt/backup  ext3      defaults,noauto        0      1
+
 
+
# the rescue system if necessary
+
/dev/discs/disc0/part6 /mnt/rescue  ext3      defaults,noauto        0      1
+
}}
+
 
+
Don't forget to make a directory for the backup
+
  # mkdir /mnt/backup
+
 
+
Again, do not forget to copy your ssl keys. Mount devfs and proc:
+
  # mount -t devfs none /mnt/newsys/dev
+
  # mount -t proc none /mnt/newsys/proc
+
 
+
Chroot into your soon to be production system, set a root password, and install essential software
+
  # chroot /mnt/newsys /bin/bash
+
  # passwd
+
  # pacman -S linux openssh mc wget nano
+
 
+
Tweak your {{ic|/mnt/newsys/boot/grub/menu.lst}} to default it to your new production system.
+
  # install-grub /dev/discs/disc0/disc  dev/discs/disc0/part2
+
  
 
Double check that you have performed all necessary steps (as for setting up the rescue system), exit chroot, and reboot.
 
Double check that you have performed all necessary steps (as for setting up the rescue system), exit chroot, and reboot.

Revision as of 07:35, 16 February 2014

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 boot

You will have to chroot into your new system to bring up a kernel. When you're in it you will have to setup a root password, otherwise SSH will not let you into your system. Also your bootloader must be directed to your new system. You might want to configure your bootloader to be able to boot into your old system. This makes it easier to use the recovery console in case you have one.

mount essential systems

# mount -o bind /dev /mnt/newsys/dev
# mount -t proc none /mnt/newsys/proc

Chroot into your new system:

# chroot /mnt/newsys /bin/bash

Make sure you have a network and check by this method.

Now you should have pacman available to manage your system. You will need a kernel and an ssh server to reboot into your rescue system. Once you are installing stuff also consider the editor of your choice (nano, joe) if you dislike vi.

# pacman -S linux openssh

Set up a bootloader following guide in Installation guide. Set up your bootmanager to the new system

Before proceeding double check that you:

# start sshd  
# set a root password

All this is necessary to get a working system. Enter 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.

Create filesystems as desired and mount your new root partition to /mnt/newsys.

 # mkdir /mnt/newsys
 # mount -t ext4 /dev/discs/disc0/part3 /mnt/newsys

Set up your new system

At this point, follow the normal steps of Installation guide. Probably the genfstab script won't work. In that case, you'll need to edit the /mnt/etc/fstab file by hand. You can use the content of /etc/mtab as reference.

Double check that you have performed all necessary steps (as for setting up the rescue system), exit chroot, and reboot.

Final Remarks

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