Difference between revisions of "Arch Linux"

From PrgmrWiki
(Redid the whole page following the steps I took to get it working.)
(Explain enabling ipv6)
 
(39 intermediate revisions by 13 users not shown)
Line 1: Line 1:
Reboot your VPS and select the CentOS rescue image.
+
The purpose of this document is to provide the minimum necessary information to get Arch up and reasonably secure.
  
If you don't want to set up partitions (I didn't), just go ahead and make it ext3.
+
The Arch Wiki has a page devoted to [https://wiki.archlinux.org/index.php/Install_from_existing_Linux installing Arch Linux from within an existing Linux], which effectively describes the underlying steps being performed here. The following steps apply that process to a VM on prgmr.
  
 +
== Accessing the Management Console ==
 +
 +
You need to access the Management Console for your VM. If you're not familiar with this, please see [[Management Console]]. The following instructions assume that you are NOT using the legacy console.
 +
 +
== Boot from rescue image ==
 +
 +
The install will be performed from a Rescue image. This is equivalent to booting off a Rescue CD or USB stick, except the process is fully remote. We must configure the VM to boot off the Rescue image, which we will use as a starting point for installing Arch into the VM disk. For more information, see [[accessing your guest from the rescue image]]. After install has completed, the VM will be switched back to booting directly from its main disk which contains the new Arch installation.
 +
 +
=== Shut down the machine ===
 +
 +
Check if the machine is currently running by looking at the <code>Current status</code> at the top of the Management Console's main menu. If it's currently running, it needs to be shut down. You may use option 4 in the main menu to force it to power off. It's about to be reformatted so a clean shutdown isn't really necessary.
 
<pre>
 
<pre>
# mkfs.ext3 /dev/xvda1
+
4. force power off (destroy/hard shutdown)
 
</pre>
 
</pre>
  
Mount the drive into /mnt
+
=== Switch to rescue mode ===
  
 +
Now that the machine is shut down, you should configure its bootloader to use the rescue image. For example, from the main menu the options would be something like this:
 +
<pre>
 +
6. set bootloader or rescue mode
 +
</pre>
 
<pre>
 
<pre>
# mount /dex/xvda1 /mnt
+
3. Linux-based Live Rescue
# cd /mnt
+
</pre>
 +
<pre>
 +
2. Linux Live Rescue, 64 bit
 
</pre>
 
</pre>
  
Download the install script and run it!
+
After selecting the rescue image you will be prompted about adding SSH keys. This is optional, and is only necessary if you intend to SSH into the rescue image while it's running. This is not required for setting up Arch.
  
 +
After enabling the rescue image, hit 0 a couple times until you're back at the main menu again.
 +
 +
=== Start in rescue mode ===
 +
 +
Now that you have enabled booting into the rescue image, the machine can be started again. Select option 2 from the main menu:
 
<pre>
 
<pre>
# wget http://calimeroteknik.free.fr/arch-guide/install-chroot.sh
+
2. create/start, opens OOB console (try this if the machine is not running)
# chmod +x install-chroot.sh
 
# ./install-chroot.sh
 
 
</pre>
 
</pre>
  
(The install script chroots for you, when you're finished just type exit)
+
At this point the machine will be booted into the rescue image configured above. If you are presented with a GRUB prompt, you should select the option that looks like <code>Debian GNU/Linux, kernel <version>-amd64 Live Rescue</code>. If you don't see any GRUB prompt then don't worry about it.
 +
 
 +
After a minute or two of startup output, you should be presented with a login prompt:
 +
<pre>
 +
Debian GNU/Linux 8 rescue ttyS0
 +
 
 +
rescue login:
 +
</pre>
 +
 
 +
Log in as <code>root</code> with no password.
 +
 
 +
== Install Arch ==
 +
 
 +
You are now booted into a rescue image. Your VM's hard drive is located at <code>/dev/xvda</code> while the rescue image itself is located at <code>/dev/xvdz</code>. Installation of Arch can now proceed against <code>/dev/xvda</code>.
 +
 
 +
If you wished to do so, at this point you could [https://wiki.archlinux.org/index.php/Install_from_existing_Linux install Arch by hand], but for the purposes of this guide, we will use some helper scripts which greatly simplify the initial setup. Feel free to examine and customize the scripts to meet your needs. For example, the scripts default to a single large root partition, while you may instead wish to have a customized partition table.
 +
 
 +
=== Download/run install scripts ===
  
 +
The scripts are provided in [https://github.com/prgmrcom/archinstall-scripts this repo] and can be installed as follows (or see the <code>README</code> within the repo):
  
Remove the default kernel, as we're installing the Xen one.
+
'''WARNING: This is the point of no return. The script will destroy any and all data in your VM. Did you make backups? Did you check that the backups are good?'''
  
 
<pre>
 
<pre>
# pacman -Rsdn kernel26
+
cd /tmp
 +
wget https://github.com/prgmrcom/archinstall-scripts/archive/master.zip
 +
unzip master.zip
 +
cd archinstall-scripts-master/
 +
./archinstall.sh
 
</pre>
 
</pre>
  
Wget the xen kernel binaries.
+
When the script has finished, it should display a message like the following before exiting:
  
 
<pre>
 
<pre>
# wget http://95.130.15.18/xen/kernel26-xen-2.6.32.9-1-x86_64.pkg.tar.gz
+
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
# wget http://95.130.15.18/xen/kernel26-xen-headers-2.6.32.9-1-x86_64.pkg.tar.gz
+
finished
 +
********
 +
root ~ #
 
</pre>
 
</pre>
  
Replace /etc/mkinitcpio.conf with http://pastie.org/894541
+
=== Follow install guide ===
  
Install the xen kernel and headers via pacman -U
+
The scripts should have taken care of the hardware aspects of configuring an Arch install, however you will still need to set up timezones, user accounts, passwords and so forth. For that you should follow the Arch [https://wiki.archlinux.org/index.php/Installation_guide Installation Guide], specifically starting where it has an <code>arch-chroot</code> command to switch into the Arch environment. In our case we can just perform a regular <code>chroot</code>:
  
 
<pre>
 
<pre>
# pacman -U kernel26-xen-2.6.32.9-1-x86_64.pkg.tar.gz
+
chroot /mnt
# pacman -U kernel26-xen-headers-2.6.32.9-1-x86_64.pkg.tar.gz
 
 
</pre>
 
</pre>
  
Install grub
+
Continue with the Arch installation guide from that point. Once you have finished the installation (and BEFORE restarting the system), see below for a few final steps.
 +
 
 +
If you do accidentally restart at the wrong time and find yourself with an unbootable system, you can [[#Recover from unbootable instance|regain access]] using the rescue image.
 +
 
 +
== Finalize installation ==
 +
 
 +
Once you have installed everything you need (for now), a couple additional steps are needed before you can reboot into the new image.
 +
 
 +
=== Enable serial access ===
  
<pre>
+
In order for your Arch image to be accessible via the Management Console, you must enable serial access via GRUB and the Linux console. Without these changes, it will not be accessible via the Management Console and it will appear to be unresponsive when booting up. These instructions assume that you're using GRUB2 (the default) and not GRUB Legacy.
pacman -S grub
 
</pre>
 
  
Edit boot/grub/menu.lst and fill it with the following:
+
Edit <code>/etc/default/grub</code> as follows:
 
 
 
<pre>
 
<pre>
timeout 5
+
GRUB_TERMINAL_INPUT=serial
default 0
+
GRUB_TERMINAL_OUTPUT=serial
 +
GRUB_SERIAL_COMMAND="serial --speed 115200 --unit=0 --word=8 --parity=no --stop=1"
  
# (0) Arch Linux
+
GRUB_CMDLINE_LINUX_DEFAULT="YOUR_OPTIONS_HERE console=ttyS0,115200n8"
title  Arch Linux
 
root  (hd0,0)
 
kernel /boot/vmlinuz26-xen root=/dev/xvda1 ro console=/dev/xvc0
 
initrd /boot/kernel26-xen.img
 
 
</pre>
 
</pre>
  
Edit /etc/inittab and remove/comment these
+
The above settings will do the following:
 +
* The <code>GRUB_TERMINAL_INPUT</code> and <code>GRUB_TERMINAL_OUTPUT</code> lines tell GRUB to output to the Management Console during system startup. These default to <code>console</code>.
 +
* The <code>GRUB_SERIAL_COMMAND</code> setting configures that serial output from GRUB. It shouldn't be strictly required but it silences a configuration warning about default options. This setting is not present by default.
 +
* The added <code>console=...</code> parameter to the <code>GRUB_CMDLINE_LINUX_DEFAULT</code> tells the Linux kernel to enable terminal access via the Management Console. This parameter should be included in addition to any others that you specify, for example <code>"quiet console=ttyS0,115200n8"</code>.
  
 +
The above changes will only take effect after you have regenerated your GRUB configuration as follows:
 
<pre>
 
<pre>
# -8 options fixes umlauts problem on login
+
grub-mkconfig -o /boot/grub/grub.cfg
c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux
 
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
 
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
 
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
 
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
 
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux
 
 
</pre>
 
</pre>
  
Uncomment this
+
=== Enable IPv6 ===
 +
The helper scripts do not currently enable IPv6 for you. To do this, first [[Setting_up_IPv6|fetch your IPv6 address]].
  
 +
Using the example from the linked page with user cnryhilln, we would append the following lines to <code>/etc/systemd/network/prgmrDhcp.network</code> below <code>[Network]</code>
 
<pre>
 
<pre>
# Hypervisor Virtual Console for Xen and KVM
+
Address=2605:2700:0:17::4713:9b0f/64
# h0:2345:respawn:/sbin/agetty -8 38400 hvc0 linux
+
Gateway=2605:2700:0:17::1
 
</pre>
 
</pre>
  
Edit etc/locale.gen to suit your needs, then run locale-gen
+
If you've already rebooted into Arch, then <code>systemctl restart systemd-networkd.service && ip link set dev eth0 down && ip link set dev eth0 up</code>. Otherwise, just continue to follow the instructions below.
  
This should fix everything complaining about time issues, though I have no idea if its the *best* way of doing it:
+
=== Boot from Arch ===
  
 +
Once you have finished configuring your new Arch system (including enabling serial access), you can now switch the boot process from the Rescue disk back to Arch.
 +
 +
# After you've installed and configured everything (don't forget to enable [[#configure serial access|serial access]]!), shut down the system with <code>shutdown -h now</code>. If you are in a chrooted environment then you may need to first exit that with <code>Ctrl+D</code>
 +
# Exit back to the Management Console with <code>Ctrl+]</code>
 +
# From the main menu of the Management Console, set the bootloader to boot from disk:
 
<pre>
 
<pre>
# echo xen > /sys/devices/system/clocksource/clocksource0/current_clocksource
+
6. set bootloader or rescue mode
 +
</pre>
 +
<pre>
 +
1. Boot from disk
 +
</pre>
 +
# Go back to the main menu of the Management Console by pressing 0, then start the system again. If it's currently running (did you run <code>shutdown</code>?) then you can just reboot it first.
 +
<pre>
 +
2. create/start, opens OOB console (try this if the machine is not running)
 
</pre>
 
</pre>
  
Install SSH and configure it (http://wiki.archlinux.org/index.php/SSH)
+
At this point you should boot into your new Arch system. If it fails to boot, you don't need to start over again, instead you can just switch back to the rescue image and make any needed repairs:
 +
 
 +
== Recover from unbootable instance ==
 +
 
 +
If you forgot to do something when setting up your Arch image, it's possible that it will be left in an unbootable state when you attempt to boot into it. These steps will allow you to access and repair the instance without needing to reinstall from scratch:
 +
 
 +
# Follow the [[#Switch to rescue mode|above instructions]] to switch the VM's bootloader back to the rescue image, and then log into the rescue image (again).
 +
# From the rescue image, you can mount your Arch disk as follows (assuming that your root partition is at <code>/dev/xvda1</code>):
  
 
<pre>
 
<pre>
# pacman -S openssh
+
mount /dev/xvda1 /mnt
 +
 
 +
mount --rbind /proc /mnt/proc
 +
mount --rbind /sys /mnt/sys
 +
mount --rbind /dev /mnt/dev
 +
mount --rbind /run /mnt/run
 +
 
 +
chroot /mnt
 
</pre>
 
</pre>
  
Reboot your VPS and you should be good to go!
+
From here you should be able to make any needed repairs to your Arch image.
 +
 
 +
== Bibliography ==
 +
 
 +
Some reference info that you may find useful. In general, the [https://wiki.archlinux.org Arch Wiki] is an extremely useful resource for getting your new system up and running, even if you aren't necessarily running Arch.
  
{{u}} {{distros}}
+
* [https://wiki.archlinux.org/index.php/General_recommendations#Users_and_groups Setting Up a New User] -- Definitely should do this!!
 +
* [https://wiki.archlinux.org/index.php/General_recommendations#Networking Networking]
 +
* [https://wiki.archlinux.org/index.php/General_recommendations#Console_improvements Console Improvements]
 +
* [https://wiki.archlinux.org/index.php/List_of_applications Available Applications]
 +
* [[Accessing your guest from the rescue image|Booting into the rescue image]]

Latest revision as of 08:29, 21 September 2018

The purpose of this document is to provide the minimum necessary information to get Arch up and reasonably secure.

The Arch Wiki has a page devoted to installing Arch Linux from within an existing Linux, which effectively describes the underlying steps being performed here. The following steps apply that process to a VM on prgmr.

Accessing the Management Console

You need to access the Management Console for your VM. If you're not familiar with this, please see Management Console. The following instructions assume that you are NOT using the legacy console.

Boot from rescue image

The install will be performed from a Rescue image. This is equivalent to booting off a Rescue CD or USB stick, except the process is fully remote. We must configure the VM to boot off the Rescue image, which we will use as a starting point for installing Arch into the VM disk. For more information, see accessing your guest from the rescue image. After install has completed, the VM will be switched back to booting directly from its main disk which contains the new Arch installation.

Shut down the machine

Check if the machine is currently running by looking at the Current status at the top of the Management Console's main menu. If it's currently running, it needs to be shut down. You may use option 4 in the main menu to force it to power off. It's about to be reformatted so a clean shutdown isn't really necessary.

4. force power off (destroy/hard shutdown)

Switch to rescue mode

Now that the machine is shut down, you should configure its bootloader to use the rescue image. For example, from the main menu the options would be something like this:

6. set bootloader or rescue mode
3. Linux-based Live Rescue
2. Linux Live Rescue, 64 bit

After selecting the rescue image you will be prompted about adding SSH keys. This is optional, and is only necessary if you intend to SSH into the rescue image while it's running. This is not required for setting up Arch.

After enabling the rescue image, hit 0 a couple times until you're back at the main menu again.

Start in rescue mode

Now that you have enabled booting into the rescue image, the machine can be started again. Select option 2 from the main menu:

2. create/start, opens OOB console (try this if the machine is not running)

At this point the machine will be booted into the rescue image configured above. If you are presented with a GRUB prompt, you should select the option that looks like Debian GNU/Linux, kernel <version>-amd64 Live Rescue. If you don't see any GRUB prompt then don't worry about it.

After a minute or two of startup output, you should be presented with a login prompt:

Debian GNU/Linux 8 rescue ttyS0

rescue login:

Log in as root with no password.

Install Arch

You are now booted into a rescue image. Your VM's hard drive is located at /dev/xvda while the rescue image itself is located at /dev/xvdz. Installation of Arch can now proceed against /dev/xvda.

If you wished to do so, at this point you could install Arch by hand, but for the purposes of this guide, we will use some helper scripts which greatly simplify the initial setup. Feel free to examine and customize the scripts to meet your needs. For example, the scripts default to a single large root partition, while you may instead wish to have a customized partition table.

Download/run install scripts

The scripts are provided in this repo and can be installed as follows (or see the README within the repo):

WARNING: This is the point of no return. The script will destroy any and all data in your VM. Did you make backups? Did you check that the backups are good?

cd /tmp
wget https://github.com/prgmrcom/archinstall-scripts/archive/master.zip
unzip master.zip
cd archinstall-scripts-master/
./archinstall.sh

When the script has finished, it should display a message like the following before exiting:

~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
finished
********
root ~ #

Follow install guide

The scripts should have taken care of the hardware aspects of configuring an Arch install, however you will still need to set up timezones, user accounts, passwords and so forth. For that you should follow the Arch Installation Guide, specifically starting where it has an arch-chroot command to switch into the Arch environment. In our case we can just perform a regular chroot:

chroot /mnt

Continue with the Arch installation guide from that point. Once you have finished the installation (and BEFORE restarting the system), see below for a few final steps.

If you do accidentally restart at the wrong time and find yourself with an unbootable system, you can regain access using the rescue image.

Finalize installation

Once you have installed everything you need (for now), a couple additional steps are needed before you can reboot into the new image.

Enable serial access

In order for your Arch image to be accessible via the Management Console, you must enable serial access via GRUB and the Linux console. Without these changes, it will not be accessible via the Management Console and it will appear to be unresponsive when booting up. These instructions assume that you're using GRUB2 (the default) and not GRUB Legacy.

Edit /etc/default/grub as follows:

GRUB_TERMINAL_INPUT=serial
GRUB_TERMINAL_OUTPUT=serial
GRUB_SERIAL_COMMAND="serial --speed 115200 --unit=0 --word=8 --parity=no --stop=1"

GRUB_CMDLINE_LINUX_DEFAULT="YOUR_OPTIONS_HERE console=ttyS0,115200n8"

The above settings will do the following:

  • The GRUB_TERMINAL_INPUT and GRUB_TERMINAL_OUTPUT lines tell GRUB to output to the Management Console during system startup. These default to console.
  • The GRUB_SERIAL_COMMAND setting configures that serial output from GRUB. It shouldn't be strictly required but it silences a configuration warning about default options. This setting is not present by default.
  • The added console=... parameter to the GRUB_CMDLINE_LINUX_DEFAULT tells the Linux kernel to enable terminal access via the Management Console. This parameter should be included in addition to any others that you specify, for example "quiet console=ttyS0,115200n8".

The above changes will only take effect after you have regenerated your GRUB configuration as follows:

grub-mkconfig -o /boot/grub/grub.cfg

Enable IPv6

The helper scripts do not currently enable IPv6 for you. To do this, first fetch your IPv6 address.

Using the example from the linked page with user cnryhilln, we would append the following lines to /etc/systemd/network/prgmrDhcp.network below [Network]

Address=2605:2700:0:17::4713:9b0f/64
Gateway=2605:2700:0:17::1

If you've already rebooted into Arch, then systemctl restart systemd-networkd.service && ip link set dev eth0 down && ip link set dev eth0 up. Otherwise, just continue to follow the instructions below.

Boot from Arch

Once you have finished configuring your new Arch system (including enabling serial access), you can now switch the boot process from the Rescue disk back to Arch.

  1. After you've installed and configured everything (don't forget to enable serial access!), shut down the system with shutdown -h now. If you are in a chrooted environment then you may need to first exit that with Ctrl+D
  2. Exit back to the Management Console with Ctrl+]
  3. From the main menu of the Management Console, set the bootloader to boot from disk:
6. set bootloader or rescue mode
1. Boot from disk
  1. Go back to the main menu of the Management Console by pressing 0, then start the system again. If it's currently running (did you run shutdown?) then you can just reboot it first.
2. create/start, opens OOB console (try this if the machine is not running)

At this point you should boot into your new Arch system. If it fails to boot, you don't need to start over again, instead you can just switch back to the rescue image and make any needed repairs:

Recover from unbootable instance

If you forgot to do something when setting up your Arch image, it's possible that it will be left in an unbootable state when you attempt to boot into it. These steps will allow you to access and repair the instance without needing to reinstall from scratch:

  1. Follow the above instructions to switch the VM's bootloader back to the rescue image, and then log into the rescue image (again).
  2. From the rescue image, you can mount your Arch disk as follows (assuming that your root partition is at /dev/xvda1):
mount /dev/xvda1 /mnt

mount --rbind /proc /mnt/proc
mount --rbind /sys /mnt/sys
mount --rbind /dev /mnt/dev
mount --rbind /run /mnt/run

chroot /mnt

From here you should be able to make any needed repairs to your Arch image.

Bibliography

Some reference info that you may find useful. In general, the Arch Wiki is an extremely useful resource for getting your new system up and running, even if you aren't necessarily running Arch.