1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#!/bin/bash
# Copyright (c) 2012 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org
#
# Server side script to generate stage3.1,2 initial ramfses for OpenSLX Linux
# stateless clients
#############################################################################
# first parameter is a hash pointing to the target directory
# /srv/openslx/build
# in the future the prefix should be set via slxsettings ...
MODULE_DIR=${ROOT_DIR}/server
STAGE31_STATIC_DIR=${ROOT_DIR}/data/stage3.1
STAGE31_DIR=${MODULE_DIR}/stage3.1
STAGE32_DIR=${ROOT_DIR}/remote/stage3.2
# initial checks
initial_checks() {
local TOOL_STR="$TOOL_STR initial_checks:"
[ -d "${STAGE32_DIR}" ] || perror "No stage3.2 directory found. Please run './mltk --tools -b' first."
[ -e "${STAGE32_DIR}/openslx/bin/busybox" ] || perror "Busybox not found, run './mltk --tools -b busybox' first."
[ -z $(which mksquashfs) ] && perror "mksquashfs not found, please install squashfs-tools first."
}
generate_rootfs() {
local TOOL_STR="$TOOL_STR generate_rootfs:"
# produce stage3.1
mkdir -p "${STAGE31_DIR}" || perror "Cannot create stage3.1 dir '${STAGE31_DIR}'"
# produce openslx dir
mkdir -p "${MODULE_DIR}/openslx/mnt" || perror "Cannot create openslx dir '${MODULE_DIR}/openslx/mnt'"
# create basic directory structure
mkdir -p "${STAGE31_DIR}"/{bin,dev,proc,run,etc,mnt,sys} || perror "Cannot create basic directory structure in '${STAGE31_DIR}'"
# copy device files from running system
cp -a /dev/{console,kmsg,mem,null,tty,tty0,tty1,tty9,urandom,zero} \
"${STAGE31_DIR}"/dev || perror "Cannot copy devices from running system"
# copy busybox, its libs and static data to stage3.1
cp -r "${STAGE32_DIR}"/openslx/* "${STAGE31_STATIC_DIR}"/* "${STAGE31_DIR}" || perror "Copying busybox, its libs and static data failed."
# fetch the libraries needed for busybox
BASICLIBS=""
for i in $(ldd "${STAGE31_DIR}/bin/busybox");
do
if [ $(echo $i | grep '^/' | grep -c ld) -eq 1 \
-o $(echo $i | grep '^/' | grep -c libc.so) -eq 1 ];
then
BASICLIBS="$BASICLIBS $i $(readlink -f "$i")"
fi
done
tarcopy "$BASICLIBS" "${STAGE31_DIR}"
#check for kernel modules, if not present copy from system
if [ ! -d ${STAGE31_DIR}/lib/modules ];
then
pinfo "Copying modules for kernel $(uname -r)..."
mkdir -p "${STAGE31_DIR}/lib/modules/$(uname -r)/kernel" || perror "Cannot create '${STAGE31_DIR}/lib/modules/$(uname -r)/kernel'"
cd /lib/modules/$(uname -r)/kernel || perror "No Directory /lib/modules/$(uname -r)/kernel found."
tarcopy "$(cat ${MODULE_DIR}/stage31.modules)" "${STAGE31_DIR}/lib/modules/$(uname -r)/kernel"
cd - >/dev/null
else
pinfo "Not copying kernel modules from system, as '${STAGE31_DIR}/lib/modules' already exists."
fi
#check for firmware, if not present copy from system
if [ ! -d ${STAGE31_DIR}/lib/firmware ];
then
pinfo "Copying firmware for kernel $(uname -r)..."
mkdir -p "${STAGE31_DIR}/lib/firmware/$(uname -r)" || perror "Cannot create '${STAGE31_DIR}/lib/firmware/$(uname -r)'"
cd /lib/firmware || perror "No Directory /lib/firmware found."
tarcopy "$(cat ${MODULE_DIR}/stage31.firmware)" "${STAGE31_DIR}/lib/firmware"
cd - >/dev/null
cd /lib/firmware/$(uname -r) || perror "No Directory /lib/firmware/$(uname -r) found."
tarcopy "$(cat ${MODULE_DIR}/stage31.firmware)" "${STAGE31_DIR}/lib/firmware/$(uname -r)"
cd - >/dev/null
else
pinfo "Not copying firmware from system, as '${STAGE31_DIR}/lib/firmware' already exists."
fi
#generate initramfs
generate_initramfs "initramfs" "${STAGE31_DIR}"
}
generate_squashfs() {
[[ $CORE_NO_SQUASHFS == 1 ]] && return
local TOOL_STR="$TOOL_STR generate_squashfs:"
[ -e "${MODULE_DIR}/openslx/mnt/openslx.sqfs" ] && rm "${MODULE_DIR}/openslx/mnt/openslx.sqfs"
pinfo "Writing openslx.sqfs to '${MODULE_DIR}/openslx/mnt/'"
mksquashfs "${STAGE32_DIR}" "${MODULE_DIR}/openslx/mnt/openslx.sqfs" -comp xz -b 1M -no-recovery || perror "mksquashfs failed ($?)."
generate_initramfs "initramfs2" "${MODULE_DIR}/openslx"
}
generate_stage31() {
initial_checks
generate_rootfs
generate_squashfs
if [ ! -e ${MODULE_DIR}/kernel ]; then
local TOOL_STR="$TOOL_STR copy_kernel:"
pinfo "Copying Kernel $(uname -r) to ${MODULE_DIR}/kernel"
cp "/boot/vmlinuz-$(uname -r)" "${MODULE_DIR}/kernel" || perror "Cannot copy kernel from '/boot/vmlinuz-$(uname -r)' to '${MODULE_DIR}/kernel'"
else
pinfo "Not copying kernel from system, as it already exists."
fi
}
clean_core() {
local TOOL_STR="$TOOL_STR clean_core:"
pinfo "Cleaning '${STAGE31_DIR}'..."
[ -d ${STAGE31_DIR} ] && { rm -rf ${STAGE31_DIR} || perror "rm -rf failed."; }
pinfo "Cleaning '${MODULE_DIR}/kernel'..."
[ -e ${MODULE_DIR}/kernel ] && { rm ${MODULE_DIR}/kernel || perror "rm failed."; }
pinfo "Cleaning '${MODULE_DIR}/initramfs'..."
[ -e ${MODULE_DIR}/initramfs ] && { rm ${MODULE_DIR}/initramfs || perror "rm failed."; }
pinfo "Cleaning '${MODULE_DIR}/openslx'..."
[ -d ${MODULE_DIR}/openslx ] && { rm -rf ${MODULE_DIR}/openslx || perror "rm failed."; }
pinfo "Cleaning '${MODULE_DIR}/initramfs2'..."
[ -d ${MODULE_DIR}/initramfs2 ] && { rm ${MODULE_DIR}/initramfs2 || perror "rm failed."; }
}
|