Fedora: Creating Arch Linux chroot with ssh server

I made a fork of a clone detection tool named CCFinderX. Two days ago I got a message from an user telling that the compilation was not working on Arch Linux. As some Kernel developers, such as Greg KH, has mentioned Arch Linux as being nice, I decided to try it.

I prefer chroots over virtual machines due higher performance, and due the fact that I do not need insulation between my chroots. As for Debian, Fedora provides all tools needed to create chroots for Arch Linux. This is "very" nice, as one can setup the Arch Linux chroot in just a few minutes.

The steps will cover installing Arch Linux tools on Fedora, creating the Arch Linux chroot, and configuring it with a new user and ssh server.

Some data:
Target directory for the chroot: /opt/arch
Package groups to be installed: base base-devel (More groups available here)
User: peter
ssh server port of the chroot: 2227

Note that the text refers to "[fedora] $" and "[arch] $", but this strings will not show up. If you want it is possible to configure bash prompt for showing different strings. Here is guide on how to do it.

Installing Fedora packages:
[fedora] $ sudo yum install arch-install-scripts gpg

Setting up Arch Linux Keys:
[fedora] $ sudo pacman-key --init
[fedora] $ sudo pacman-key --populate archlinux
Create the target directory:
[fedora] $ sudo mkdir /opt/arch

Creating the Arch Linux chroot:
[fedora] $ sudo pacstrap -d -i /opt/arch base

Prepare chroot directory (Hint: Save this to a script, or check my start/stop chroot scripts). Note that lines with -o bind mount the host directory inside the chroot. So if you delete something there, it will affect the host:
[fedora] $ sudo mount /tmp /opt/arch/tmp -o bind
[fedora] $ sudo mount /lib/modules /opt/arch/lib/modules -o bind
[fedora] $ sudo mount proc /opt/arch/proc -t proc -o nosuid,noexec,nodev
[fedora] $ sudo mount sysfs /opt/arch/sys -t sysfs -o nosuid,noexec,nodev
[fedora] $ sudo mount devtmpfs /opt/arch/dev -t devtmpfs -o mode=0755,nosuid
[fedora] $ sudo mount devpts /opt/arch/dev/pts -t devpts -o gid=5,mode=620
[fedora] $ sudo cp -a /etc/resolv.conf /opt/arch/etc/resolv.conf

Entering the chroot:
[fedora] $ sudo chroot /opt/arch su -
[arch] #

Changing root password:
[arch] # passwd

Adding a new user:
[arch] # useradd -m -g users -G wheel,storage,power -s /bin/bash peter
[arch] # passwd peter

Installing base-devel group:
[arch] # pacman -Sy base-devel

Installing openssh tools, configure server port:
[arch] # pacman -Sy openssh
[arch] # vi /etc/ssh/sshd_config
[arch] # cat /etc/ssh/sshd_config |grep 2227
Port 2227

Create ssh keys:
[arch] # /usr/bin/ssh-keygen -A

Start ssh server:
[arch] # /usr/bin/sshd -f /etc/ssh/sshd_config

Exit chroot
[arch] # exit
[fedora] $

ssh to chroot:
[fedora] $ ssh localhost -p 2227
[arch] $


Nice resources:
 - How to install Arch Linux, while keeping it simple
 - Arch Linux Website
 - My start/stop chroot scripts




Comments

Popular posts from this blog

Toshiba R830 and 16GB of RAM

Five steps to create Fedora chroot jail using yum

GitHub Social Coding