newer-initramfs/rootfs/init

103 lines
3.5 KiB
Bash
Executable File

#!/bin/sh
# better-initramfs project
# https://bitbucket.org/piotrkarbowski/better-initramfs
# Copyright (c) 2010-2013, Piotr Karbowski <piotr.karbowski@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of the Piotr Karbowski nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE
: ${PATH:=/bin:/sbin:/usr/bin:/usr/sbin}
# Load functions.
. /functions.sh
run_hooks init
# Prepare dirs
run dodir /dev /newroot /sbin /proc /sys /etc /var/log /var/run
# Basic /dev content, we need it as fast as possible.
[ ! -e /dev/console ] && run mknod /dev/console c 5 1
[ ! -e /dev/null ] && run mknod /dev/null c 1 3
[ ! -e /dev/tty ] && run mknod /dev/tty c 5 0
[ ! -e /dev/urandom ] && run mknod /dev/urandom c 1 9
[ ! -e /dev/random ] && run mknod /dev/random c 1 8
[ ! -e /dev/zero ] && run mknod /dev/zero c 1 5
# Clear the screen
clear
# Save IFS so we can easly restore it if we ever change it.
readonly default_ifs="${IFS}"
# Basic
kernelver="$(uname -r)"
ver="$(cat /VERSION)"
einfo "better-initramfs ${ver}. Linux kernel ${kernelver}.\n"
echo -e "\nWelcome to better-initramfs ${ver}. Linux kernel ${kernelver}.\n" > /etc/motd
emount /proc /sys
# Disable kernel messages from popping onto the screen
echo 0 > /proc/sys/kernel/printk
process_commandline_options
InitializeBusybox
emount /dev
run_hooks early
SetupNetwork
use sshd && setup_sshd
loadkeymap
# Let's try to support all possible combinations of storage layers.
use bcache register_bcache_devices
use softraid InitializeSoftwareRaid && use bcache register_bcache_devices
use lvm InitializeLVM && use bcache register_bcache_devices
use luks InitializeLUKS && use lvm InitializeLVM && use bcache register_bcache_devices
use zfs InitializeZFS
populate_dev_disk_by_label_and_uuid
use rescueshell rescueshell
use swsusp && SwsuspResume
use uswsusp && UswsuspResume
use tuxonice TuxOnIceResume
run_hooks pre_newroot_mount
use rootdelay rootdelay
emount /newroot
emount /newroot/usr
# Wait for sshd connection only if rescueshell have never occur.
use sshd && was_shell || wait_sshd
cleanup
moveDev
eumount /sys /proc
run_hooks pre_switch_root
boot_newroot
ewarn "Something went wrong."
rescueshell
# vim: noexpandtab