reorganize

This commit is contained in:
illiliti
2020-03-08 02:12:31 +03:00
parent ea46267e85
commit 871db084bb
6 changed files with 1 additions and 1 deletions

14
usr/share/tinyramfs/group Normal file
View File

@@ -0,0 +1,14 @@
root:x:0:
tty:x:5:
dialout:x:11:
uucp:x:14:
kmem:x:3:
input:x:25:
video:x:13:
audio:x:12:
lp:x:10:
disk:x:9:
cdrom:x:16:
tape:x:6:
kvm:x:24:
floppy:x:8:

163
usr/share/tinyramfs/init Normal file
View File

@@ -0,0 +1,163 @@
#!/sbin/busybox sh
#
# tiny init script
panic() {
printf "panic >> %s\n" "$1"
# TODO fix job control
sh
}
parse_cmdline() {
# store output in variable
read -r cmdline < /proc/cmdline
# turn output into list
set -f && set +f -- $cmdline
for line in "$@"; do
value="${line##*=}"
case "${line%%=*}" in
debug) debug="$value" ;;
init) init="$value" ;;
root) root="$value" ;;
root.type) root_type="$value" ;;
root.opts) root_opts="$value" ;;
lvm) lvm="$value" ;;
lvm.name) lvm_name="$value" ;;
lvm.group) lvm_group="$value" ;;
lvm.args) lvm_args="$value" ;;
luks) luks="$value" ;;
luks.root) luks_root="$value" ;;
luks.name) luks_name="$value" ;;
luks.discard) luks_discard="$value" ;;
luks.args) luks_args="$value" ;;
# TODO implement
#lvm.discard) ;;
#lvm.config) ;;
#luks.header) ;;
#luks.keyfile) ;;
esac
done
}
mount_pseudofs() {
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
}
setup_devmgr() {
case "$devmgr" in
udev)
udevd -d
udevadm trigger -c add -t subsystems
udevadm trigger -c add -t devices
udevadm settle
;;
mdev)
mdev -df &
find /sys -name modalias -type f -exec sort -u {} + |
xargs modprobe -ba
;;
mdevd)
mdevd &
mdevd-coldplug
;;
*)
panic "devmgr option broken"
;;
esac
}
findfs_sh() {
value="${1##*=}"
case "${1%%=*}" in
LABEL) device="/dev/disk/by-label/${value}" ;;
UUID) device="/dev/disk/by-uuid/${value}" ;;
PARTUUID) device="/dev/disk/by-partuuid/${value}" ;;
/dev/*) device="$1" ;;
*) panic "findfs option broken" ;;
esac
# avoid race condition
while [ ! -e "$device" ]; do
sleep 0.5
[ "$increment" ] || increment=0
increment=$(( increment + 1 ))
[ "$increment" = 10 ] && panic "failed to lookup partition"
done
printf "%s\n" "$device"
}
unlock_luks() {
[ "$luks_discard" = 1 ] && luks_args="--allow-discards $luks_args"
cryptsetup $luks_args \
luksOpen \
$(findfs_sh "$luks_root") \
${luks_name:-luks_root} ||
panic "failed to unlock luks container"
}
trigger_lvm() {
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
lvm lvchange $lvm_args --sysinit -q -a y "${lvm_group}/${lvm_name}" > /dev/null
elif [ "$lvm_group" ]; then
lvm vgchange $lvm_args --sysinit -q -a y "$lvm_group" > /dev/null
else
lvm vgchange $lvm_args --sysinit -q -a y > /dev/null
fi
}
mount_rootfs() {
mount ${root_type:+-t $root_type} \
${root_opts:+-o $root_opts} \
$(findfs_sh "$root") \
/mnt/root ||
panic "failed to mount rootfs"
}
cleanup() {
case "$devmgr" in
udev) udevadm control -e ;;
mdev) killall mdev ;;
mdevd) killall mdevd ;;
esac
# unmount pseudofs's
umount /dev /sys /proc
}
boot_system() {
exec switch_root /mnt/root \
${init:-/sbin/init} ||
panic "failed to boot system"
}
/sbin/busybox --install -s
. /config || panic "failed to source config"
mount_pseudofs
parse_cmdline
[ "$debug" = 1 ] && set -x
setup_devmgr
# TODO handle situations when LUKS on LVM
[ "$luks" = 1 ] &&
command -v cryptsetup > /dev/null 2>&1 && unlock_luks
[ "$lvm" = 1 ] &&
command -v lvm > /dev/null 2>&1 && trigger_lvm
mount_rootfs
[ "$debug" = 1 ] && panic "dropping to shell"
cleanup
boot_system

View File

@@ -0,0 +1,96 @@
# Copyright (c) 2012-2019, 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 US
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# mdev-like-a-boss
# Syntax:
# [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
#
# [-]: do not stop on this match, continue reading mdev.conf
# =: move, >: move and create a symlink
# !: do not create device node
# @|$|*: run cmd if $ACTION=remove, @cmd if $ACTION=add, *cmd in all cases
# support module loading on hotplug
$MODALIAS=.* 0:0 660 @modprobe -b "$MODALIAS"
# null may already exist; therefore ownership has to be changed with command
null 0:0 666 @chmod 666 $MDEV
zero 0:0 666
full 0:0 666
random 0:0 444
urandom 0:0 444
hwrandom 0:0 444
grsec 0:0 660
kmem 0:0 640
mem 0:0 640
port 0:0 640
# console may already exist; therefore ownership has to be changed with command
console 0:5 600 @chmod 600 $MDEV
ptmx 0:5 666
pty.* 0:5 660
# typical devices
tty 0:5 666
tty[0-9]* 0:5 660
vcsa*[0-9]* 0:5 660
ttyS[0-9]* 0:14 660
# block devices
ram([0-9]*) 0:9 660 >rd/%1
loop([0-9]+) 0:9 660 >loop/%1
sr[0-9]* 0:16 660 @ln -sf $MDEV cdrom
fd[0-9]* 0:8 660
SUBSYSTEM=block;.* 0:9 660 */lib/mdev/storage-device
# raid controllers
cciss!(.*) 0:9 660 =cciss/%1
ida!(.*) 0:9 660 =ida/%1
rd!(.*) 0:9 660 =rd/%1
# graphics
card[0-9] 0:13 660 =dri/
agpgart 0:0 660 >misc/
psaux 0:0 660 >misc/
rtc 0:0 664 >misc/
# input stuff
SUBSYSTEM=input;.* 0:25 660
# drm etc
dri/.* 0:13 660
# don't create old usbdev* devices.
usbdev[0-9].[0-9]* 0:0 660 !
# stop creating x:x:x:x which looks like /dev/dm-*
[0-9]+\:[0-9]+\:[0-9]+\:[0-9]+ 0:0 660 !
# /dev/cpu support.
microcode 0:0 600 =cpu/
cpu([0-9]+) 0:0 600 =cpu/%1/cpuid
msr([0-9]+) 0:0 600 =cpu/%1/msr

