3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
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.
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')"
19 USAGE
="${PROGRAM} [--force]"
23 # Reading configuration files
24 Read_conffiles config
/all config
/common config
/bootstrap config
/chroot config
/binary config
/source
27 Echo_message
"Begin building root filesystem image..."
29 # Requiring stage file
30 Require_stagefile .build
/config .build
/bootstrap .build
/binary_chroot
33 Check_stagefile .build
/binary_rootfs
41 case "${LIVE_IMAGE_ARCHITECTURE}" in
51 case "${LB_INITRAMFS}" in
66 mkdir
-p binary
/${INITFS}
68 for STAGE
in ${LB_CACHE_STAGES}
70 if [ "${STAGE}" = "rootfs" ] && [ -d cache
/binary_rootfs
]
73 rm -rf binary
/"${INITFS}"/filesystem.
*
76 mkdir
-p binary
/"${INITFS}"
77 cp -a cache
/binary_rootfs
/filesystem.
* binary
/"${INITFS}"
80 Create_stagefile .build
/binary_rootfs
85 case "${LB_CHROOT_FILESYSTEM}" in
88 Check_package chroot
/sbin
/mkfs.
${LB_CHROOT_FILESYSTEM} e2fsprogs
91 Restore_cache cache
/packages.binary
97 if [ -f binary
/${INITFS}/filesystem.
${LB_CHROOT_FILESYSTEM} ]
99 rm -f binary
/${INITFS}/filesystem.
${LB_CHROOT_FILESYSTEM}
102 case "${LB_BUILD_WITH_CHROOT}" in
104 DU_DIM
="$(du -ms chroot/chroot | cut -f1)"
105 INODES
="$(find chroot/chroot | wc -l)"
109 DU_DIM
="$(du -ms chroot | cut -f1)"
110 INODES
="$(find chroot | wc -l)"
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
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"
123 Chroot chroot
"ln -s /proc/mounts/mtab /etc/mtab"
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" ]
135 Chroot chroot
"rm -f /etc/mtab"
138 umount filesystem.tmp
142 mv chroot
/filesystem.
${LB_CHROOT_FILESYSTEM} binary
/${INITFS}
146 du
-B 1 -s chroot
/chroot | cut
-f1 > binary
/${INITFS}/filesystem.size
150 if [ -e chroot
/chroot.cache
]
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
${@}
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 ${@}
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
209 Save_cache cache
/packages.binary
214 Check_package chroot
/usr
/sbin
/mkfs.jffs2 mtd-tools
217 Restore_cache cache
/packages.binary
222 # Remove old jffs2 image
223 if [ -f binary
/${INITFS}/filesystem.jffs2
]
225 rm -f binary
/${INITFS}/filesystem.jffs2
228 if [ -n "${LB_JFFS2_ERASEBLOCK}" ]
230 JFFS2_OPTIONS
="--eraseblock=${LB_JFFS2_ERASEBLOCK}"
233 case "${LB_BUILD_WITH_CHROOT}" in
235 Chroot chroot
"mkfs.jffs2 ${JFFS2_OPTIONS} --root=chroot --output filesystem.jffs2"
238 mv chroot
/filesystem.jffs2 binary
/${INITFS}
240 if [ -e chroot
/chroot.cache
]
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
${@}
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 ${@}
286 mkfs.jffs2
${JFFS2_OPTIONS} --root=chroot
--output binary
/${INITFS}/filesystem.jffs2
291 Save_cache cache
/packages.binary
295 if [ -d binary
/${INITFS}/filesystem.dir
]
297 rm -rf binary
/${INITFS}/filesystem.dir
300 case "${LB_BUILD_WITH_CHROOT}" in
302 mv chroot
/chroot binary
/${INITFS}/filesystem.dir
306 cp -a chroot binary
/${INITFS}/filesystem.dir
313 Check_package chroot
/usr
/share
/doc
/squashfs-tools squashfs-tools
316 Restore_cache cache
/packages.binary
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
]
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" ]
337 MKSQUASHFS_OPTIONS
="${MKSQUASHFS_OPTIONS} -info"
340 if [ -f config
/rootfs
/squashfs.
sort ]
342 MKSQUASHFS_OPTIONS
="${MKSQUASHFS_OPTIONS} -sort squashfs.sort"
344 case "${LB_BUILD_WITH_CHROOT}" in
346 cp config
/rootfs
/squashfs.
sort chroot
350 cp config
/rootfs
/squashfs.
sort .
355 if [ "${LB_MODE}" != "ubuntu" ]
357 MKSQUASHFS_OPTIONS
="${MKSQUASHFS_OPTIONS} -comp xz"
360 case "${LB_BUILD_WITH_CHROOT}" in
362 if [ -e config
/rootfs
/excludes
]
364 cp config
/rootfs
/excludes chroot
/excludes
366 MKSQUASHFS_OPTIONS
="${MKSQUASHFS_OPTIONS} -wildcards -ef /excludes"
370 Chroot chroot
"mksquashfs chroot filesystem.squashfs ${MKSQUASHFS_OPTIONS}"
372 rm -f chroot
/chroot
/excludes
376 du
-B 1 -s chroot
/chroot | cut
-f1 > binary
/${INITFS}/filesystem.size
381 mv chroot
/filesystem.squashfs binary
/${INITFS}
382 rm -f chroot
/squashfs.
sort
384 if [ -e chroot
/chroot.cache
]
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
${@}
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 ${@}
428 chmod 0644 binary
/${INITFS}/filesystem.squashfs
432 if [ -e config
/rootfs
/excludes
]
434 MKSQUASHFS_OPTIONS
="${MKSQUASHFS_OPTIONS} -wildcards -ef config/rootfs/excludes"
437 mksquashfs chroot binary
/${INITFS}/filesystem.squashfs
${MKSQUASHFS_OPTIONS}
441 du
-B 1 -s chroot | cut
-f1 > binary
/${INITFS}/filesystem.size
448 Save_cache cache
/packages.binary
457 case "${LB_BUILD_WITH_CHROOT}" in
459 mv chroot
/chroot binary
463 Echo_message
"This may take a while."
471 for STAGE
in ${LB_CACHE_STAGES}
473 if [ "${STAGE}" = "rootfs" ]
475 rm -rf cache
/binary_rootfs
477 mkdir
-p cache
/binary_rootfs
479 if [ "${LB_CHROOT_FILESYSTEM}" != "none" ]
481 cp -a binary
/"${INITFS}"/filesystem.
* cache
/binary_rootfs
486 # Creating stage file
487 Create_stagefile .build
/binary_rootfs