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
|
#!/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 ...
ROOT_DIR=$(dirname $(readlink -f $0))
SELF=$(readlink -f $0)
STAGE31_STATIC_DIR=${ROOT_DIR}/../data/stage3.1
STAGE31_DIR=${ROOT_DIR}/stage3.1
STAGE32_DIR=${ROOT_DIR}/../remote/stage3.2
# initial checks
if [ "x$(whoami)" != "xroot" ]; then
echo "ERROR: You need to have root rights to install packages."
exit 1
fi
if [ ! -d ${STAGE32_DIR} ];
then
echo "No stage3.2 directory found. Please run setup-tools.sh first."
exit 1
fi
if [ ! -e ${STAGE32_DIR}/openslx/bin/busybox ];
then
echo "Busybox not found, run 'setup-tools.sh busybox' first."
exit 1
fi
# shouldn't squashfs-tools be automatically installed as we need them nevertheless!?
# what if it is already on the machine? faster to check with which than the apt-get check?
if [ -z $(which mksquashfs) ];
then
echo "mksquashfs not found, please install squashfs-tools first."
exit 1
fi
# produce stage3.1
[ ! -d ${STAGE31_DIR} ] && mkdir -p ${STAGE31_DIR}
# create basic directory structure
mkdir -p ${STAGE31_DIR}/{bin,dev,proc,run,lib,etc,mnt,sys}
# copy device files from running system
cp -a /dev/{console,kmsg,mem,null,tty,tty0,tty1,tty9,urandom,zero} \
${STAGE31_DIR}/dev
# copy busybox, its libs and static data to stage3.1
cp -r ${STAGE32_DIR}/openslx/* ${STAGE31_STATIC_DIR}/* ${STAGE31_DIR}
# 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
echo $i
BASICLIBS="$BASICLIBS $i $(readlink -f "$i")"
fi
done
tar cpv $BASICLIBS | tar xpv -C ${STAGE31_DIR} &>/dev/null
# finalize the initramfs target
[ ! -d ${STAGE32_DIR} ] && echo "No stage3.2 directory found. Please run setup_tools first." && exit 1
[ -e ${STAGE31_DIR}/mnt/openslx.sqfs ] && rm ${STAGE31_DIR}/mnt/openslx.sqfs
mksquashfs ${STAGE32_DIR} ${STAGE31_DIR}/mnt/openslx.sqfs -comp xz -b 1M -no-recovery 2>/dev/null
cd ${STAGE31_DIR}
find . | cpio --format="newc" --create | gzip -9 > ${ROOT_DIR}/initramfs
cd - &>/dev/null
|