View File

@@ -0,0 +1,2 @@
root:x:0:0::/root:/bin/sh
nobody:x:99:99::/:/bin/false

View File

@@ -0,0 +1,133 @@
#!/bin/sh
# Copyright (c) 2012-2019, 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 US
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This script meant to create /dev/disk/by-* and /dev/mapper/* symlinks.
# and remove them after storage device is removed.
# the /dev/disk/by-* handling based on the idea and proof of concept from BitJam.
# debug
#exec >> /run/debug-mdev 2>&1
#set -x
#echo '### ENV:'
#env
#echo '### CODE:'
#
umask 077
storage_dir="/tmp/.mdev-like-a-boss"
[ -d "$storage_dir" ] || mkdir "$storage_dir"
[ "$MDEV" ] || exit 2
create_uuid_label_symlink() {
target_dir="/dev/disk/by-${1}"
target_symlink="${target_dir}/${2}"
[ -e "$target_symlink" ] && return
mkdir -p "$target_dir"
ln -sf "/dev/${MDEV}" "$target_symlink"
printf "%s\n" "$target_symlink" > "${storage_dir}/storage_symlink_${1}_${MDEV}"
}
add_symlinks() {
# Skip temp cryptsetup nodes.
case "$MDEV" in
dm-[0-9]*)
case $(cat "/sys/block/${MDEV}/dm/name") in
temporary-cryptsetup-[0-9]*)
return 0
;;
esac
;;
esac
if command -v blkid > /dev/null 2>&1; then
blkid_output=$(blkid "/dev/${MDEV}")
eval "${blkid_output#*: }"
[ "$UUID" ] && create_uuid_label_symlink uuid "$UUID"
[ "$LABEL" ] && create_uuid_label_symlink label "$LABEL"
[ "$PARTUUID" ] && create_uuid_label_symlink partuuid "$PARTUUID"
fi
if [ -f "/sys/block/${MDEV}/dm/name" ]; then
[ -d /dev/mapper ] || mkdir /dev/mapper
if ! [ -c /dev/mapper/control ]; then
while read -r dm; do
[ "${dm#* }" = device-mapper ] && {
mknod /dev/mapper/control c 10 "${dm% *}" || exit 1
break
}
done < /proc/misc
fi
dmname=$(cat "/sys/block/${MDEV}/dm/name")
if [ "$dmname" ]; then
target_symlink="/dev/mapper/${dmname}"
[ -e "$target_symlink" ] && return
ln -sf "/dev/${MDEV}" "$target_symlink"
printf "%s\n" "$target_symlink" > "${storage_dir}/storage_symlink_mapper_${MDEV}"
fi
fi
}
set_readahead() {
read_ahead_kb_control="/sys/class/block/${MDEV}/queue/read_ahead_kb"
new_read_ahead_kb="2048"
if [ -f "$read_ahead_kb_control" ]; then
read_ahead_kb=$(cat "$read_ahead_kb_control")
if [ "$read_ahead_kb" -lt "$new_read_ahead_kb" ]; then
logger -t mdev "Changing $MDEV read_ahead_kb from $read_ahead_kb to $new_read_ahead_kb"
printf "%s" "$new_read_ahead_kb" > "$read_ahead_kb_control"
fi
fi
}
drop_symlinks() {
for type in uuid label mapper; do
[ -f "${storage_dir}/storage_symlink_${type}_${MDEV}" ] || continue
target_symlink=$(cat "${storage_dir}/storage_symlink_${type}_${MDEV}" 2> /dev/null)
[ "$target_symlink" ] || continue
target_symlink_device=$(readlink "$target_symlink")
if [ "$target_symlink_device" = "/dev/${MDEV}" ]; then
rm "$target_symlink"
fi
rm "${storage_dir}/storage_symlink_${type}_${MDEV}"
done
}
case "$ACTION" in
add | "")
add_symlinks
set_readahead
;;
remove)
drop_symlinks
;;
esac