summaryrefslogtreecommitdiff
path: root/archiso
diff options
context:
space:
mode:
Diffstat (limited to 'archiso')
-rw-r--r--archiso/archiso_pxe_nbd6
-rw-r--r--archiso/archiso_shutdown40
-rw-r--r--archiso/hooks/archiso_pxe_common42
-rw-r--r--archiso/hooks/archiso_pxe_http61
-rw-r--r--archiso/hooks/archiso_pxe_nfs26
-rw-r--r--archiso/hooks/archiso_shutdown23
-rw-r--r--archiso/install/archiso_kms14
-rw-r--r--archiso/install/archiso_pxe_common30
-rw-r--r--archiso/install/archiso_pxe_http15
-rw-r--r--archiso/install/archiso_pxe_nfs16
-rw-r--r--archiso/install/archiso_shutdown18
11 files changed, 291 insertions, 0 deletions
diff --git a/archiso/archiso_pxe_nbd b/archiso/archiso_pxe_nbd
new file mode 100644
index 0000000..e6b9872
--- /dev/null
+++ b/archiso/archiso_pxe_nbd
@@ -0,0 +1,6 @@
+omit_kill_nbd_client() {
+ add_omit_pids $(< /run/archiso/nbd_client.pid)
+}
+
+add_hook shutdown_prekillall omit_kill_nbd_client
+add_hook single_prekillall omit_kill_nbd_client
diff --git a/archiso/archiso_shutdown b/archiso/archiso_shutdown
new file mode 100644
index 0000000..85cce59
--- /dev/null
+++ b/archiso/archiso_shutdown
@@ -0,0 +1,40 @@
+#!/bin/ash
+
+# /oldroot depends on things inside /oldroot/run/archiso...
+mkdir /oldrun
+mount -n --move /oldroot/run /oldrun
+
+# Unmount all mounts now.
+umount $(mount | awk '$3 ~/^\/oldroot/ {print $3}' | sort -r)
+
+# Remove all dm-snapshot devices.
+dmsetup remove_all
+
+# Remove all loopback devices.
+for _lup in $(grep ^/dev/loop /oldrun/archiso/used_block_devices | tac); do
+ if ! losetup -d ${_lup} 2> /dev/null; then
+ umount -d ${_lup}
+ fi
+done
+
+# Unmount the space used to store *.cow.
+umount /oldrun/archiso/cowspace
+
+# Unmount boot device if needed (no copytoram=y used)
+if [[ ! -d /oldrun/archiso/copytoram ]]; then
+ if [[ -d /oldrun/archiso/img_dev ]]; then
+ umount /oldrun/archiso/img_dev
+ else
+ umount /oldrun/archiso/bootmnt
+ fi
+ if [[ -f /oldrun/archiso/nbd_client.pid ]]; then
+ nbd-client -d /dev/nbd0
+ fi
+fi
+
+# reboot / poweroff / halt, depending on the argument passed by init
+# if something invalid is passed, we halt
+case "$1" in
+ reboot|poweroff|halt) "$1" -f ;;
+ *) halt -f;;
+esac
diff --git a/archiso/hooks/archiso_pxe_common b/archiso/hooks/archiso_pxe_common
new file mode 100644
index 0000000..febb503
--- /dev/null
+++ b/archiso/hooks/archiso_pxe_common
@@ -0,0 +1,42 @@
+# vim: set ft=sh:
+
+run_hook () {
+ local i net_mac bootif_mac bootif_dev
+ # These variables will be parsed from /tmp/net-*.conf generated by ipconfig
+ local DEVICE
+ local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1
+ local HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH
+ local filename
+ # /tmp/net-*.conf
+
+ if [[ -n "${ip}" ]]; then
+ if [[ -n "${BOOTIF}" ]]; then
+ bootif_mac=${BOOTIF#01-}
+ bootif_mac=${bootif_mac//-/:}
+ for i in /sys/class/net/*/address; do
+ read net_mac < ${i}
+ if [[ "${bootif_mac}" == "${net_mac}" ]]; then
+ bootif_dev=${i#/sys/class/net/}
+ bootif_dev=${bootif_dev%/address}
+ break
+ fi
+ done
+ ip="${ip}::${bootif_dev}"
+ fi
+
+ # setup network and save some values
+ ipconfig "ip=${ip}"
+
+ . /tmp/net-*.conf
+
+ pxeserver=${ROOTSERVER}
+
+ # setup DNS resolver
+ if [[ "${IPV4DNS0}" != "0.0.0.0" ]]; then
+ echo "nameserver ${IPV4DNS0}" > /etc/resolv.conf
+ fi
+ if [[ "${IPV4DNS1}" != "0.0.0.0" ]]; then
+ echo "nameserver ${IPV4DNS1}" >> /etc/resolv.conf
+ fi
+ fi
+}
diff --git a/archiso/hooks/archiso_pxe_http b/archiso/hooks/archiso_pxe_http
new file mode 100644
index 0000000..ae56210
--- /dev/null
+++ b/archiso/hooks/archiso_pxe_http
@@ -0,0 +1,61 @@
+# vim: set ft=sh:
+
+run_hook() {
+ if [[ -n "${ip}" && -n "${archiso_http_srv}" ]]; then
+
+ archiso_http_srv=$(eval echo ${archiso_http_srv})
+ [[ -z "${archiso_http_spc}" ]] && archiso_http_spc="75%"
+
+ mount_handler="archiso_pxe_http_mount_handler"
+ fi
+}
+
+# Fetch a file with CURL
+#
+# $1 URL
+# $2 Destination directory inside httpspace/${archisobasedir}
+_curl_get() {
+ local _url="${1}"
+ local _dst="${2}"
+
+ msg ":: Downloading '${_url}'"
+ if ! curl -f -o "/run/archiso/httpspace/${archisobasedir}${_dst}/${_url##*/}" --create-dirs "${_url}"; then
+ echo "ERROR: Downloading '${_url}'"
+ echo " Falling back to interactive prompt"
+ echo " You can try to fix the problem manually, log out when you are finished"
+ launch_interactive_shell
+ fi
+}
+
+archiso_pxe_http_mount_handler () {
+ newroot="${1}"
+
+ msg ":: Mounting /run/archiso/httpspace (tmpfs) filesystem, size='${archiso_http_spc}'"
+ mkdir -p "/run/archiso/httpspace"
+ mount -t tmpfs -o size="${archiso_http_spc}",mode=0755 httpspace "/run/archiso/httpspace"
+
+ local _aitab_url="${archiso_http_srv}${aitab#/run/archiso/bootmnt/}"
+ local _aitab_file="/run/archiso/httpspace/${aitab#/run/archiso/bootmnt/}"
+
+ _curl_get "${_aitab_url}" "/"
+
+ local aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size
+ while read aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size; do
+ [[ "${aitab_img#\#}" != "${aitab_img}" ]] && continue
+ [[ "${aitab_arch}" != "any" && "${aitab_arch}" != "${arch}" ]] && continue
+ if [[ "${aitab_fs_type}" != "none" ]]; then
+ _curl_get "${archiso_http_srv}${archisobasedir}/${aitab_arch}/${aitab_img}.fs.sfs" "/${aitab_arch}"
+ else
+ _curl_get "${archiso_http_srv}${archisobasedir}/${aitab_arch}/${aitab_img}.sfs" "/${aitab_arch}"
+ fi
+ done < "${_aitab_file}"
+
+ if [[ "${checksum}" == "y" ]]; then
+ _curl_get "${archiso_http_srv}${archisobasedir}/checksum.${arch}.md5" "/"
+ fi
+
+ mkdir -p "/run/archiso/bootmnt"
+ mount -o bind /run/archiso/httpspace /run/archiso/bootmnt
+
+ archiso_mount_handler ${newroot}
+}
diff --git a/archiso/hooks/archiso_pxe_nfs b/archiso/hooks/archiso_pxe_nfs
new file mode 100644
index 0000000..a053672
--- /dev/null
+++ b/archiso/hooks/archiso_pxe_nfs
@@ -0,0 +1,26 @@
+# vim: set ft=sh:
+
+run_hook() {
+ if [[ -n "${ip}" && -n "${archiso_nfs_srv}" ]]; then
+
+ archiso_nfs_srv=$(eval echo ${archiso_nfs_srv})
+ [[ -n "${archiso_nfs_opt}" ]] && archiso_nfs_opt="-o ${archiso_nfs_opt}"
+
+ mount_handler="archiso_nfs_mount_handler"
+ fi
+}
+
+archiso_nfs_mount_handler() {
+ newroot="${1}"
+ mkdir -p "/run/archiso/bootmnt"
+ msg ":: Mounting '${archiso_nfs_srv}'"
+ # Do not put "${archiso_nfs_opt}" nfsmount fails!
+ if ! nfsmount ${archiso_nfs_opt} "${archiso_nfs_srv}" "/run/archiso/bootmnt"; then
+ echo "ERROR: Mounting '${archiso_nfs_srv}'"
+ echo " Falling back to interactive prompt"
+ echo " You can try to fix the problem manually, log out when you are finished"
+ launch_interactive_shell
+ fi
+
+ archiso_mount_handler ${newroot}
+}
diff --git a/archiso/hooks/archiso_shutdown b/archiso/hooks/archiso_shutdown
new file mode 100644
index 0000000..24e4103
--- /dev/null
+++ b/archiso/hooks/archiso_shutdown
@@ -0,0 +1,23 @@
+run_hook ()
+{
+ msg -n ":: Creating shutdown ramfs..."
+
+ for _dir in bin lib sbin usr/bin usr/lib usr/sbin; do
+ mkdir -p /run/initramfs/${_dir}
+ done
+ cp /bin/busybox /run/initramfs/bin/
+ cp /lib/ld-* /run/initramfs/lib/
+ cp /lib/lib* /run/initramfs/lib/
+ cp /usr/lib/lib* /run/initramfs/usr/lib/
+ cp /bin/mount /run/initramfs/bin/
+ cp /sbin/dmsetup /run/initramfs/sbin/
+ cp /sbin/losetup /run/initramfs/sbin/
+ if [[ -x /bin/nbd-client ]]; then
+ cp /bin/nbd-client /run/initramfs/bin/
+ fi
+
+ chroot /run/initramfs /bin/busybox --install
+ cp /shutdown /run/initramfs/
+
+ msg "done."
+}
diff --git a/archiso/install/archiso_kms b/archiso/install/archiso_kms
new file mode 100644
index 0000000..6566049
--- /dev/null
+++ b/archiso/install/archiso_kms
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+build() {
+ MODULES="radeon nouveau i915 via-agp sis-agp intel-agp"
+ if [[ $(uname -m) == i686 ]]; then
+ MODULES+=" amd64-agp ati-agp sworks-agp ali-agp amd-k7-agp nvidia-agp efficeon-agp"
+ fi
+}
+
+help() {
+ cat << HELPEOF
+Adds all common KMS drivers to the initramfs image.
+HELPEOF
+}
diff --git a/archiso/install/archiso_pxe_common b/archiso/install/archiso_pxe_common
new file mode 100644
index 0000000..b37e5a1
--- /dev/null
+++ b/archiso/install/archiso_pxe_common
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+build() {
+ MODULES="${MODULES} $(comm -2 -3 <(checked_modules "/drivers/net/" | sort) \
+ <(find $MODULEDIR/kernel/drivers/net/{irda,phy,wimax,wireless} \
+ -name '*.ko*' \
+ -exec bash -c 'printf "%s\n" "${@%%.ko*}" | sed "s@.*/@@;s@-@_@" | sort' _ {} +) \
+ | grep -v -e 'ppp_' -e 'plip' -e 'pppoe')"
+ SCRIPT="archiso_pxe_common"
+
+
+ add_binary /lib/initcpio/ipconfig /bin/ipconfig
+
+ # Add hosts support files+dns
+ add_symlink /lib/libnss_files.so.2 $(readlink /lib/libnss_files.so.2)
+ add_binary $(readlink -f /lib/libnss_files.so.2)
+ add_symlink /lib/libnss_dns.so.2 $(readlink /lib/libnss_dns.so.2)
+ add_binary $(readlink -f /lib/libnss_dns.so.2)
+
+ add_dir /etc
+ echo "hosts: files dns" > $BUILDROOT/etc/nsswitch.conf
+}
+
+help() {
+cat<<HELPEOF
+ This hook loads the necessary modules for boot via PXE.
+HELPEOF
+}
+
+# vim: set ft=sh ts=4 sw=4 et:
diff --git a/archiso/install/archiso_pxe_http b/archiso/install/archiso_pxe_http
new file mode 100644
index 0000000..9e2ff65
--- /dev/null
+++ b/archiso/install/archiso_pxe_http
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+build() {
+ SCRIPT="archiso_pxe_http"
+
+ add_binary curl
+}
+
+help() {
+cat<<HELPEOF
+ This hook loads the necessary modules for boot via PXE and HTTP.
+HELPEOF
+}
+
+# vim: set ft=sh ts=4 sw=4 et:
diff --git a/archiso/install/archiso_pxe_nfs b/archiso/install/archiso_pxe_nfs
new file mode 100644
index 0000000..f7b6f5d
--- /dev/null
+++ b/archiso/install/archiso_pxe_nfs
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+build() {
+ MODULES="nfs"
+ SCRIPT="archiso_pxe_nfs"
+
+ add_binary /lib/initcpio/nfsmount /bin/nfsmount
+}
+
+help() {
+ cat <<HELPEOF
+ This hook loads the necessary modules for boot via PXE and NFS.
+HELPEOF
+}
+
+# vim: set ft=sh ts=4 sw=4 et:
diff --git a/archiso/install/archiso_shutdown b/archiso/install/archiso_shutdown
new file mode 100644
index 0000000..87b8297
--- /dev/null
+++ b/archiso/install/archiso_shutdown
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+build() {
+ SCRIPT="archiso_shutdown"
+
+ add_file /usr/lib/initcpio/archiso_shutdown /shutdown
+}
+
+help() {
+ cat <<HELPEOF
+This hook will create a shutdown initramfs in /run/initramfs
+that we can pivot to on shutdown in order to unmount / and
+and others mount points, dm-snapshot devices and loopback devices.
+Mostly usefull for dm-snapshot persistent.
+HELPEOF
+}
+
+# vim: set ft=sh ts=4 sw=4 et: