mklive.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. #!/bin/bash
  2. #
  3. #-
  4. # Copyright (c) 2009-2015 Juan Romero Pardines.
  5. # All rights reserved.
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions
  9. # are met:
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. #-
  27. umask 022
  28. . ./lib.sh
  29. readonly REQUIRED_PKGS="base-files libgcc dash coreutils sed tar gawk syslinux grub-i386-efi grub-x86_64-efi memtest86+ squashfs-tools xorriso"
  30. readonly INITRAMFS_PKGS="binutils xz device-mapper dhclient dracut-network openresolv"
  31. readonly PROGNAME=$(basename "$0")
  32. declare -a INCLUDE_DIRS=()
  33. info_msg() {
  34. printf "\033[1m$@\n\033[m"
  35. }
  36. die() {
  37. info_msg "ERROR: $@"
  38. error_out 1 $LINENO
  39. }
  40. print_step() {
  41. CURRENT_STEP=$((CURRENT_STEP+1))
  42. info_msg "[${CURRENT_STEP}/${STEP_COUNT}] $@"
  43. }
  44. mount_pseudofs() {
  45. for f in sys dev proc; do
  46. mkdir -p "$ROOTFS"/$f
  47. mount --rbind /$f "$ROOTFS"/$f
  48. done
  49. }
  50. umount_pseudofs() {
  51. for f in sys dev proc; do
  52. if [ -d "$ROOTFS/$f" ] && ! umount -R -f "$ROOTFS/$f"; then
  53. info_msg "ERROR: failed to unmount $ROOTFS/$f/"
  54. return 1
  55. fi
  56. done
  57. }
  58. error_out() {
  59. trap - INT TERM 0
  60. umount_pseudofs || exit "${1:-0}"
  61. [ -d "$BUILDDIR" ] && [ -z "$KEEP_BUILDDIR" ] && rm -rf --one-file-system "$BUILDDIR"
  62. exit "${1:-0}"
  63. }
  64. usage() {
  65. cat <<-EOH
  66. Usage: $PROGNAME [options]
  67. Generates a basic live ISO image of Void Linux. This ISO image can be written
  68. to a CD/DVD-ROM or any USB stick.
  69. To generate a more complete live ISO image, use build-x86-images.sh.
  70. OPTIONS
  71. -a <arch> Set XBPS_ARCH in the ISO image
  72. -b <system-pkg> Set an alternative base package (default: base-system)
  73. -r <repo> Use this XBPS repository. May be specified multiple times
  74. -c <cachedir> Use this XBPS cache directory (default: ./xbps-cachedir-<arch>)
  75. -k <keymap> Default keymap to use (default: us)
  76. -l <locale> Default locale to use (default: en_US.UTF-8)
  77. -i <lz4|gzip|bzip2|xz>
  78. Compression type for the initramfs image (default: xz)
  79. -s <gzip|lzo|xz> Compression type for the squashfs image (default: xz)
  80. -o <file> Output file name for the ISO image (default: automatic)
  81. -p "<pkg> ..." Install additional packages in the ISO image
  82. -g "<pkg> ..." Ignore packages when building the ISO image
  83. -I <includedir> Include directory structure under given path in the ROOTFS
  84. -S "<service> ..." Enable services in the ISO image
  85. -e <shell> Default shell of the root user (must be absolute path).
  86. Set the live.shell kernel argument to change the default shell of anon.
  87. -C "<arg> ..." Add additional kernel command line arguments
  88. -T <title> Modify the bootloader title (default: Void Linux)
  89. -v linux<version> Install a custom Linux version on ISO image (default: linux metapackage)
  90. -K Do not remove builddir
  91. -h Show this help and exit
  92. -V Show version and exit
  93. EOH
  94. }
  95. copy_void_keys() {
  96. mkdir -p "$1"/var/db/xbps/keys
  97. cp keys/*.plist "$1"/var/db/xbps/keys
  98. }
  99. copy_dracut_files() {
  100. mkdir -p "$1"/usr/lib/dracut/modules.d/01vmklive
  101. cp dracut/vmklive/* "$1"/usr/lib/dracut/modules.d/01vmklive/
  102. }
  103. copy_autoinstaller_files() {
  104. mkdir -p "$1"/usr/lib/dracut/modules.d/01autoinstaller
  105. cp dracut/autoinstaller/* "$1"/usr/lib/dracut/modules.d/01autoinstaller/
  106. }
  107. install_prereqs() {
  108. XBPS_ARCH=$ARCH "$XBPS_INSTALL_CMD" -r "$VOIDHOSTDIR" ${XBPS_REPOSITORY} \
  109. -c "$XBPS_HOST_CACHEDIR" -y $REQUIRED_PKGS
  110. [ $? -ne 0 ] && die "Failed to install required software, exiting..."
  111. }
  112. install_packages() {
  113. XBPS_ARCH=$BASE_ARCH "${XBPS_INSTALL_CMD}" -r "$ROOTFS" \
  114. ${XBPS_REPOSITORY} -c "$XBPS_CACHEDIR" -yn $PACKAGE_LIST $INITRAMFS_PKGS
  115. [ $? -ne 0 ] && die "Missing required binary packages, exiting..."
  116. mount_pseudofs
  117. LANG=C XBPS_ARCH=$BASE_ARCH "${XBPS_INSTALL_CMD}" -U -r "$ROOTFS" \
  118. ${XBPS_REPOSITORY} -c "$XBPS_CACHEDIR" -y $PACKAGE_LIST $INITRAMFS_PKGS
  119. [ $? -ne 0 ] && die "Failed to install $PACKAGE_LIST"
  120. xbps-reconfigure -r "$ROOTFS" -f base-files >/dev/null 2>&1
  121. chroot "$ROOTFS" env -i xbps-reconfigure -f base-files
  122. # Enable choosen UTF-8 locale and generate it into the target rootfs.
  123. if [ -f "$ROOTFS"/etc/default/libc-locales ]; then
  124. sed -e "s/\#\(${LOCALE}.*\)/\1/g" -i "$ROOTFS"/etc/default/libc-locales
  125. fi
  126. chroot "$ROOTFS" env -i xbps-reconfigure -a
  127. # Cleanup and remove useless stuff.
  128. rm -rf "$ROOTFS"/var/cache/* "$ROOTFS"/run/* "$ROOTFS"/var/run/*
  129. }
  130. ignore_packages() {
  131. mkdir -p "$ROOTFS"/etc/xbps.d
  132. for pkg in $IGNORE_PKGS; do
  133. echo "ignorepkg=$pkg" >> "$ROOTFS"/etc/xbps.d/mklive-ignore.conf
  134. done
  135. }
  136. enable_services() {
  137. SERVICE_LIST="$*"
  138. for service in $SERVICE_LIST; do
  139. if ! [ -e $ROOTFS/etc/sv/$service ]; then
  140. die "service $service not in /etc/sv"
  141. fi
  142. ln -sf /etc/sv/$service $ROOTFS/etc/runit/runsvdir/default/
  143. done
  144. }
  145. change_shell() {
  146. chroot "$ROOTFS" chsh -s "$ROOT_SHELL" root
  147. [ $? -ne 0 ] && die "Failed to change the shell for root"
  148. }
  149. copy_include_directories() {
  150. for includedir in "${INCLUDE_DIRS[@]}"; do
  151. info_msg "=> copying include directory '$includedir' ..."
  152. find "$includedir" -mindepth 1 -maxdepth 1 -exec cp -rfpPv {} "$ROOTFS"/ \;
  153. done
  154. }
  155. generate_initramfs() {
  156. local _args
  157. copy_dracut_files "$ROOTFS"
  158. copy_autoinstaller_files "$ROOTFS"
  159. chroot "$ROOTFS" env -i /usr/bin/dracut -N --"${INITRAMFS_COMPRESSION}" \
  160. --add-drivers "ahci" --force-add "vmklive autoinstaller" --omit systemd "/boot/initrd" $KERNELVERSION
  161. [ $? -ne 0 ] && die "Failed to generate the initramfs"
  162. mv "$ROOTFS"/boot/initrd "$BOOT_DIR"
  163. cp "$ROOTFS"/boot/vmlinuz-$KERNELVERSION "$BOOT_DIR"/vmlinuz
  164. }
  165. cleanup_rootfs() {
  166. for f in ${INITRAMFS_PKGS}; do
  167. revdeps=$(xbps-query -r "$ROOTFS" -X $f)
  168. if [ -n "$revdeps" ]; then
  169. xbps-pkgdb -r "$ROOTFS" -m auto $f
  170. else
  171. xbps-remove -r "$ROOTFS" -Ry ${f} >/dev/null 2>&1
  172. fi
  173. done
  174. rm -r "$ROOTFS"/usr/lib/dracut/modules.d/01vmklive
  175. rm -r "$ROOTFS"/usr/lib/dracut/modules.d/01autoinstaller
  176. }
  177. generate_isolinux_boot() {
  178. cp -f "$SYSLINUX_DATADIR"/isolinux.bin "$ISOLINUX_DIR"
  179. cp -f "$SYSLINUX_DATADIR"/ldlinux.c32 "$ISOLINUX_DIR"
  180. cp -f "$SYSLINUX_DATADIR"/libcom32.c32 "$ISOLINUX_DIR"
  181. cp -f "$SYSLINUX_DATADIR"/vesamenu.c32 "$ISOLINUX_DIR"
  182. cp -f "$SYSLINUX_DATADIR"/libutil.c32 "$ISOLINUX_DIR"
  183. cp -f "$SYSLINUX_DATADIR"/chain.c32 "$ISOLINUX_DIR"
  184. cp -f "$SYSLINUX_DATADIR"/reboot.c32 "$ISOLINUX_DIR"
  185. cp -f "$SYSLINUX_DATADIR"/poweroff.c32 "$ISOLINUX_DIR"
  186. cp -f isolinux/isolinux.cfg.in "$ISOLINUX_DIR"/isolinux.cfg
  187. cp -f ${SPLASH_IMAGE} "$ISOLINUX_DIR"
  188. sed -i -e "s|@@SPLASHIMAGE@@|$(basename "${SPLASH_IMAGE}")|" \
  189. -e "s|@@KERNVER@@|${KERNELVERSION}|" \
  190. -e "s|@@KEYMAP@@|${KEYMAP}|" \
  191. -e "s|@@ARCH@@|$BASE_ARCH|" \
  192. -e "s|@@LOCALE@@|${LOCALE}|" \
  193. -e "s|@@BOOT_TITLE@@|${BOOT_TITLE}|" \
  194. -e "s|@@BOOT_CMDLINE@@|${BOOT_CMDLINE}|" \
  195. "$ISOLINUX_DIR"/isolinux.cfg
  196. # include memtest86+
  197. cp -f "$VOIDHOSTDIR"/boot/memtest86+/memtest.bin "$BOOT_DIR"
  198. }
  199. generate_grub_efi_boot() {
  200. cp -f grub/grub.cfg "$GRUB_DIR"
  201. cp -f grub/grub_void.cfg.in "$GRUB_DIR"/grub_void.cfg
  202. sed -i -e "s|@@SPLASHIMAGE@@|$(basename "${SPLASH_IMAGE}")|" \
  203. -e "s|@@KERNVER@@|${KERNELVERSION}|" \
  204. -e "s|@@KEYMAP@@|${KEYMAP}|" \
  205. -e "s|@@ARCH@@|$BASE_ARCH|" \
  206. -e "s|@@BOOT_TITLE@@|${BOOT_TITLE}|" \
  207. -e "s|@@BOOT_CMDLINE@@|${BOOT_CMDLINE}|" \
  208. -e "s|@@LOCALE@@|${LOCALE}|" "$GRUB_DIR"/grub_void.cfg
  209. mkdir -p "$GRUB_DIR"/fonts
  210. cp -f "$GRUB_DATADIR"/unicode.pf2 "$GRUB_DIR"/fonts
  211. modprobe -q loop || :
  212. # Create EFI vfat image.
  213. truncate -s 32M "$GRUB_DIR"/efiboot.img >/dev/null 2>&1
  214. mkfs.vfat -F12 -S 512 -n "grub_uefi" "$GRUB_DIR/efiboot.img" >/dev/null 2>&1
  215. GRUB_EFI_TMPDIR="$(mktemp --tmpdir="$HOME" -d)"
  216. LOOP_DEVICE="$(losetup --show --find "${GRUB_DIR}"/efiboot.img)"
  217. mount -o rw,flush -t vfat "${LOOP_DEVICE}" "${GRUB_EFI_TMPDIR}" >/dev/null 2>&1
  218. cp -a "$IMAGEDIR"/boot "$VOIDHOSTDIR"
  219. xbps-uchroot "$VOIDHOSTDIR" grub-mkstandalone -- \
  220. --directory="/usr/lib/grub/i386-efi" \
  221. --format="i386-efi" \
  222. --output="/tmp/bootia32.efi" \
  223. "boot/grub/grub.cfg"
  224. if [ $? -ne 0 ]; then
  225. umount "$GRUB_EFI_TMPDIR"
  226. losetup --detach "${LOOP_DEVICE}"
  227. die "Failed to generate EFI loader"
  228. fi
  229. mkdir -p "${GRUB_EFI_TMPDIR}"/EFI/BOOT
  230. cp -f "$VOIDHOSTDIR"/tmp/bootia32.efi "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTIA32.EFI
  231. xbps-uchroot "$VOIDHOSTDIR" grub-mkstandalone -- \
  232. --directory="/usr/lib/grub/x86_64-efi" \
  233. --format="x86_64-efi" \
  234. --output="/tmp/bootx64.efi" \
  235. "boot/grub/grub.cfg"
  236. if [ $? -ne 0 ]; then
  237. umount "$GRUB_EFI_TMPDIR"
  238. losetup --detach "${LOOP_DEVICE}"
  239. die "Failed to generate EFI loader"
  240. fi
  241. cp -f "$VOIDHOSTDIR"/tmp/bootx64.efi "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64.EFI
  242. umount "$GRUB_EFI_TMPDIR"
  243. losetup --detach "${LOOP_DEVICE}"
  244. rm -rf "$GRUB_EFI_TMPDIR"
  245. # include memtest86+
  246. cp -f "$VOIDHOSTDIR"/boot/memtest86+/memtest.efi "$BOOT_DIR"
  247. }
  248. generate_squashfs() {
  249. umount_pseudofs || exit 1
  250. # Find out required size for the rootfs and create an ext3fs image off it.
  251. ROOTFS_SIZE=$(du --apparent-size -sm "$ROOTFS"|awk '{print $1}')
  252. mkdir -p "$BUILDDIR/tmp/LiveOS"
  253. truncate -s "$((ROOTFS_SIZE+ROOTFS_SIZE))M" \
  254. "$BUILDDIR"/tmp/LiveOS/ext3fs.img >/dev/null 2>&1
  255. mkdir -p "$BUILDDIR/tmp-rootfs"
  256. mkfs.ext3 -F -m1 "$BUILDDIR/tmp/LiveOS/ext3fs.img" >/dev/null 2>&1
  257. mount -o loop "$BUILDDIR/tmp/LiveOS/ext3fs.img" "$BUILDDIR/tmp-rootfs"
  258. cp -a "$ROOTFS"/* "$BUILDDIR"/tmp-rootfs/
  259. umount -f "$BUILDDIR/tmp-rootfs"
  260. mkdir -p "$IMAGEDIR/LiveOS"
  261. "$VOIDHOSTDIR"/usr/bin/mksquashfs "$BUILDDIR/tmp" "$IMAGEDIR/LiveOS/squashfs.img" \
  262. -comp "${SQUASHFS_COMPRESSION}" || die "Failed to generate squashfs image"
  263. chmod 444 "$IMAGEDIR/LiveOS/squashfs.img"
  264. # Remove rootfs and temporary dirs, we don't need them anymore.
  265. rm -rf "$ROOTFS" "$BUILDDIR/tmp-rootfs" "$BUILDDIR/tmp"
  266. }
  267. generate_iso_image() {
  268. "$VOIDHOSTDIR"/usr/bin/xorriso -as mkisofs \
  269. -iso-level 3 -rock -joliet \
  270. -max-iso9660-filenames -omit-period \
  271. -omit-version-number -relaxed-filenames -allow-lowercase \
  272. -volid "VOID_LIVE" \
  273. -eltorito-boot boot/isolinux/isolinux.bin \
  274. -eltorito-catalog boot/isolinux/boot.cat \
  275. -no-emul-boot -boot-load-size 4 -boot-info-table \
  276. -eltorito-alt-boot -e boot/grub/efiboot.img -isohybrid-gpt-basdat -no-emul-boot \
  277. -isohybrid-mbr "$SYSLINUX_DATADIR"/isohdpfx.bin \
  278. -output "$OUTPUT_FILE" "$IMAGEDIR" || die "Failed to generate ISO image"
  279. }
  280. #
  281. # main()
  282. #
  283. while getopts "a:b:r:c:C:T:Kk:l:i:I:S:e:s:o:p:g:v:Vh" opt; do
  284. case $opt in
  285. a) BASE_ARCH="$OPTARG";;
  286. b) BASE_SYSTEM_PKG="$OPTARG";;
  287. r) XBPS_REPOSITORY="--repository=$OPTARG $XBPS_REPOSITORY";;
  288. c) XBPS_CACHEDIR="$OPTARG";;
  289. g) IGNORE_PKGS="$IGNORE_PKGS $OPTARG" ;;
  290. K) readonly KEEP_BUILDDIR=1;;
  291. k) KEYMAP="$OPTARG";;
  292. l) LOCALE="$OPTARG";;
  293. i) INITRAMFS_COMPRESSION="$OPTARG";;
  294. I) INCLUDE_DIRS+=("$OPTARG");;
  295. S) SERVICE_LIST="$SERVICE_LIST $OPTARG";;
  296. e) ROOT_SHELL="$OPTARG";;
  297. s) SQUASHFS_COMPRESSION="$OPTARG";;
  298. o) OUTPUT_FILE="$OPTARG";;
  299. p) PACKAGE_LIST="$PACKAGE_LIST $OPTARG";;
  300. C) BOOT_CMDLINE="$OPTARG";;
  301. T) BOOT_TITLE="$OPTARG";;
  302. v) LINUX_VERSION="$OPTARG";;
  303. V) version; exit 0;;
  304. h) usage; exit 0;;
  305. *) usage >&2; exit 1;;
  306. esac
  307. done
  308. shift $((OPTIND - 1))
  309. XBPS_REPOSITORY="$XBPS_REPOSITORY --repository=https://repo-default.voidlinux.org/current --repository=https://repo-default.voidlinux.org/current/musl"
  310. # Configure dracut to use overlayfs for the writable overlay.
  311. BOOT_CMDLINE="$BOOT_CMDLINE rd.live.overlay.overlayfs=1 "
  312. ARCH=$(xbps-uhelper arch)
  313. # Set defaults
  314. : ${BASE_ARCH:=$(xbps-uhelper arch 2>/dev/null || uname -m)}
  315. : ${XBPS_CACHEDIR:="$(pwd -P)"/xbps-cachedir-${BASE_ARCH}}
  316. : ${XBPS_HOST_CACHEDIR:="$(pwd -P)"/xbps-cachedir-${ARCH}}
  317. : ${KEYMAP:=us}
  318. : ${LOCALE:=en_US.UTF-8}
  319. : ${INITRAMFS_COMPRESSION:=xz}
  320. : ${SQUASHFS_COMPRESSION:=xz}
  321. : ${BASE_SYSTEM_PKG:=base-system}
  322. : ${BOOT_TITLE:="Void Linux"}
  323. case $BASE_ARCH in
  324. x86_64*|i686*) ;;
  325. *) >&2 echo architecture $BASE_ARCH not supported by mklive.sh; exit 1;;
  326. esac
  327. # Required packages in the image for a working system.
  328. PACKAGE_LIST="$BASE_SYSTEM_PKG $PACKAGE_LIST"
  329. # Check for root permissions.
  330. if [ "$(id -u)" -ne 0 ]; then
  331. die "Must be run as root, exiting..."
  332. fi
  333. trap 'error_out $? $LINENO' INT TERM 0
  334. if [ -n "$ROOTDIR" ]; then
  335. BUILDDIR=$(mktemp --tmpdir="$ROOTDIR" -d)
  336. else
  337. BUILDDIR=$(mktemp --tmpdir="$(pwd -P)" -d)
  338. fi
  339. BUILDDIR=$(readlink -f "$BUILDDIR")
  340. IMAGEDIR="$BUILDDIR/image"
  341. ROOTFS="$IMAGEDIR/rootfs"
  342. VOIDHOSTDIR="$BUILDDIR/void-host"
  343. BOOT_DIR="$IMAGEDIR/boot"
  344. ISOLINUX_DIR="$BOOT_DIR/isolinux"
  345. GRUB_DIR="$BOOT_DIR/grub"
  346. CURRENT_STEP=0
  347. STEP_COUNT=10
  348. [ "${#INCLUDE_DIRS[@]}" -gt 0 ] && STEP_COUNT=$((STEP_COUNT+1))
  349. [ -n "${IGNORE_PKGS}" ] && STEP_COUNT=$((STEP_COUNT+1))
  350. [ -n "$ROOT_SHELL" ] && STEP_COUNT=$((STEP_COUNT+1))
  351. : ${SYSLINUX_DATADIR:="$VOIDHOSTDIR"/usr/lib/syslinux}
  352. : ${GRUB_DATADIR:="$VOIDHOSTDIR"/usr/share/grub}
  353. : ${SPLASH_IMAGE:=data/splash.png}
  354. : ${XBPS_INSTALL_CMD:=xbps-install}
  355. : ${XBPS_REMOVE_CMD:=xbps-remove}
  356. : ${XBPS_QUERY_CMD:=xbps-query}
  357. : ${XBPS_RINDEX_CMD:=xbps-rindex}
  358. : ${XBPS_UHELPER_CMD:=xbps-uhelper}
  359. : ${XBPS_RECONFIGURE_CMD:=xbps-reconfigure}
  360. mkdir -p "$ROOTFS" "$VOIDHOSTDIR" "$ISOLINUX_DIR" "$GRUB_DIR"
  361. print_step "Synchronizing XBPS repository data..."
  362. copy_void_keys "$ROOTFS"
  363. copy_void_keys "$VOIDHOSTDIR"
  364. XBPS_ARCH=$BASE_ARCH $XBPS_INSTALL_CMD -r "$ROOTFS" ${XBPS_REPOSITORY} -S
  365. XBPS_ARCH=$ARCH $XBPS_INSTALL_CMD -r "$VOIDHOSTDIR" ${XBPS_REPOSITORY} -S
  366. # Get linux version for ISO
  367. # If linux version option specified use
  368. if [ -n "$LINUX_VERSION" ]; then
  369. if ! echo "$LINUX_VERSION" | grep "linux[0-9._]\+"; then
  370. die "-v option must be in format linux<version>"
  371. fi
  372. _linux_series="$LINUX_VERSION"
  373. PACKAGE_LIST="$PACKAGE_LIST $LINUX_VERSION"
  374. else # Otherwise find latest stable version from linux meta-package
  375. _linux_series=$(XBPS_ARCH=$BASE_ARCH $XBPS_QUERY_CMD -r "$ROOTFS" ${XBPS_REPOSITORY:=-R} -x linux | grep 'linux[0-9._]\+')
  376. fi
  377. _kver=$(XBPS_ARCH=$BASE_ARCH $XBPS_QUERY_CMD -r "$ROOTFS" ${XBPS_REPOSITORY:=-R} -p pkgver ${_linux_series})
  378. KERNELVERSION=$($XBPS_UHELPER_CMD getpkgversion ${_kver})
  379. if [ "$?" -ne "0" ]; then
  380. die "Failed to find kernel package version"
  381. fi
  382. : ${OUTPUT_FILE="void-live-${BASE_ARCH}-${KERNELVERSION}-$(date -u +%Y%m%d).iso"}
  383. print_step "Installing software to generate the image: ${REQUIRED_PKGS} ..."
  384. install_prereqs
  385. mkdir -p "$ROOTFS"/etc
  386. [ -s data/motd ] && cp data/motd "$ROOTFS"/etc
  387. [ -s data/issue ] && cp data/issue "$ROOTFS"/etc
  388. if [ -n "$IGNORE_PKGS" ]; then
  389. print_step "Ignoring packages in the rootfs: ${IGNORE_PKGS} ..."
  390. ignore_packages
  391. fi
  392. print_step "Installing void pkgs into the rootfs: ${PACKAGE_LIST} ..."
  393. install_packages
  394. : ${DEFAULT_SERVICE_LIST:=agetty-tty1 agetty-tty2 agetty-tty3 agetty-tty4 agetty-tty5 agetty-tty6 udevd}
  395. print_step "Enabling services: ${SERVICE_LIST} ..."
  396. enable_services ${DEFAULT_SERVICE_LIST} ${SERVICE_LIST}
  397. if [ -n "$ROOT_SHELL" ]; then
  398. print_step "Changing the root shell ..."
  399. change_shell
  400. fi
  401. if [ "${#INCLUDE_DIRS[@]}" -gt 0 ];then
  402. print_step "Copying directory structures into the rootfs ..."
  403. copy_include_directories
  404. fi
  405. print_step "Generating initramfs image ($INITRAMFS_COMPRESSION)..."
  406. generate_initramfs
  407. print_step "Generating isolinux support for PC-BIOS systems..."
  408. generate_isolinux_boot
  409. print_step "Generating GRUB support for EFI systems..."
  410. generate_grub_efi_boot
  411. print_step "Cleaning up rootfs..."
  412. cleanup_rootfs
  413. print_step "Generating squashfs image ($SQUASHFS_COMPRESSION) from rootfs..."
  414. generate_squashfs
  415. print_step "Generating ISO image..."
  416. generate_iso_image
  417. hsize=$(du -sh "$OUTPUT_FILE"|awk '{print $1}')
  418. info_msg "Created $(readlink -f "$OUTPUT_FILE") ($hsize) successfully."