blob: 59a3468a0bba96966430decbadc9223e7f951e2d (
plain)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
#!/bin/bash
set -u
clear
printf "%b" "Sourcing colors...\n"
# Colors defined for text
source colors.sh
printf "%b" "Sourcing environment variables...\n"
# LFS build environment settings
source env.sh
printf "%b" "Sourcing functions...\n"
# Functions used during build
source functions.sh
# Version check script
#source versioncheck.sh
printf "%b" "\n\n\n${CYN}BUILDING ${YLW}${LFS_VER} $(uname -m)${CYN} at \
${IWHT}${LFS}${CYN} on ${IWHT}${LFS_DISK}${LFS_PART}${RST}\n\n"
printf "%b" "${IRED}*** ${IREDB}WARNING${RST} \
${IWHT}POTENTIAL DATA LOSS \
${IREDB}WARNING ${RST}${IRED}***${GRN}\n${RST}"
printf "%b" "${GRN}Automatic creation of partition(s), filesystem(s) \n\
and mounting will occur unless manually performed\n\
before continuing.${RST}\n\n\n"
# Continue or Abort
printf "%b" "${IGRN}CONTINUE ${IWHTB}(C)${RST} / ${IRED}ABORT ${IWHTB}(OTHER)${RST}\n"
if read -r -n 1 contabort; then
if [[ "$contabort" == "C" ]] || [[ "$contabort" == "c" ]]; then
printf "%b" "\b${IWHT}Build is "
success "CONTINUING\n"
else
printf "%b" "\b${IWHT}Build "
fail "ABORTED!\n"
exit 0
fi
else
printf "%b" "\b${IWHT}Selection "
fail "FAILURE!\n"
exit 1
fi
# Create LFS directory if it doesn't exist
printf "%b" "${GRN}Creating LFS directory at ${YLW}${LFS}${GRN}${RST}... "
if [[ -d "${LFS}" ]]; then
success "EXISTS"
else
if ! sudo mkdir "${LFS}" >/dev/null 2>&1; then
fail "FAILED!"
exit 1
fi
fi
# Setup partition, filesystem, format and mount if
# LFS filesystem is not previously mounted
if ! grep -q "${LFS}" /proc/mounts; then
printf "%b" "${GRN}Preparing LFS partition and filesystem${RST}...\n"
source setupdisk.sh "${LFS_DISK}" "${LFS_PART}"
printf "%b" " ${IGRN}Mounting ${IWHT}${LFS_DISK}${LFS_PART} ${IGRN}at \
${IWHT}${LFS}${RST}\n"
sudo mount "${LFS_DISK}${LFS_PART}" "${LFS}"
fi
# Create limited directory layout
if [[ ! -f "${LFS}"/sources/limited ]]; then
printf "%b" " ${IGRN}Changing ownership of ${IWHT}${LFS}${IGRN} \
to user ${IWHT}${USER}${RST}\n"
sudo chown "${USER}" "${LFS}"
printf "%b" " ${IGRN}Creating limited directory structure at \
${IWHT}${LFS}${IGRN}${RST}\n"
mkdir -p "${LFS}"/sources
mkdir -p "${LFS}"/tools
mkdir -p "${LFS}"/bin
mkdir -p "${LFS}"/etc
mkdir -p "${LFS}"/lib
mkdir -p "${LFS}"/sbin
mkdir -p "${LFS}"/usr
mkdir -p "${LFS}"/var
touch "${LFS}"/sources/limited
fi
case $(uname -m) in
x86_64) mkdir -p "${LFS}"/lib64 ;;
esac
# Will use normal user and not special lfs user
#sudo groupadd lfs
#sudo useradd -s /bin/bash -g lfs -m -k /dev/null lfs
#printf "%b" "${LFS_PWD}\n${LFS_PWD}\n" | sudo passwd lfs
# Copy scripts and csv files to LFS sources target
printf "%b" "${GRN}Copying required files to ${YLW}${LFS}/sources \
${GRN}target directory${RST}... "
if ! cp -rf ./*.sh chapter* ./*.csv kernelconfig "${LFS}/sources"; then
fail "FAILED!"
else
success "OK"
fi
cd "${LFS}/sources" || exit 1
# Download packages and patches
printf "%b" "\n${IWHT}============ ${IGRN}Downloading source files and patches \
${IWHT}============${RST}\n"
source download.sh
retval=$?
if [[ "$retval" -ne 0 ]]; then
exit 1
fi
# Chapter 5
printf "%b" "\n${IWHT}============ ${IGRN}Building ${IYLW}Chapter 5${IWHT} \
============${RST}\n"
for package in binutils gcc linux-api-headers glibc libstdc++; do
source packageinstall.sh 5 $package
retval=$?
if [[ "$retval" -ne 0 ]]; then
exit 1
fi
done
# Chapter 6
printf "%b" "\n${IWHT}============ ${IGRN}Building ${IYLW}Chapter 6${IWHT} \
============${RST}\n"
for package in m4 ncurses bash coreutils diffutils file findutils gawk grep gzip make patch sed tar xz binutils gcc; do
source packageinstall.sh 6 $package
retval=$?
if [[ "$retval" -ne 0 ]]; then
exit 1
fi
done
printf "%b" "\n${IWHT}======= ${IYLW}Chapter 6 ${IGRN}Cleanup and Backup \
${IWHT}=======${RST}\n"
source chapter6/cleanup.sh
source chapter6/backup.sh
# Prepare chroot scripts to be executable for owner, group and others
chmod ugo+x preparechroot.sh
chmod ugo+x insidechroot.sh
printf "%b" "\n${CYN}PREPARING ${RED}CHROOT${CYN} ENVIRONMENT${RST}...\n"
source preparechroot.sh "${LFS}"
source createdirs.sh
source essential.sh
printf "%b" "\n${CYN}ENTERING ${RED}CHROOT${CYN} ENVIRONMENT${RST}...\n"
sleep 3
# Create chapter7 log directory as non root user
mkdir -p "${LFS}"/sources/log/chapter7
# Enter CHROOT for chapter 7
sudo chroot "${LFS}" /usr/bin/env -i \
HOME=/root \
TERM="${TERM}" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
NUMPROCS="${NUMPROCS}" \
MAKEFLAGS="${MAKEFLAGS}" \
NINJAJOBS="${MAKEFLAGS}" \
SPINNER="${SPINNER}" \
/bin/bash --login +h -c "/sources/insidechroot.sh 7"
retval=$?
printf "%b" "\n${CYN}EXITED ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n"
# Cleanup and Backup if chapter 7 successfully finished
if [[ "$retval" -eq 0 ]]; then
source umountvirtfs.sh
printf "%b" "\n${IWHT}======= ${IYLW}Chapter 7 ${IGRN}Cleanup and Backup \
${IWHT}=======${RST}\n"
# shellcheck source=chapter7/cleanup.sh
source "${LFS}"/sources/chapter7/cleanup.sh
# shellcheck source=chapter7/backup.sh
source "${LFS}"/sources/chapter7/backup.sh
else
exit "$retval"
fi
# Mount virtual kernel filesystems after cleanup and backup
source mountvirtfs.sh
printf "%b" "\n${CYN}ENTERING ${RED}CHROOT${CYN} ENVIRONMENT...${RST}\n"
sleep 3
# Create chapter8 log directory as non root user
mkdir -p "${LFS}"/sources/log/chapter8
# Enter CHROOT for chapter 8
sudo chroot "${LFS}" /usr/bin/env -i \
HOME=/root \
TERM="${TERM}" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
NUMPROCS="${NUMPROCS}" \
MAKEFLAGS="${MAKEFLAGS}" \
NINJAJOBS="${NINJAJOBS}" \
SPINNER="${SPINNER}" \
/bin/bash --login +h -c "/sources/insidechroot.sh 8"
retval=$?
printf "%b" "\n${CYN}EXITED ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n"
# Cleanup and Backup if chapter 8 successfully finished
if [[ "$retval" -eq 0 ]]; then
source umountvirtfs.sh
printf "%b" "\n${IWHT}======= ${IYLW}Chapter 8 ${IGRN}Cleanup and Backup \
${IWHT}=======${RST}\n"
# shellcheck source=chapter8/cleanup.sh
source "${LFS}"/sources/chapter8/cleanup.sh
# shellcheck source=chapter8/backup.sh
source "${LFS}"/sources/chapter8/backup.sh
else
exit "$retval"
fi
# Mount virtual kernel filesystems after cleanup and backup
source mountvirtfs.sh
printf "%b" "\n${CYN}ENTERING ${RED}CHROOT${CYN} ENVIRONMENT...${RST}\n"
sleep 3
# Create chapter9 log directory as non root user
mkdir -p "${LFS}"/sources/log/chapter9
# Enter CHROOT for chapter 9
sudo chroot "${LFS}" /usr/bin/env -i \
HOME=/root \
TERM="${TERM}" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
NUMPROCS="${NUMPROCS}" \
MAKEFLAGS="${MAKEFLAGS}" \
NINJAJOBS="${NINJAJOBS}" \
SPINNER="${SPINNER}" \
/bin/bash --login +h -c "/sources/insidechroot.sh 9"
retval=$?
printf "%b" "\n${CYN}EXITED ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n"
printf "%b" "\n${CYN}ENTERING ${RED}CHROOT${CYN} ENVIRONMENT...${RST}\n"
sleep 3
# Create chapter10 log directory as non root user
mkdir -p "${LFS}"/sources/log/chapter10
# Enter CHROOT for chapter 10
sudo chroot "${LFS}" /usr/bin/env -i \
HOME=/root \
TERM="${TERM}" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
NUMPROCS="${NUMPROCS}" \
MAKEFLAGS="${MAKEFLAGS}" \
NINJAJOBS="${NINJAJOBS}" \
SPINNER="${SPINNER}" \
LFS_DISK="${LFS_DISK}" \
LFS_PART="${LFS_PART}" \
LFS_FS="${LFS_FS}" \
LFS_SWAP="${LFS_SWAP}" \
/bin/bash --login +h -c "/sources/insidechroot.sh 10"
retval=$?
printf "%b" "\n${CYN}EXITED ${RED}CHROOT${RST} ENVIRONMENT...${RST}\n"
|