Install Alpine on Rackspace: Difference between revisions

From Alpine Linux
(remove draft)
(polish up)
Line 6: Line 6:




== Create apk overlay suitable for hard disk based tmpfs boot ==
== Copy settings from existing server into apkovl ==


The first step is to create Alpine configuration file with basic configuration of the host. We need the new box to start networking and ssh in the beginning so we can reconnect to it after reboot.
The first step is to create Alpine configuration file with basic configuration of the host. We need the new box to start networking and ssh in the beginning so we can reconnect to it after reboot.
Line 14: Line 14:
  cd overlay
  cd overlay
  mkdir -p etc/ssh etc/network etc/runlevels/{default,boot,sysinit,shutdown} root/.ssh etc/lbu
  mkdir -p etc/ssh etc/network etc/runlevels/{default,boot,sysinit,shutdown} root/.ssh etc/lbu
You can also use default Alpine configuration files. In this case you should use ssh key to authorize yourself (as root password is empty, and ssh has empty passwords disabled).


If you want to keep the existing host identity (e.g. SSH key), you can copy them over:
If you want to keep the existing host identity (e.g. SSH key), you can copy them over:
Line 27: Line 25:




Find out which shell is used for root:
Edit etc/passwd and change bash to /bin/sh.
 
grep ^root /etc/passwd
 
If its /bin/sh, you are good.  If not, edit etc/passwd and change it to /bin/sh.
  sed -i -e '/^root:/s:/bin/bash:/bin/sh:' etc/passwd
  sed -i -e '/^root:/s:/bin/bash:/bin/sh:' etc/passwd


Line 38: Line 32:
'''Make sure there is no whitespace at end of lines''' in interfaces file. Busybox ifup is very picky.
'''Make sure there is no whitespace at end of lines''' in interfaces file. Busybox ifup is very picky.


 
Create the apk world (/etc/apk/world) with essential packages:
Make sure your etc/resolv.conf exists; if not create etc/resolv.conf with the nameserver configuration like:
  echo "alpine-base iproute2 openssh bash" > etc/apk/world
nameserver dns.ip.ad.dr
 
Create the apk world (var/lib/apk/world) with essential packages:
mkdir -p var/lib/apk
  echo "alpine-base iproute2 openssh bash" > var/lib/apk/world


(bash is technically not needed, but include it in case you forgot to edit your etc/passwd file correctly)
(bash is technically not needed, but include it in case you forgot to edit your etc/passwd file correctly)
Line 59: Line 48:
Verify the overlay with "tar tzf" to see that it contains everything in proper places, and ensure it is in the / directory
Verify the overlay with "tar tzf" to see that it contains everything in proper places, and ensure it is in the / directory


  tar tzvf host.apkovl.tar.gz
  tar ../tzvf host.apkovl.tar.gz
  cp host.apkovl.tar.gz /
  cp ../host.apkovl.tar.gz /


== Install Alpine cd-rom image on hard disk ==
== Install Alpine cd-rom image to hard disk ==


We need to copy over two sets of information: the boot kernel (kernel, initramdisk and boot configuration) and operating system boot data (overlay, apk packages and kernel modules). These can reside on same partition if they fit. However, /boot is usually small, so you might want to put the apks on separate partition. This guide assumes they are on sda1 (/boot) and sda2 (/) with both having ext3 filesystems. If you don't have ext3 on / or /boot, then you might be able to disable swap and reformat the swap partition as ext3 and use that.
We need to copy over two sets of information: the boot kernel (kernel, initramdisk and boot configuration) and operating system boot data (overlay, apk packages and kernel modules).


Download an alpine iso and mount it; for example
Download an alpine iso and mount it; for example
Line 72: Line 61:
   mount alpine*.iso /cdrom -o loop
   mount alpine*.iso /cdrom -o loop


