10 cache_dir="${work_dir}/cache"
11 script_path=$(readlink -f ${0%/*})
13 mirror="http://ftp.jaist.ac.jp/pub/Linux/ubuntu/"
17 iso_label="${os_name}_${codename}_${arch}"
18 iso_publisher='Fascode Network <https://fascode.net>'
19 iso_application="${os_name} Live/Rescue CD"
20 iso_version="${codename}-$(date +%Y.%m.%d)"
21 iso_filename="${iso_name}-${iso_version}-${arch}.iso"
24 # Show an INFO message
28 echo -e "\033[0;36m[LUBS Core] \033[0;32mINFO:\033[0;39m ${_msg}"
31 # Show an ERROR message then exit with status
32 # _msg_error <message> <exit code>
36 echo -e "\033[0;36m[LUBS Core] \033[0;31mERROR:\033[0;39m ${_msg}" >&2
37 if [[ ! ${_error} = 0 ]]; then
43 # Helper function to run make_*() only one time.
45 if [[ ! -e "${work_dir}/build.${1}" ]]; then
47 touch "${work_dir}/build.${1}"
53 "${script_path}/lubs-chroot" "${work_dir}/airootfs" ${@}
57 run_cmd apt-get --yes install ${@}
64 if [[ ${EUID} -ne 0 ]]; then
65 _msg_error "This script must be run as root." 1
68 [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
71 for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir}) | sort -r); do
72 _msg_info "Unmounting ${mount}"
80 if [[ ! -d "${cache_dir}/${codename}" ]]; then
81 _msg_info "Installing Ubuntu to '${cache_dir}/${codename}'..."
82 mkdir -p "${cache_dir}/${codename}"
83 debootstrap --arch=${arch} --include=linux-image-generic --verbose --merged-usr "${codename}" "${cache_dir}/${codename}" ${mirror}
84 _msg_info "${codename} installed successfully!"
87 rm -rf "${work_dir}/airootfs" && mkdir -p "${work_dir}/airootfs"
88 _msg_info "copy base files from '${cache_dir}/${codename}' to '${work_dir}/airootfs'..."
89 rsync -au "${cache_dir}/${codename}/" "${work_dir}/airootfs"
90 echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' >> "${work_dir}/airootfs/etc/bash.bashrc"
91 run_cmd apt-get update
92 # run_cmd apt-get upgrade
93 _msg_info "make basefs done!"
97 cp ${script_path}/source.list.d/${codename}/* ${work_dir}/airootfs/etc/apt
101 run_cmd apt-get install --yes systemd-sysv
102 run_cmd dbus-uuidgen > /etc/machine-id
103 run_cmd ln -fs /etc/machine-id /var/lib/dbus/machine-id
107 run_cmd apt-get update
108 installpkglist=($(grep -h -v ^'#' ${script_path}/packages.x86_64))
109 run_cmd sudo -i apt-get --yes install ${installpkglist[@]}
114 run_cmd LANG=en_US.UTF-8 LC_ALL=C LANGUAGE=en_US.UTF-8 dpkg-reconfigure -f noninteractive locales
117 run_cmd dpkg-reconfigure dpkg-reconfigure localesresolvconf
120 run_cmd echo -e "[main]\nrc-manager=resolvconf\nplugins=ifupdown,keyfile\n\ndns=dnsmasq\n[ifupdown]\nmanaged=false" > /etc/NetworkManager/NetworkManager.conf
123 #run_cmd echo -ne "UTC" > '/etc/timezone'
124 #run_cmd dpkg-reconfigure -f noninteractive tzdata
126 run_cmd dpkg-reconfigure -f noninteractive dpkg-reconfigure locales network-manager
127 run_cmd truncate -s 0 /etc/machine-id
130 make_customize_airootfs() {
131 # Overwrite airootfs with customize_airootfs.
132 cp -af "${script_path}/airootfs" "${work_dir}"
134 if [[ -f "${work_dir}/airootfs/root/customize_airootfs.sh" ]]; then
135 chmod 755 "${work_dir}/airootfs/root/customize_airootfs.sh"
136 run_cmd "/root/customize_airootfs.sh"
141 run_cmd apt-get clean
142 run_cmd apt-get --yes autoremove
143 run_cmd rm -rf "/tmp/* ~/.bash_history"
147 run_cmd update-initramfs -c -k all
148 run_cmd apt-get install --yes memtest86+
149 mkdir -p out/{casper,isolinux,install}
150 cp ${work_dir}/airootfs/boot/vmlinuz-*-*-generic out/casper/vmlinuz
151 cp ${work_dir}/airootfs/boot/initrd.img-*-*-generic out/casper/initrd
152 cp ${work_dir}/airootfs/boot/memtest86+.bin out/install/memtest86+
153 wget -O out/install/memtest86-usb.zip https://www.memtest86.com/downloads/memtest86-usb.zip
154 zip -r out/install/memtest86-usb.zip memtest86-usb.img out/install/memtest86
155 rm -f out/install/memtest86-usb.zip
160 cat <<EOF > out/isolinux/grub.cfg
162 search --set=root --file /ubuntu
169 menuentry "Try Ubuntu FS without installing" {
170 linux /casper/vmlinuz boot=casper quiet splash ---
171 initrd /casper/initrd
174 menuentry "Install Ubuntu FS" {
175 linux /casper/vmlinuz boot=casper only-ubiquity quiet splash ---
176 initrd /casper/initrd
179 menuentry "Check disc for defects" {
180 linux /casper/vmlinuz boot=casper integrity-check quiet splash ---
181 initrd /casper/initrd
184 menuentry "Test memory Memtest86+ (BIOS)" {
185 linux16 /install/memtest86+
188 menuentry "Test memory Memtest86 (UEFI, long load time)" {
190 insmod search_fs_uuid
192 loopback loop /install/memtest86
193 chainloader (loop,gpt1)/efi/boot/BOOTX64.efi
199 run_cmd dpkg-query -W --showformat='${Package} ${Version}\n' | tee out/casper/filesystem.manifest
200 cp -v out/casper/filesystem.manifest "out/casper/filesystem.manifest-desktop"
201 sed -i '/ubiquity/d' "out/casper/filesystem.manifest-desktop"
202 sed -i '/casper/d' "out/casper/filesystem.manifest-desktop"
203 sed -i '/discover/d' "out/casper/filesystem.manifest-desktop"
204 sed -i '/laptop-detect/d' "out/casper/filesystem.manifest-desktop"
205 sed -i '/os-prober/d' "out/casper/filesystem.manifest-desktop"
209 mksquashfs "${work_dir}/airootfs" "out/casper/filesystem.squashfs"
210 printf $(du -sx --block-size=1 "${work_dir}/airootfs" | cut -f1) > out/casper/filesystem.size
214 cat <<EOF > out/README.diskdefines
215 #define DISKNAME Ubuntu from scratch
230 --format=x86_64-efi \
231 --output=isolinux/bootx64.efi \
234 "boot/grub/grub.cfg=isolinux/grub.cfg"
237 dd if=/dev/zero of=efiboot.img bs=1M count=10 && \
238 sudo mkfs.vfat efiboot.img && \
239 LC_CTYPE=C mmd -i efiboot.img efi efi/boot && \
240 LC_CTYPE=C mcopy -i efiboot.img ./bootx64.efi ::efi/boot/
244 --output=isolinux/core.img \
245 --install-modules="linux16 linux normal iso9660 biosdisk memdisk search tar ls" \
246 --modules="linux16 linux normal iso9660 biosdisk search" \
249 "boot/grub/grub.cfg=isolinux/grub.cfg"
250 cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img > isolinux/bios.img
256 /bin/bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)"
265 -full-iso9660-filenames \
266 -volid "${iso_label}" \
267 -appid "${iso_application}" \
268 -publisher "${iso_publisher}" \
269 -preparer "prepared by LUBS" \
270 -eltorito-boot boot/grub/bios.img \
274 --eltorito-catalog boot/grub/boot.cat \
276 --grub2-mbr /usr/lib/grub/i386-pc/boot_hybrid.img \
280 -append_partition 2 0xef isolinux/efiboot.img \
281 -output "../${iso_filename}" \
284 /boot/grub/bios.img=isolinux/bios.img \
285 /EFI/efiboot.img=isolinux/efiboot.img
291 run_once make_sourcelist
292 run_once make_systemd
293 run_once make_packages
295 run_once make_customize_airootfs
297 run_once make_bootfiles
298 run_once make_grubcfg
299 run_once make_manifest
300 run_once make_squashfs
301 run_once make_deifnes
302 run_once make_isolinux