Compare commits

..

No commits in common. "master" and "without-docker" have entirely different histories.

20 changed files with 219 additions and 508 deletions

4
.gitignore vendored
View File

@ -7,6 +7,4 @@ source.tar.xz
sd*.raw*
rootfs*
*/*.tar
*/*.built
.docker-container.built
docker-rules.mk
*/*.built

View File

@ -1,4 +0,0 @@
language: bash
script:
- make travis

View File

@ -1,79 +0,0 @@
FROM derjudge/archlinux
MAINTAINER lesderid <les@lesderid.net>
# Environment
ENV SCW_BASE_IMAGE armbuild/scw-archlinux:2014-12-02
# Update the keyring
RUN pacman -Sy --noconfirm archlinux-keyring
# Force openssl upgrade first (bad symbol issue)
RUN pacman -Sy --noconfirm --force openssl
# Install packages
RUN pacman -Sy --noconfirm \
bash-completion \
bc \
binutils \
cronie \
curl \
dnsutils \
fakeroot \
htop \
iptables \
lsb-release \
mg \
nbd \
ntp \
openbsd-netcat \
openssh \
rsync \
rsyslog \
screen \
socat \
sudo \
tmux \
vim \
wget
# Locales
RUN sed 's/^\([^#]\)/#\1/' -i /etc/locale.gen \
&& sed 's/^#en_US.UTF-8/en_US.UTF-8/;s/^#en_GB.UTF-8/en_GB.UTF-8/' -i /etc/locale.gen \
&& echo LANG=en_GB.UTF-8 > /etc/locale.conf \
&& locale-gen
# Patch rootfs
RUN curl -Lkq http://j.mp/scw-skeleton | FLAVORS=common,docker-based,systemd bash -e
ADD ./patches/etc/ /etc/
ADD ./patches/usr/ /usr/
# Systemd
RUN systemctl enable \
scw-fetch-ssh-keys \
scw-sync-kernel-modules \
scw-generate-ssh-keys \
scw-gen-machine-id.service \
ntpdate.service \
sshd.service \
serial-getty@ttyS0.service \
&& systemctl mask \
getty@tty1.service
# packages upgrade
RUN pacman --noconfirm -Suy
# Remove root password
RUN passwd -d root
# Cleanup
RUN pacman-db-upgrade \
&& pacman -Sc --noconfirm \
&& rm -rf /var/cache/pacman/pkg \
&& pacman-db-upgrade

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2014-2015 Scaleway
Copyright (c) 2014 Online Labs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,18 +0,0 @@
NAME = archlinux
VERSION = latest
VERSION_ALIASES = 2014-12-02
TITLE = Arch Linux
DESCRIPTION = A simple, lightweight distribution
SOURCE_URL = https://github.com/lesderid/image-archlinux
VENDOR_URL = https://www.archlinux.org/
IMAGE_VOLUME_SIZE = 50G
IMAGE_BOOTSCRIPT = latest
IMAGE_NAME = ArchLinux
## Image tools (https://github.com/scaleway/image-tools)
all: docker-rules.mk
docker-rules.mk:
wget -qO - https://j.mp/scw-builder | bash
-include docker-rules.mk

View File

@ -1,44 +1,21 @@
# Arch Linux image on Scaleway
Official Archlinux image on Online Labs
=======================================
[![Build Status](https://travis-ci.org/lesderid/image-archlinux.svg?branch=master)](https://travis-ci.org/lesderid/image-archlinux)
**Warning: this is image is not yet working**
Scripts to build an Arch Linux (x86_64) image on Scaleway
This image is built using [Image Tools](https://github.com/scaleway/image-tools) and is based on the official [Ubuntu](https://github.com/scaleway/image-ubuntu) image.
![](https://d11xdyzr0div58.cloudfront.net/static/logos/archlinux-logo-dark-scalable.518881f04ca9.svg)
Scripts to build the official Archlinux image on Online Labs
---
**This image is meant to be used on a VC1 server.**
Related projects
----------------
We use the Docker's building system and convert it at the end to a disk image that will boot on real servers without Docker. Note that the image is still runnable as a Docker container for debug or for inheritance.
- https://github.com/online-labs/image-tools (Main project for building images on Online Labs)
- https://github.com/online-labs/image-builder (Old repository with full history)
- https://github.com/online-labs/ocs-scripts (Common scripts for distributions)
[More info](https://github.com/scaleway/image-tools#docker-based-builder)
---
## Building
Build and add the image to [your account](https://cloud.scaleway.com/#/images):
$ make image_on_local
Full list of commands available at: [scaleway/image-tools](https://github.com/scaleway/image-tools/#commands)
## Testing
To test your image, run:
$ scw run --tmp-ssh-key --name="archlinux" <IMAGE_ID>
---
## Links
links
-----
- [Community: Add Archlinux ARM image](https://community.cloud.online.net/t/need-feedback-add-arch-linux-arm-image/243?u=manfred)
- [Community: New linux distributions (Debian, CoreOS, CentOS, Fedora, Arch Linux, ...)](https://community.cloud.online.net/t/official-new-linux-distributions-debian-coreos-centos-fedora-arch-linux/229?u=manfred)
---
A project by [![Scaleway](https://avatars1.githubusercontent.com/u/5185491?v=3&s=42)](https://www.scaleway.com/) and lesderid

85
build Executable file
View File

@ -0,0 +1,85 @@
#!/bin/bash
. ./lib.sh # Include library
# Image
DISTRIB="archlinux"
ARCH=${ARCH:-"armhf"}
TARGET=${TARGET:-"rootfs-target"}
CLEAN_PATHS="/root/.bash_history /root/.history /etc/resolv.conf /etc/ssh/*_key*"
PKGS_INCLUDE=${PKGS_INCLUDE:-"cronie,curl,iptables,dhcpcd,less,man,nano,nbd,ntp,openssh,wget,vim"}
# MIRROR=${MIRROR:-"http://mirror.cloud.online.net/ubuntu-ports/"}
VERSION=${VERSION:-"latest"}
LOCALES="en_US.UTF-8,fr_FR.UTF-8"
S3_URL=s3://test-images/archlinux/
# Required
NAME=${NAME:-"rootfs-$ARCH-$DISTRIB"}
build_image() {
# TODO Mirror
sudo wget -O source.tar.gz \
http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-$VERSION.tar.gz
sudo mkdir -p "$TARGET"
sudo tar -C "$TARGET" -xzf source.tar.gz
}
patch_image() {
# prepare chroot
sudo umount $TARGET/{sys,dev,proc} || true
sudo mount -t proc proc $TARGET/proc
sudo mount -t sysfs sys $TARGET/sys
sudo mount -o bind /dev $TARGET/dev
do_in_target 'sed s/root:[^:]\+:/root:x:/ -i /etc/shadow'
sudo mkdir -p $TARGET/run/systemd/resolve
sudo cp /etc/resolv.conf $TARGET/run/systemd/resolve/resolv.conf
do_in_target 'curl https://raw.githubusercontent.com/online-labs/ocs-scripts/master/upgrade_root.bash | bash'
patch_target archlinux/patches
# TODO Get ssh keys from config
sudo mkdir -p $TARGET/root/.ssh
sudo cp -va /root/.ssh/authorized_keys $TARGET/root/.ssh
echo $LOCALES | sed 's/,/\n/' | while read loc; do
do_in_target "sed -e s/^\#${loc}/${loc}/ -i /etc/locale.gen"
done
do_in_target locale-gen
pkgs_pacman=`echo $PKGS_INCLUDE | tr ',' ' '`
do_in_target "pacman -Sy --noconfirm $pkgs_pacman"
do_in_target "systemctl enable sshd.service"
# tty settings
do_in_target "systemctl disable getty@tty1.service"
do_in_target "systemctl enable serial-getty@ttyS0.service"
# clean chroot
sudo rm -f $TARGET/run/systemd/resolve/resolv.conf
sudo umount $TARGET/{sys,dev,proc} || true
}
upgrade_image() {
sudo umount $TARGET/{sys,dev,proc} || true
sudo mount -t proc proc $TARGET/proc
sudo mount -t sysfs sys $TARGET/sys
sudo mount -o bind /dev $TARGET/dev
sudo cp /etc/resolv.conf $TARGET/run/systemd/resolve/resolv.conf
do_in_target "pacman --noconfirm -Suy"
sudo rm -f $TARGET/run/systemd/resolve/resolv.conf
sudo umount $TARGET/{sys,dev,proc} || true
}
clean_image() {
# FIXME: clean package achives
clean_target $CLEAN_PATHS
# FIXME: reload package index
}
if [ "${1}" != "--source-only" ]; then
cli $@
fi

118
lib.sh Normal file
View File

@ -0,0 +1,118 @@
# Declares helpers for image building
set -e
[ "$DEBUG" = "1" ] && set -x
prepare_nbd_volume() {
device=$1
if ! `mountpoint -q "$TARGET"`; then
sudo mkfs.ext4 "$device"
sudo mkdir -p "$TARGET.device"
sudo mount "$device" "$TARGET.device"
rsync -aHAX "$TARGET/" "$TARGET.device"
fi
}
require_debootstrap() {
type -P debootstrap >/dev/null && return
sudo apt-get update
sudo apt-get -y install debootstrap
}
clean_workspace() {
sudo rm -rf $TARGET/* $TARGET/.??*
}
debootstrap() {
if [ ! -d "$TARGET.debootstrap" ]; then
sudo debootstrap \
--arch="$ARCH" \
--variant="$VARIANT" \
--components="$COMPONENTS" \
--include="$PKGS_INCLUDE" \
"$VERSION" \
"$TARGET.debootstrap" \
"$MIRROR" \
"$SCRIPT"
fi
rsync -aHAX "$TARGET.debootstrap/" "$TARGET/"
}
upgrade_debs() {
do_in_target "apt-get update"
do_in_target "apt-get -y upgrade"
}
secondstage() {
# This step could be done directly by removing
# do_in_target /debootstrap/debootstrap --second-stage
echo "Not needed anymore (removed the --foreign option)"
}
patch_target() {
patches_dir=../$1
for file in $(find "$patches_dir" -type f | sed -n "s|^$patches_dir/||p"); do
sudo mkdir -p "$TARGET/$(dirname $file)"
sudo cp "$patches_dir/$file" "$TARGET/$file"
done
}
clean_target() {
clean_paths="$@"
for path in $clean_paths; do
if [ -e "$TARGET/$path" ]; then
sudo rm -rf "$TARGET/$path"
fi
done
for file in $(find "$TARGET/var/log" -type f); do
echo | sudo tee $file
done
find "$TARGET" \( -name "*~" -or -name ".??*~" -or -name "#*#" -or -name ".#*" \) -delete
}
archive_target() {
sudo tar -C "$TARGET" -czf "$NAME.tar.gz" .
}
do_in_target() {
sudo chroot "$TARGET" su - root -c "$@"
}
push_to_s3() {
edit_date=$(stat -c %Y "$TARGET")
s3cmd put --acl-public "$NAME.tar.gz" "$S3_URL/$NAME-${edit_date}.tar.gz"
s3cmd put --acl-public "$NAME.tar.gz" "$S3_URL/$NAME-latest.tar.gz"
s3cmd ls "s3://rescue-images/rescue/"
# s3cmd cp --acl-public "s3://rescue-images/rescue/$NAME-${edit_date}.tar.gz" "s3://rescue-images/rescue/$NAME-latest.tar.gz"
}
cli() {
case $1 in
"tarball")
build_image
patch_image
upgrade_image
clean_image
archive_target
push_to_s3
exit 0
;;
"image")
NBD_DEVICE=${2:-"/dev/nbd1"}
build_image
patch_image
upgrade_image
clean_image
prepare_nbd_volume $NBD_DEVICE
sync
exit 0
;;
"build_image"|"patch_image"|"archive_target"|"prepare_nbd_volume"|"upgrade_image"|"clean_image"|"push_to_s3")
eval $@
exit 0
;;
esac
echo >&2 "usage: [DEBUG=1] $0 (tarball|image)"
exit 1
}

View File

@ -1,53 +0,0 @@
####################################################
# This is the configuration file for localepurge(8).
####################################################
# Comment this to enable localepurge.
# NO COMMENT IT IF YOU ARE NOT SURE WHAT ARE YOU DOING
# THIS APP DO NOT ASK FOR CONFIRMATION
#NEEDSCONFIGFIRST
####################################################
# Uncommenting this string enables removal of localized
# man pages based on the configuration information for
# locale files defined below:
MANDELETE
####################################################
# Uncommenting this string causes localepurge to simply delete
# locales which have newly appeared on the system without
# bothering you about it:
#DONTBOTHERNEWLOCALE
#####################################################
# Commenting out this string enables faster but less
# accurate calculation of freed disk space:
#QUICKNDIRTYCALC
####################################################
# Uncommenting this string enables display of freed disk
# space if localepurge has purged any superfluous data:
SHOWFREEDSPACE
#####################################################
# Commenting out this string disables verbose output:
#VERBOSE
#####################################################
# You like Colors?
#NOCOLOR
#####################################################
# You can use the -v -d -nc options in command line.
#####################################################
# Following locales won't be deleted from this system
# for example:
en_US
en_US.UTF-8

View File

@ -3,7 +3,7 @@
# - http://support.ntp.org/bin/view/Support/GettingStarted
# - https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon
server ntp.int.scaleway.com
server ntp.int.cloud.online.net
# Associate to public NTP pool servers; see http://www.pool.ntp.org/
server 0.arch.pool.ntp.org

View File

@ -1,2 +0,0 @@
# default nameserver
nameserver 8.8.8.8

View File

@ -1,133 +0,0 @@
# $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
# The default requires explicit activation of protocol 1
#Protocol 2
# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024
# Ciphers and keying
#RekeyLimit default none
# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
PermitRootLogin without-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#RSAAuthentication yes
#PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
# Change to no to disable s/key passwords
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no # pam does that
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation sandbox # Default for new installations.
PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# override default of no subsystems
Subsystem sftp /usr/lib/ssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server

View File

@ -2,7 +2,6 @@
Name=eth0
[Network]
DHCP=yes
DNS=10.1.31.38
DNS=10.1.31.39
Domains=scaleway.com
Domains=cloud.online.net

View File

@ -1,6 +0,0 @@
# Scaleway's DNS
[Resolve]
DNS=10.1.31.38
FallbackDNS=8.8.8.8 8.8.4.4
LLMNR=no

View File

@ -1,35 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Serial Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
BindsTo=dev-%i.device
After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service
After=rc-local.service
# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes
[Service]
ExecStart=-/sbin/agetty --keep-baud %I 9600 vt102
Type=idle
Restart=always
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes
[Install]
WantedBy=getty.target

View File

@ -1,23 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Network Name Resolution
Documentation=man:systemd-resolved.service(8)
After=NetworkManager-wait-online.service
[Service]
Type=notify
Restart=always
RestartSec=0
ExecStart=/usr/lib/systemd/systemd-resolved
CapabilityBoundingSet=CAP_SETUID CAP_SETGID CAP_SETPCAP CAP_CHOWN CAP_DAC_OVERRIDE CAP_FOWNER
ProtectSystem=full
ProtectHome=yes
[Install]
WantedBy=multi-user.target

View File

@ -1,18 +0,0 @@
# Fetch Scaleway metadata
fetch_scw_metadata()
{
metadata_host_name=$(/usr/local/bin/oc-metadata --cached HOSTNAME)
if [ "x$metadata_host_name" != "x" ]; then
echo $metadata_host_name > /etc/hostname
sed "/^127.0.1.1[ \t].*$/ s/.*$/127.0.1.1\t$metadata_host_name/" -i /etc/hosts
sed "/^127.0.0.1[ \t]localhost/ s/localhost.*$/localhost $metadata_host_name/" -i /etc/hosts
export new_host_name="${metadata_host_name}"
hostname $metadata_host_name
echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = ${metadata_host_name}
fi
}
if $if_up; then
fetch_scw_metadata
fi

View File

@ -1,36 +0,0 @@
#!/bin/bash
METADATA_CACHE=`mktemp -u`
get_metadata() {
if [ ! -f $METADATA_CACHE ]; then
/usr/local/bin/oc-metadata --cached > $METADATA_CACHE
fi
}
get_value() {
# Get value from metadata
key="$1"
grep "^$key=" "$METADATA_CACHE" | cut -d= -f2 | sed "s/^['\"]//;s/['\"]$//"
}
add_volumes() {
keys=$(get_value VOLUMES)
for key in $keys
do
test $key -eq 0 && continue
host=$(get_value VOLUMES_${key}_EXPORT_URI | sed 's|nbd://\(.*\):.*|\1|')
port=$(get_value VOLUMES_${key}_EXPORT_URI | sed 's|nbd://.*:\(.*\)|\1|')
device=/dev/nbd$key
xnbd-client -c $device && continue
for i in {1..3}
do
xnbd-client --connect $device $host $port --blocksize 4096 && break
sleep 5
done
done
}
get_metadata
add_volumes
rm $METADATA_CACHE

View File

@ -1,15 +0,0 @@
#!/bin/sh
# Thanks to the LTSP project
# If the root /dev/nbd0 device is unmounted on reboot then nbd read
# errors occur, and if it isn't, then # the nbd-server process on the server
# doesn't terminate.
# Called by init scripts on reboot.
NBD_CLIENT=/usr/local/sbin/xnbd-client
disconnect() {
$NBD_CLIENT -d "/dev/nbd0"
echo b > /proc/sysrq-trigger
}
disconnect

View File

@ -1,45 +0,0 @@
#!/bin/bash
ROOT_DEVICE="/dev/nbd0"
umount_nbd_devices() {
for device in $(mount | cut -d " " -f 1 | grep /dev/nbd)
do
test $device = $ROOT_DEVICE && continue
umount $device 2>/dev/null
if [ $? -eq 1 ]
then
echo -n "umount of $device failed! Data loss may occur! will continue in 10 seconds..."
sleep 1
for i in 9 8 7 6 5 4 3 2 1
do
echo -n $i" "
sleep 1
done
echo "ok, going on..."
fi
done
}
swapoff_nbd_devices() {
for device in $(grep '^/dev/nb' /proc/swaps | cut -d ' ' -f1)
do
swapoff $device 2> /dev/null
done
}
disconnect_devices() {
for device in $(ls /dev/nbd*)
do
test $device = $ROOT_DEVICE && continue
if xnbd-client -c $device 2> /dev/null
then
xnbd-client -d $device
fi
done
}
umount_nbd_devices
swapoff_nbd_devices
disconnect_devices