Copy the apkovl and the contents of cd-rom image to root of current installation:
Copy the contents of cd-rom image to root of current installation, then setup grub:
cp host.apkovl.tar.gz /
<pre>
cp -a /cdrom/* /
cp -a /cdrom/* /


<pre>
mkdir -p /boot/grub
cat - >target/boot/grub/grub.conf <<EOF  
cat - >target/boot/grub/grub.conf <<EOF  
default=0
default=0
Line 88: Line 75:
initrd /boot/grsec.gz
initrd /boot/grsec.gz
EOF
EOF
ln -sf ./grub.conf target/boot/grub/menu.lst
</pre>
</pre>


:* Syslinux automatically adds BOOT_IMAGE to the kernel command line; grub does not, so make sure you specify it in the grub.conf
Reboot and check that all came back as expected.
:* You do not need any other grub files - just boot.conf
 
ln -sf ./grub.conf target/boot/grub/menu.lst
 
Reboot

Revision as of 18:44, 26 July 2013

Create a minimal rackspace server

Debian 7

512MB, 20GB


Copy settings from existing server into apkovl

The first step is to create Alpine configuration file with basic configuration of the host. We need the new box to start networking and ssh in the beginning so we can reconnect to it after reboot.

Create basic layout for the overlay:

mkdir overlay
cd overlay
mkdir -p etc/ssh etc/network etc/runlevels/{default,boot,sysinit,shutdown} root/.ssh etc/lbu

If you want to keep the existing host identity (e.g. SSH key), you can copy them over:

cp -a /etc/{passwd,group,shadow,gshadow,hostname,resolv.conf,network/interfaces,ssh} etc/
cp /etc/network/interfaces etc/network

Copy over your ssh authorized_keys and make sure its included in future:

cp -a /root/.ssh/authorized_keys root/.ssh
echo "/root/.ssh" > etc/lbu/include


Edit etc/passwd and change bash to /bin/sh.

sed -i -e '/^root:/s:/bin/bash:/bin/sh:' etc/passwd
Note: If you don't do this, nobody (even with physical access) will be able to log into the machine.

Make sure there is no whitespace at end of lines in interfaces file. Busybox ifup is very picky.

Create the apk world (/etc/apk/world) with essential packages:

echo "alpine-base iproute2 openssh bash" > etc/apk/world

(bash is technically not needed, but include it in case you forgot to edit your etc/passwd file correctly)

Double check the IP configuration and ssh keys.

Finally, make the essential services start up automatically and create the overlay file:

ln -s /etc/init.d/{hwclock,modules,sysctl,hostname,bootmisc,syslog} etc/runlevels/boot/
ln -s /etc/init.d/{devfs,dmesg,mdev,hwdrivers} etc/runlevels/sysinit/
ln -s /etc/init.d/{networking,sshd} etc/runlevels/default/
ln -s /etc/init.d/{mount-ro,killprocs,savecache} etc/runlevels/shutdown/
tar czf ../host.apkovl.tar.gz *

Verify the overlay with "tar tzf" to see that it contains everything in proper places, and ensure it is in the / directory

tar ../tzvf host.apkovl.tar.gz
cp ../host.apkovl.tar.gz /

Install Alpine cd-rom image to hard disk

We need to copy over two sets of information: the boot kernel (kernel, initramdisk and boot configuration) and operating system boot data (overlay, apk packages and kernel modules).

Download an alpine iso and mount it; for example

 wget http://dl-4.alpinelinux.org/alpine/v2.6/releases/x86_64/alpine-2.6.2-x86_64.iso
 mkdir /cdrom
 mount alpine*.iso /cdrom -o loop

Copy the contents of cd-rom image to root of current installation, then setup grub:

cp -a /cdrom/* /

cat - >target/boot/grub/grub.conf <<EOF 
default=0
timeout=3
hiddenmenu

title Alpine Linux
root (hd0)
kernel /boot/grsec alpine_dev=xvda1:ext3 modules=loop,squashfs,sd-mod,ext3 console=hvc0 pax_nouderef BOOT_IMAGE=/boot/grsec
initrd /boot/grsec.gz
EOF

ln -sf ./grub.conf target/boot/grub/menu.lst

Reboot and check that all came back as expected.