Difference between revisions of "Arch Linux"

From PrgmrWiki
(Clean up link formatting -- no changes to actual content (yet))
(Explain enabling ipv6)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
The purpose of this document is to provide the minimum necessary information to get Arch up and reasonably secure.
 
The purpose of this document is to provide the minimum necessary information to get Arch up and reasonably secure.
  
It should be noted 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]. If you are interested in a more thorough approach, the scripts and the link below will allow you a more sophisticated understanding of what you are doing. It may be noted that this document does not reference this particular wiki page.
+
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 ===
+
== Accessing the Management Console ==
If you're not familiar with accessing the management console, please see [[Management Console]]
 
  
=== Boot a Rescue Image ===
+
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.
Shut down your machine if it is running. Then in the management console select
+
 
 +
== 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>
 +
4. force power off (destroy/hard shutdown)
 +
</pre>
 +
 
 +
=== 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>
 
<pre>
    2. create/start, opens OOB console (try this if the machine is not running)
+
6. set bootloader or rescue mode
 
</pre>
 
</pre>
This will bring up a menu resembling:
 
 
<pre>
 
<pre>
    GNU GRUB  version 0.97  (131072K lower / 0K upper memory)
+
3. Linux-based Live Rescue
 +
</pre>
 +
<pre>
 +
2. Linux Live Rescue, 64 bit
 +
</pre>
  
+-------------------------------------------------------------------------+
+
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.
| user bootloader configuration                                          | 
+
 
| Debian GNU/Linux, kernel 3.2.0-4-amd64 Live Rescue                      |
+
After enabling the rescue image, hit 0 a couple times until you're back at the main menu again.
| Debian GNU/Linux, kernel 3.2.0-4-amd64 (single-user mode) Live Rescue  |
+
 
| ubuntu-trusty-14.04-64 rescue                                          |
+
=== Start in rescue mode ===
| ubuntu-trusty-14.04-64 install                                          |
+
 
| centos5-64 rescue                                                       |
+
Now that you have enabled booting into the rescue image, the machine can be started again. Select option 2 from the main menu:
| centos5-64 install                                                      |
+
<pre>
| debian-wheezy-7.0-64 rescue                                             |
+
2. create/start, opens OOB console (try this if the machine is not running)
| debian-wheezy-7.0-64 install                                            |
 
| fedora20-64 rescue                                                      |
 
| fedora20-64 install                                                    |
 
| centos6-64 rescue                                                      | v
 
+-------------------------------------------------------------------------+
 
    Use the ^ and v keys to select which entry is highlighted.
 
    Press enter to boot the selected OS, 'e' to edit the
 
    commands before booting, or 'c' for a command-line.
 
 
</pre>
 
</pre>
  
Boot <code>Debian GNU/Linux Live Rescue</code> from GRUB.
+
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.
  
=== Installing Base Arch ===
+
After a minute or two of startup output, you should be presented with a login prompt:
==== Clone the Repository ====
+
<pre>
Clone [https://github.com/prgmrcom/archinstall-scripts this repo] in the rescue image instance:
+
Debian GNU/Linux 8 rescue ttyS0
 +
 
 +
rescue login:
 +
</pre>
  
For example:
+
Log in as <code>root</code> with no password.
<pre>
+
 
root ~ # git clone https://github.com/prgmrcom/archinstall-scripts
+
== Install Arch ==
Cloning into 'archinstall-scripts'...
+
 
remote: Counting objects: 20, done.
+
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>.
remote: Total 20 (delta 0), reused 0 (delta 0), pack-reused 20
+
 
Unpacking objects: 100% (20/20), done.
+
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.
Checking connectivity... done.
+
 
root ~ # </pre>
+
=== 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):
 +
 
 +
'''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?'''
  
==== Run the Install Script ====
 
Run the `archinstall.sh` script.
 
 
<pre>
 
<pre>
root ~ # cd archinstall-scripts
+
cd /tmp
root ~ # sudo ./archinstall.sh
+
wget https://github.com/prgmrcom/archinstall-scripts/archive/master.zip
 +
unzip master.zip
 +
cd archinstall-scripts-master/
 +
./archinstall.sh
 
</pre>
 
</pre>
  
When the script ends, there will be the word "finished" on a new line which will look like this:
+
When the script has finished, it should display a message like the following before exiting:
 +
 
 
<pre>
 
<pre>
[tons of script output]
 
 
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
finished
 
finished
 
********
 
********
root ~ # </pre>
+
root ~ #
 +
</pre>
 +
 
 +
=== Follow install guide ===
  
=== Post Configuration ===
+
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>:
This script should take 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. See the Arch [https://wiki.archlinux.org/index.php/Installation_guide Installation Guide] and [https://wiki.archlinux.org/index.php/General_recommendations General Recommendations] for details.
 
  
The Installation Guide is really quite thorough, and should be glanced through if not read in its entirety. Some things you might find important:
+
<pre>
 +
chroot /mnt
 +
</pre>
  
* [https://wiki.archlinux.org/index.php/General_recommendations#Users_and_groups Setting Up a New User]: super important
+
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.
* [https://wiki.archlinux.org/index.php/General_recommendations#Networking Networking]: it's all reasonably useful
+
 
 +
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 ===
 +
 
 +
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 <code>/etc/default/grub</code> as follows:
 +
<pre>
 +
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"
 +
</pre>
 +
 
 +
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>
 +
grub-mkconfig -o /boot/grub/grub.cfg
 +
</pre>
 +
 
 +
=== 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>
 +
Address=2605:2700:0:17::4713:9b0f/64
 +
Gateway=2605:2700:0:17::1
 +
</pre>
 +
 
 +
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.
 +
 
 +
=== 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>
 +
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>
 +
 
 +
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>
 +
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>
 +
 
 +
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.
 +
 
 +
* [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/General_recommendations#Console_improvements Console Improvements]
* [https://wiki.archlinux.org/index.php/Installation_guide#Locale Changing Your Locale]
 
* [https://wiki.archlinux.org/index.php/Installation_guide#Time_zone Changing Your Time Zone]
 
 
* [https://wiki.archlinux.org/index.php/List_of_applications Available Applications]
 
* [https://wiki.archlinux.org/index.php/List_of_applications Available Applications]
 
+
* [[Accessing your guest from the rescue image|Booting into the rescue image]]
== Bibliography ==
 
* [[Accessing your guest from the rescue image|Booting into 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.