Moving partial python rewrite to separate branch, let's do it in the jessie+1 cycle...
[debian-live-build.git] / scripts / build / binary_rootfs
blob4c13346d6bec0d25846634a3e09682784f5b3995
1 #!/bin/sh
3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
5 ##
6 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7 ## This is free software, and you are welcome to redistribute it
8 ## under certain conditions; see COPYING for details.
11 set -e
13 # Including common functions
14 [ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
16 # Setting static variables
17 DESCRIPTION="$(Echo 'build rootfs image')"
18 HELP=""
19 USAGE="${PROGRAM} [--force]"
21 Arguments "${@}"
23 # Reading configuration files
24 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
25 Set_defaults
27 Echo_message "Begin building root filesystem image..."
29 # Requiring stage file
30 Require_stagefile .build/config .build/bootstrap .build/binary_chroot
32 # Checking stage file
33 Check_stagefile .build/binary_rootfs
35 # Checking lock file
36 Check_lockfile .lock
38 # Creating lock file
39 Create_lockfile .lock
41 case "${LIVE_IMAGE_ARCHITECTURE}" in
42 amd64|i386)
43 LINUX="vmlinuz"
46 powerpc)
47 LINUX="vmlinux"
49 esac
51 case "${LB_INITRAMFS}" in
52 casper)
53 INITFS="casper"
56 live-boot)
57 INITFS="live"
61 INITFS="boot"
63 esac
65 # Creating directory
66 mkdir -p binary/${INITFS}
68 for STAGE in ${LB_CACHE_STAGES}
70 if [ "${STAGE}" = "rootfs" ] && [ -d cache/binary_rootfs ]
71 then
72 # Removing old chroot
73 rm -rf binary/"${INITFS}"/filesystem.*
75 # Restoring old cache
76 mkdir -p binary/"${INITFS}"
77 cp -a cache/binary_rootfs/filesystem.* binary/"${INITFS}"
79 # Creating stage file
80 Create_stagefile .build/binary_rootfs
81 exit 0
83 done
85 case "${LB_CHROOT_FILESYSTEM}" in
86 ext2|ext3|ext4)
87 # Checking depends
88 Check_package chroot/sbin/mkfs.${LB_CHROOT_FILESYSTEM} e2fsprogs
90 # Restoring cache
91 Restore_cache cache/packages.binary
93 # Installing depends
94 Install_package
96 # Remove old image
97 if [ -f binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM} ]
98 then
99 rm -f binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM}
102 case "${LB_BUILD_WITH_CHROOT}" in
103 true)
104 DU_DIM="$(du -ms chroot/chroot | cut -f1)"
105 INODES="$(find chroot/chroot | wc -l)"
108 false)
109 DU_DIM="$(du -ms chroot | cut -f1)"
110 INODES="$(find chroot | wc -l)"
112 esac
114 REAL_DIM="$(Calculate_partition_size ${DU_DIM} ${LB_CHROOT_FILESYSTEM})"
115 REAL_INODES="$(Calculate_partition_size ${INODES} ${LB_CHROOT_FILESYSTEM})"
117 case "${LB_BUILD_WITH_CHROOT}" in
118 true)
119 dd if=/dev/zero of=chroot/filesystem.${LB_CHROOT_FILESYSTEM} bs=1024k count=0 seek=${REAL_DIM}
121 if ! Chroot chroot "test -s /etc/mtab"
122 then
123 Chroot chroot "ln -s /proc/mounts/mtab /etc/mtab"
124 FAKE_MTAB="true"
127 Chroot chroot "mkfs.${LB_CHROOT_FILESYSTEM} -F -b 1024 -N ${REAL_INODES} -m 0 filesystem.${LB_CHROOT_FILESYSTEM}"
129 mkdir -p filesystem.tmp
130 mount -o loop chroot/filesystem.${LB_CHROOT_FILESYSTEM} filesystem.tmp
131 cp -a chroot/chroot/* filesystem.tmp
133 if [ "${FAKE_MTAB}" = "true" ]
134 then
135 Chroot chroot "rm -f /etc/mtab"
138 umount filesystem.tmp
139 rmdir filesystem.tmp
141 # Move image
142 mv chroot/filesystem.${LB_CHROOT_FILESYSTEM} binary/${INITFS}
144 case "${LB_MODE}" in
145 ubuntu)
146 du -B 1 -s chroot/chroot | cut -f1 > binary/${INITFS}/filesystem.size
148 esac
150 if [ -e chroot/chroot.cache ]
151 then
152 rm -f .lock
153 mv chroot/chroot chroot.tmp
155 lb chroot_archives binary remove ${@}
156 lb chroot_apt remove ${@}
157 lb chroot_hostname remove ${@}
158 lb chroot_resolv remove ${@}
159 lb chroot_hosts remove ${@}
160 lb chroot_sysv-rc remove ${@}
161 lb chroot_upstart remove ${@}
162 lb chroot_dpkg remove ${@}
163 lb chroot_debianchroot remove ${@}
164 lb chroot_sysfs remove ${@}
165 lb chroot_selinuxfs remove ${@}
166 lb chroot_proc remove ${@}
167 lb chroot_devpts remove ${@}
169 rm -rf chroot
170 mv chroot.tmp chroot
172 lb chroot_devpts install ${@}
173 lb chroot_proc install ${@}
174 lb chroot_selinuxfs install ${@}
175 lb chroot_sysfs install ${@}
176 lb chroot_debianchroot install ${@}
177 lb chroot_dpkg install ${@}
178 lb chroot_sysv-rc install ${@}
179 lb chroot_upstart install ${@}
180 lb chroot_hosts install ${@}
181 lb chroot_resolv install ${@}
182 lb chroot_hostname install ${@}
183 lb chroot_apt install ${@}
184 lb chroot_archives binary install ${@}
186 touch .lock
187 else
188 rm -rf chroot/chroot
190 # Removing depends
191 Remove_package
195 false)
196 dd if=/dev/zero of=binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM} bs=1024k count=0 seek=${REAL_DIM}
197 mkfs.${LB_CHROOT_FILESYSTEM} -F -b 1024 -N ${REAL_INODES} -m 0 binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM}
199 mkdir -p filesystem.tmp
200 mount -o loop binary/${INITFS}/filesystem.${LB_CHROOT_FILESYSTEM} filesystem.tmp
201 cp -a chroot/* filesystem.tmp
203 umount filesystem.tmp
204 rmdir filesystem.tmp
206 esac
208 # Saving cache
209 Save_cache cache/packages.binary
212 jffs2)
213 # Checking depends
214 Check_package chroot/usr/sbin/mkfs.jffs2 mtd-tools
216 # Restoring cache
217 Restore_cache cache/packages.binary
219 # Installing depends
220 Install_package
222 # Remove old jffs2 image
223 if [ -f binary/${INITFS}/filesystem.jffs2 ]
224 then
225 rm -f binary/${INITFS}/filesystem.jffs2
228 if [ -n "${LB_JFFS2_ERASEBLOCK}" ]
229 then
230 JFFS2_OPTIONS="--eraseblock=${LB_JFFS2_ERASEBLOCK}"
233 case "${LB_BUILD_WITH_CHROOT}" in
234 true)
235 Chroot chroot "mkfs.jffs2 ${JFFS2_OPTIONS} --root=chroot --output filesystem.jffs2"
237 # Move image
238 mv chroot/filesystem.jffs2 binary/${INITFS}
240 if [ -e chroot/chroot.cache ]
241 then
242 rm -f .lock
243 mv chroot/chroot chroot.tmp
245 lb chroot_archives binary remove ${@}
246 lb chroot_apt remove ${@}
247 lb chroot_hostname remove ${@}
248 lb chroot_resolv remove ${@}
249 lb chroot_hosts remove ${@}
250 lb chroot_sysv-rc remove ${@}
251 lb chroot_upstart remove ${@}
252 lb chroot_dpkg remove ${@}
253 lb chroot_debianchroot remove ${@}
254 lb chroot_sysfs remove ${@}
255 lb chroot_selinuxfs remove ${@}
256 lb chroot_proc remove ${@}
257 lb chroot_devpts remove ${@}
259 rm -rf chroot
260 mv chroot.tmp chroot
262 lb chroot_devpts install ${@}
263 lb chroot_proc install ${@}
264 lb chroot_selinuxfs install ${@}
265 lb chroot_sysfs install ${@}
266 lb chroot_debianchroot install ${@}
267 lb chroot_dpkg install ${@}
268 lb chroot_sysv-rc install ${@}
269 lb chroot_upstart install ${@}
270 lb chroot_hosts install ${@}
271 lb chroot_resolv install ${@}
272 lb chroot_hostname install ${@}
273 lb chroot_apt install ${@}
274 lb chroot_archives binary install ${@}
276 touch .lock
277 else
278 rm -rf chroot/chroot
280 # Removing depends
281 Remove_package
285 false)
286 mkfs.jffs2 ${JFFS2_OPTIONS} --root=chroot --output binary/${INITFS}/filesystem.jffs2
288 esac
290 # Saving cache
291 Save_cache cache/packages.binary
294 plain)
295 if [ -d binary/${INITFS}/filesystem.dir ]
296 then
297 rm -rf binary/${INITFS}/filesystem.dir
300 case "${LB_BUILD_WITH_CHROOT}" in
301 true)
302 mv chroot/chroot binary/${INITFS}/filesystem.dir
305 false)
306 cp -a chroot binary/${INITFS}/filesystem.dir
308 esac
311 squashfs)
312 # Checking depends
313 Check_package chroot/usr/share/doc/squashfs-tools squashfs-tools
315 # Restoring cache
316 Restore_cache cache/packages.binary
318 # Installing depends
319 Install_package
321 Echo_message "Preparing squashfs image..."
322 Echo_message "This may take a while."
324 # Remove old squashfs image
325 if [ -f binary/${INITFS}/filesystem.squashfs ]
326 then
327 rm -f binary/${INITFS}/filesystem.squashfs
330 # Remove stale squashfs image
331 rm -f chroot/filesystem.squashfs
333 MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -no-progress"
335 if [ "${_VERBOSE}" = "true" ]
336 then
337 MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -info"
340 if [ -f config/rootfs/squashfs.sort ]
341 then
342 MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -sort squashfs.sort"
344 case "${LB_BUILD_WITH_CHROOT}" in
345 true)
346 cp config/rootfs/squashfs.sort chroot
349 false)
350 cp config/rootfs/squashfs.sort .
352 esac
355 if [ "${LB_MODE}" != "ubuntu" ]
356 then
357 MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -comp xz"
360 case "${LB_BUILD_WITH_CHROOT}" in
361 true)
362 if [ -e config/rootfs/excludes ]
363 then
364 cp config/rootfs/excludes chroot/excludes
366 MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -wildcards -ef /excludes"
369 # Create image
370 Chroot chroot "mksquashfs chroot filesystem.squashfs ${MKSQUASHFS_OPTIONS}"
372 rm -f chroot/chroot/excludes
374 case "${LB_MODE}" in
375 ubuntu)
376 du -B 1 -s chroot/chroot | cut -f1 > binary/${INITFS}/filesystem.size
378 esac
380 # Move image
381 mv chroot/filesystem.squashfs binary/${INITFS}
382 rm -f chroot/squashfs.sort
384 if [ -e chroot/chroot.cache ]
385 then
386 rm -f .lock
387 mv chroot/chroot chroot.tmp
389 lb chroot_archives binary remove ${@}
390 lb chroot_apt remove ${@}
391 lb chroot_hostname remove ${@}
392 lb chroot_resolv remove ${@}
393 lb chroot_hosts remove ${@}
394 lb chroot_sysv-rc remove ${@}
395 lb chroot_upstart remove ${@}
396 lb chroot_dpkg remove ${@}
397 lb chroot_debianchroot remove ${@}
398 lb chroot_sysfs remove ${@}
399 lb chroot_selinuxfs remove ${@}
400 lb chroot_proc remove ${@}
401 lb chroot_devpts remove ${@}
403 rm -rf chroot
404 mv chroot.tmp chroot
406 lb chroot_devpts install ${@}
407 lb chroot_proc install ${@}
408 lb chroot_selinuxfs install ${@}
409 lb chroot_sysfs install ${@}
410 lb chroot_debianchroot install ${@}
411 lb chroot_dpkg install ${@}
412 lb chroot_sysv-rc install ${@}
413 lb chroot_upstart install ${@}
414 lb chroot_hosts install ${@}
415 lb chroot_resolv install ${@}
416 lb chroot_hostname install ${@}
417 lb chroot_apt install ${@}
418 lb chroot_archives binary install ${@}
420 touch .lock
421 else
422 rm -rf chroot/chroot
424 # Removing depends
425 Remove_package
428 chmod 0644 binary/${INITFS}/filesystem.squashfs
431 false)
432 if [ -e config/rootfs/excludes ]
433 then
434 MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -wildcards -ef config/rootfs/excludes"
437 mksquashfs chroot binary/${INITFS}/filesystem.squashfs ${MKSQUASHFS_OPTIONS}
439 case "${LB_MODE}" in
440 ubuntu)
441 du -B 1 -s chroot | cut -f1 > binary/${INITFS}/filesystem.size
443 esac
445 esac
447 # Saving cache
448 Save_cache cache/packages.binary
451 none)
452 if [ -d binary ]
453 then
454 rm -rf binary
457 case "${LB_BUILD_WITH_CHROOT}" in
458 true)
459 mv chroot/chroot binary
462 false)
463 Echo_message "This may take a while."
464 cp -a chroot binary
466 esac
469 esac
471 for STAGE in ${LB_CACHE_STAGES}
473 if [ "${STAGE}" = "rootfs" ]
474 then
475 rm -rf cache/binary_rootfs
477 mkdir -p cache/binary_rootfs
479 if [ "${LB_CHROOT_FILESYSTEM}" != "none" ]
480 then
481 cp -a binary/"${INITFS}"/filesystem.* cache/binary_rootfs
484 done
486 # Creating stage file
487 Create_stagefile .build/binary_rootfs