@zhongdao
2019-10-01T12:55:13.000000Z
字数 20868
阅读 2627
未分类
两个实现方案
A. 将tms整合到ubuntu里,制作一个自己的发布盘和安装盘。
B. 自己安装ubuntu, 另外再通过安装包安装tms。
优先实现方法A. 这里面也分2种,一种是利用现有工具,一种是按照ubuntu官方的定义,自己写脚本,编辑配置文件,定制安装盘。
现状:
tms是通过母盘复制的。
tms本身是shell脚本安装到ubuntu里的。
支持系统: ubuntu 16.04
tms的实际安装情况:
需要安装java sdk;需要安装usbkey驱动;需要安装tms的java程序; 需要修改配置文件。自动挂载xT硬盘(系统分区时已经解决)。
以上这些步骤都可以通过shell命令自动完成。usbkey安装需要联网。
BFT的安装情况:
联网,shell脚本自动安装
巴克的安装情况:
联网,安装依赖库,安装软件。
需要调研:
是否需要制作deb安装包,才能制作下一步的ubuntu安装盘。
需要的话,就先把tms的deb制作好。
不需要的话,就只需要把相关文件通过shell脚本执行,并在ubuntu的安装盘安装过程中复制到系统既定位置,但是前提是对ubuntu的安装规范及其了解并且可以定制它。
systemback 在vmware上测试通过,据反映,有些只有uefi的新硬件无法启动,为了支持uefi启动,需要将efi的启动分区加入,步骤见下面第3章的systemback部分。
自己通过脚本定制安装内容,在安装BFT的情况下,vmware测试通过。
为了制作完整的tms母盘,需要将tms进行安装并测试其可用性。
大家各自有自己工作任务,时间不充沛,需要大量公司内部沟通,这事要有一个人负责和主导。
这个人要熟悉 tms的母盘安装和验证,了解各种硬件,跟研发有充分沟通。
在vmware上验证通过的安装盘定制方法,需要此人进一步在不同实际硬件上,TMS的各类软件硬件功能上进行仔细而认真的验证。
https://www.maketecheasier.com/6-tools-to-easily-create-your-own-custom-linux-distro/
https://askubuntu.com/questions/832425/how-to-make-iso-of-current-installation-using-respin
定制Ubuntu安装CD
https://wiki.ubuntu.org.cn/%E5%AE%9A%E5%88%B6Ubuntu%E5%AE%89%E8%A3%85CD
LiveCDCustomization
https://help.ubuntu.com/community/LiveCDCustomization
根据这些文章,一类是根据原理定制安装盘,一类是通过工具来生成iso,
其中live cd 不一定具有安装功能,是一个cd上的ubuntu系统。
使用Systemback构造属于自己的Ubuntu镜像(详解
https://blog.csdn.net/qq_39591494/article/details/88674694
通过systemback制作系统镜像以及镜像安装,实现系统备份和复刻
https://blog.csdn.net/qq_41248872/article/details/86659074
将自己的 ubuntu 系统制作为ISO镜像
https://blog.csdn.net/qq_34638161/article/details/81282354
自定义Ubuntu镜像iso文件
https://blog.csdn.net/u011249920/article/details/82260026
How do I create an EFI-bootable ISO of a customized version of Ubuntu?
https://askubuntu.com/questions/457528/how-do-i-create-an-efi-bootable-iso-of-a-customized-version-of-ubuntu
How to create UEFI-only bootable USB live media?
https://askubuntu.com/questions/395879/how-to-create-uefi-only-bootable-usb-live-media
ubuntu上的uefi说明
https://help.ubuntu.com/community/UEFI
Instructions to make a boot drive, that boots both in UEFI and BIOS mode
https://help.ubuntu.com/community/Installation/iso2usb/diy
先下载
wget 47.92.93.51/grub-do-it-yourself.img.xz
wget 47.92.93.51/grub-do-it-yourself.img.xz.md5.asc
gpg --keyserver keyserver.ubuntu.com --recv-keys EB0FC2C8
gpg --verify grub-do-it-yourself.img.xz.md5.asc
md5sum -c grub-do-it-yourself.img.xz.md5.asc
wget 47.92.93.51/ubuntu-16.04.6-desktop-amd64.iso
sudo mkdir -p /mnt/lp1
sudo mount -o loop ubuntu-16.04.1-desktop-amd64.iso /mnt/lp1
检测当前系统是bios还是uefi
test -d /sys/firmware/efi && echo efi || echo bios
A. 安装
sudo add-apt-repository ppa:nemh/systemback
sudo apt-get update && sudo apt-get install systemback unionfs-fuse
sudo apt-get install live-boot -y
sudo apt-get autoremove --purge casper
B. 通过systemback制作live system,然后制作为 systemback.iso
C. 添加uefi分区到 iso ( efi.img 来自 安装盘 extract-cd/boot/grub/efi.img)
cd /home
cat `ls -1 -t syst*.iso|head -1` efi.img >/tmp/live.iso
echo -e "n\np\n2\n\n\nt\n2\nef\nw\n"|fdisk /tmp/live.iso
D. 制作到u盘上。通过netbootin软件或者dd命令。
pv /tmp/live.iso | dd of=/dev/sdb conv=notrunc,noerror
https://github.com/Distroshare/distroshare-ubuntu-imager
其工作原理为:
https://help.ubuntu.com/community/MakeALiveCD/DVD/BootableFlashFromHarddiskInstall
apt install xorriso -y
git clone https://github.com/Distroshare/distroshare-ubuntu-imager
cd distroshare-ubuntu-imager/
./distroshare-ubuntu-imager.sh
可以制作成功,但是没有安装选项。
https://sourceforge.net/projects/uck/
http://www.linuxrespin.org/create-your-distro/
https://launchpad.net/~sergiomejia666/+archive/ubuntu/respin
安装
sudo add-apt-repository ppa:sergiomejia666/respin
sudo add-apt-repository ppa:sergiomejia666/xresprobe
sudo apt-get update
sudo apt-get install respin isolinux
# 可安装程序。
apt-get install ubiquity ubiquity-frontend-gtk
制作:
sudo respin dist cdfs
sudo respin dist iso cutstom.iso
这样安装完后,iso可以启动可install, 但是安装一半时 install crash.
https://www.techrepublic.com/article/how-to-create-a-custom-ubuntu-iso-with-cubic/
https://askubuntu.com/questions/741753/how-to-use-cubic-to-create-a-custom-ubuntu-live-cd-image
https://www.linux.com/tutorials/roll-your-own-customized-ubuntu-uck/
百度: 定制 ubuntu安装盘制作
定制Ubuntu安装CD
https://wiki.ubuntu.org.cn/%E5%AE%9A%E5%88%B6Ubuntu%E5%AE%89%E8%A3%85CD
定制 Ubuntu 安装盘 X
https://blog.csdn.net/wang_xya/article/details/43451703
如何将我当前的Ubuntu系统封装成为可以安装的iso镜像?(respin)
https://www.zhihu.com/question/48701784
将当前的Ubuntu系统封装成为可以安装(发布)的iso镜像 (remastersys)
https://blog.51cto.com/solin/1865855
Roll Your Own Customized Ubuntu With UCK
https://www.linux.com/tutorials/roll-your-own-customized-ubuntu-uck/
remastersys
https://en.wikipedia.org/wiki/Remastersys
LinuxRespin
http://www.linuxrespin.org/
https://gitlab.com/remastersys/LinuxRespin
How to make .iso of current installation using Respin?
https://askubuntu.com/questions/832425/how-to-make-iso-of-current-installation-using-respin
Alternatives to Linux Respin for all platforms
https://alternativeto.net/software/linux-respin/
Build my own Ubuntu ISO (respin)
https://askubuntu.com/questions/829652/build-my-own-ubuntu-iso
todo:
DerivativeDistroHowto
https://wiki.ubuntu.com/DerivativeDistroHowto
Create a Linux Distribution Based on Ubuntu
https://fosspost.org/tutorials/create-linux-distribution-based-on-ubuntu
8 Tools to Easily Create Your Own Custom Linux Distro
https://www.maketecheasier.com/6-tools-to-easily-create-your-own-custom-linux-distro/
How To Create A Custom Ubuntu Distribution With Distroshare Ubuntu Imager
https://www.addictivetips.com/ubuntu-linux-tips/create-custom-ubuntu-distribution-distroshare-ubuntu-imager/
How to create a custom Ubuntu ISO with Cubic
https://www.techrepublic.com/article/how-to-create-a-custom-ubuntu-iso-with-cubic/
What is the simplest Debian Packaging Guide?
https://askubuntu.com/questions/1345/what-is-the-simplest-debian-packaging-guide
ubuntu packaging guide
http://packaging.ubuntu.com/html/packaging-new-software.html
Easy way to create a Debian package and local package repository
https://linuxconfig.org/easy-way-to-create-a-debian-package-and-local-package-repository
Building a very simple debian package
https://tribaal.io/very-simple-debian-package.html
HOWTO: Build debian packages for simple shell scripts
https://blog.packagecloud.io/eng/2016/12/15/howto-build-debian-package-containing-simple-shell-scripts/
https://blog.packagecloud.io/eng/2015/04/13/working-with-deb-ubuntu-source-packages/
sudo su -c "grep '^deb ' /etc/apt/sources.list" | sed 's/^deb/deb-src/g' > /etc/apt/sources.list.d/deb-src.list
apt update
sudo apt install dpkg-dev
sudo apt-get source ctorrent
vi btconfig.h 修改meta文件大小限制以便支持超大文件传输.
原代码不能支持比较大的原文件(不能支持单文件大于200G左右, 具体下限不确定),其中一个原因是生成的metainfofile: ctorrent文件过大,程序认为不合理。所以将限制改大即可。
#define MAX_METAINFO_FILESIZ (48*1024*1024)
slice
piece length
size_t arg_piece_length = 4193300
具体的diff如下:
diff ctorrent-1.3.4.dnh3.3.2/btconfig.cpp ctorrent-1.3.4.dnh3.3.2-large/btconfig.cpp
41c41
< size_t arg_piece_length = 262144;
---
> size_t arg_piece_length = 4193300;
diff ctorrent-1.3.4.dnh3.3.2/btconfig.h ctorrent-1.3.4.dnh3.3.2-large/btconfig.h
8,9c8,9
< #define MAX_METAINFO_FILESIZ (4*1024*1024)
< #define DEFAULT_SLICE_SIZE (16*1024)
---
> #define MAX_METAINFO_FILESIZ (64*1024*1024)
> #define DEFAULT_SLICE_SIZE (128*1024)
为了区分执行程序的版本,修改了帮助usage的输出
diff ctorrent-1.3.4.dnh3.3.2/ctorrent.cpp ctorrent-1.3.4.dnh3.3.2-large/ctorrent.cpp
445c445
< fprintf(stderr,"ctorrent -s new_filename -e 12 -C 32 -p 6881 example.torrent\n");
---
> fprintf(stderr,"ctorrent -s new_file -e 12 -C 32 -p 6881 example.torrent\n");
lijun@ctserver:~/diff$ diff -u ctorrent-1.3.4.dnh3.3.2/btconfig.h ctorrent-1.3.4.dnh3.3.2-large/btconfig.h
--- ctorrent-1.3.4.dnh3.3.2/btconfig.h 2009-07-15 20:17:07.000000000 +0800
+++ ctorrent-1.3.4.dnh3.3.2-large/btconfig.h 2018-01-25 18:19:15.000000000 +0800
@@ -5,8 +5,8 @@
extern size_t cfg_req_slice_size;
-#define MAX_METAINFO_FILESIZ (4*1024*1024)
-#define DEFAULT_SLICE_SIZE (16*1024)
+#define MAX_METAINFO_FILESIZ (64*1024*1024)
+#define DEFAULT_SLICE_SIZE (128*1024)
// According to specs the max slice size is 128K. While most clients now do
// not accept a value that large, we want max compatibility.
#define cfg_max_slice_size (128*1024)
lijun@ctserver:~/diff$ diff -u ctorrent-1.3.4.dnh3.3.2/btconfig.cpp ctorrent-1.3.4.dnh3.3.2-large/btconfig.cpp
--- ctorrent-1.3.4.dnh3.3.2/btconfig.cpp 2009-07-15 20:17:07.000000000 +0800
+++ ctorrent-1.3.4.dnh3.3.2-large/btconfig.cpp 2018-01-25 18:19:15.000000000 +0800
@@ -38,7 +38,7 @@
unsigned char arg_allocate = 0;
unsigned char arg_daemon = 0;
-size_t arg_piece_length = 262144;
+size_t arg_piece_length = 4193300;
char *arg_announce = (char*) 0;
char *arg_comment = (char*) 0;
lijun@ctserver:~/diff$ diff -u ctorrent-1.3.4.dnh3.3.2/ctorrent.cpp ctorrent-1.3.4.dnh3.3.2-large/ctorrent.cpp
--- ctorrent-1.3.4.dnh3.3.2/ctorrent.cpp 2009-07-15 20:17:07.000000000 +0800
+++ ctorrent-1.3.4.dnh3.3.2-large/ctorrent.cpp 2018-01-25 18:32:11.000000000 +0800
@@ -442,7 +442,7 @@
fprintf(stderr, "%-15s %s\n", "-c comment", "Include a comment/description");
fprintf(stderr,"\nExample:\n");
- fprintf(stderr,"ctorrent -s new_filename -e 12 -C 32 -p 6881 example.torrent\n");
+ fprintf(stderr,"ctorrent -s new_file -e 12 -C 32 -p 6881 example.torrent\n");
fprintf(stderr,"\nhome page: http://ctorrent.sourceforge.net/\n");
fprintf(stderr,"see also: http://www.rahul.net/dholmes/ctorrent/\n");
fprintf(stderr,"bug report: %s\n",PACKAGE_BUGREPORT);
对ubuntu的源文件进行patch
# diff -u 目录_apt source 下来的; 目录_修改过的支持大文件的
lijun@ctserver:~$ diff -u tmp/ctorrent-1.3.4.dnh3.3.2/btconfig.cpp ctorrent-1.3.4.dnh3.3.2/btconfig.cpp > btconfig.cpp.patch
lijun@ctserver:~$ diff -u tmp/ctorrent-1.3.4.dnh3.3.2/btconfig.h ctorrent-1.3.4.dnh3.3.2/btconfig.h > btconfig.h.patch
lijun@ctserver:~$ diff -u tmp/ctorrent-1.3.4.dnh3.3.2/ctorrent.cpp ctorrent-1.3.4.dnh3.3.2/ctorrent.cpp > ctorrent.cpp.patch
# cd sourcedir need to patch
cp *.patch tmp/ctorrent-1.3.4.dnh3.3.2/
cd tmp/ctorrent-1.3.4.dnh3.3.2/
patch < btconfig.cpp.patch
patch < btconfig.h.patch
patch < ctorrent.cpp.patch
源站修改过的源码:
wget http://39.106.122.67/ctorrent/ctorrent-1.3.4.dnh3.3.2.largefile.tgz
ubuntu版的修改过的源码:
wget http://39.106.122.67/ctorrent/ctorrent-1.3.4.dnh3.3.2.ubuntu.largefile.src.tgz
重新编译后的ubuntu安装包:
64bit系统:
wget http://39.106.122.67/ctorrent/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb
32bit系统:
wget http://39.106.122.67/ctorrent/ctorrent_1.3.4.dnh3.3.2-4_i386.deb
sudo dpkg -i ctorrent_1.3.4.dnh3.3.2-4_amd64.deb
sudo dpkg -i ctorrent_1.3.4.dnh3.3.2-4_i386.deb
How to Customize an Ubuntu Installation Disc – The Right Way (16.04 Compatible!)
https://nathanpfry.com/how-to-customize-an-ubuntu-installation-disc/
里面有链接,附有script脚本下载。
https://pastebin.com/NQUTWC1y
Install CD Customization
https://help.ubuntu.com/community/InstallCDCustomization
InstallCDCustomization 安装/定制(中英对照翻译) https://www.zybuluo.com/zhongdao/note/1548285
How to create custom Ubuntu install with packages, system settings, defaults?
use the ubuntu preseed for that.
In ubuntu iso you can find it under preseed/ubuntu.seed
Automating the installation using preseeding
https://help.ubuntu.com/lts/installation-guide/i386/apb.html
Guide to particulars in customizing Ubuntu Installer
https://askubuntu.com/questions/29121/guide-to-particulars-in-customizing-ubuntu-installer?rq=1
For a reference preseed, you might like to refer to installation-guide-i386 which contains the following sample preseed:
/usr/share/doc/installation-guide-i386/example-preseed.txt.gz
- Completely rewrite the packages installed by default, much like minimal installs
- Add a few proprietary applications to the default install list
To provide the list of packages you want installed, you might like to look for the following line:
tasksel tasksel/first multiselect ubuntu-desktop
Where "ubuntu-desktop" can be changed for an arbitrary number of packages or meta packages.
- Automatically install and mount proprietary drivers on install and live session
Other that specifying the packages needed (for the proprietary drivers), I'm not sure how this would be accomplished. As a side note, you "mount" a partition, you "load" a kernel module/driver.
- Edit the default configuration files for applications installed by default
To make those kind of scripted changes, you probably want to look into:
d-i preseed/late_command string ...
Where the "..." can be replaced with arbitrary commands like sed -i for example.
- Specify partitions along with permission
There's a partition section in the example preseed mentioned above.
Ubiquity with preseed
Casper supports preseed and ubiquity can have many values preseeded. Here are some of the variables that can be preseeded relevant to ubiquity:
ubiquity countrychooser/shortlist select US
ubiquity languagechooser/language-name select English
ubiquity localechooser/supported-locales multiselect en_US.UTF-8
ubiquity ubiquity/summary note
ubiquity ubiquity/reboot boolean true
ubiquity ubiquity/poweroff boolean true
ubiquity ubiquity/success_command string ...
Where "..." would contain the same as the late_command mentioned above, success_command is read by ubiquity and late_command by d-i.
参考:
https://askubuntu.com/questions/409607/how-to-create-a-customized-ubuntu-server-iso/409651#409651
系统上可以参考的preseed文件示例。
/usr/share/doc/installation-guide-i386/example-preseed.txt.gz
下载 ubuntu 16.04 iso, 然后修改路径和名称, 执行 customcd.sh
其中可以修改自定义安装的package.
具体是在准备阶段,将deb复制过去。 在chroot的安装阶段进行deb的安装。
下面是个实例,是ctorrent的安装。
# Prepare and chroot
sudo cp /etc/resolv.conf edit/etc/
sudo cp /root/soft/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb edit/tmp/ # add here.
sudo cp /root/install-bft.sh edit/tmp/
....
apt-get install google-chrome-stable yubikey-luks -y
dpkg -i /tmp/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb # add here.
/tmp/install-bft.sh
chmod 755 /etc/rc.local
apt-get autoremove -y
apt-get autoclean -y
最后形成一个 install iso, 可以用于安装。
为了修改preseed文件, 也可以将shell脚本分成2步来执行,
c1.sh; 完成准备, 然后修改preseed脚本。
c2.sh; 形成chroot,然后安装定制pkg, 最后形成iso.
从这里下载:
https://pan.baidu.com/s/1SbzUHxDurGG5qNRk3DZN_Q
为了了解定制细节,可以参考相关网址:
Install CD Customization
https://help.ubuntu.com/community/InstallCDCustomization
How to create custom Ubuntu install with packages, system settings, defaults?
use the ubuntu preseed for that.
In ubuntu iso you can find it under preseed/ubuntu.seed
Automating the installation using preseeding
https://help.ubuntu.com/lts/installation-guide/i386/apb.html
How to Customize an Ubuntu Installation Disc – The Right Way (16.04 Compatible!)
https://nathanpfry.com/how-to-customize-an-ubuntu-installation-disc/
https://gitlab.com/morph027/custom-live-ubuntu-cinnamon
InstallCDCustomization 安装/定制(中英对照) - 作业部落 Cmd Markdown 编辑阅读器 https://www.zybuluo.com/zhongdao/note/1548285
livecd定制(中英对照翻译) - 作业部落 Cmd Markdown 编辑阅读器 https://www.zybuluo.com/zhongdao/note/1612551
#!/bin/bash
# 2017-July-04 - having difficulties building a custom Live CD that boots from a USB stick
#
# Tried https://nathanpfry.com/how-to-customize-an-ubuntu-installation-disc/, but no joy.
#
# So, reverting to 'base' documentation, I attempted a
# Simple extraction/decompression/re-manifest/compress/make iso image
# based on https://help.ubuntu.com/community/LiveCDCustomization
#
# Could NOT get this to work using genisoimage, even with adaptations from
# https://askubuntu.com/questions/457528/how-do-i-create-an-efi-bootable-iso-of-a-customized-version-of-ubuntu which
# pointed me toward "-eltorito-alt-boot and -e boot/grub/efi.img -no-emul-boot"
#
# 2017-July-05 - success, but only with xorriso
#
# Eventually, Google pointed me to yet another tool to install, xorriso, thanks to
# https://linuxconfig.org/legacy-bios-uefi-and-secureboot-ready-ubuntu-live-image-customization
#
# It works. If anyone cares to propose updates to the script that do not require the 'dd' of isohdpfx.bin
# and still result in a USB-stick-bootable .iso using genisoimage, I would be pleased to drop xorriso.
# Assumptions:
# 0. I need this to work for ubuntu 16.04. I don't care about earlier releases, or necessarily later ones (TODO)
# 1. Host is a fully-patched Ubuntu 16.04.2 server. (I tried a VM, but no loop device)
# 2. I have downloaded "ubuntu-mate-16.04.2-desktop-amd64.iso" using wget
# This script sits at ~/.
# e.g. wget http://mirrors.aliyun.com/ubuntu-releases/16.04/ubuntu-16.04.6-desktop-amd64.iso
# Always good to check http://releases.ubuntu.com/
CDIMAGENAME='ubuntu-16.04.6-desktop-amd64.iso'
IMAGE_NAME='Custom1604'
echo "Copying $CDIMAGENAME to working directory..."
cd ~/.
mkdir custom-img
cp $CDIMAGENAME custom-img
cd custom-img
# Extract the CD .iso contents
#Mount the .iso to a local mount point. 'loop' is a read-only device, so mount will
# warn that it is mounting it read-only. You can use "-o loop,ro" to avoid that warning, if you like.
mkdir mnt
echo "Mounting the .iso as 'mnt' in the local directory. Password-up, please."
sudo mount -o loop $CDIMAGENAME mnt
#Extract the .iso contents into dir 'extract-cd'
mkdir extract-cd
sudo rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
#Extract the isohybrid MBR 'isohdpfx.bin' from the source ISO image using dd
sudo dd if=$CDIMAGENAME bs=512 count=1 of=extract-cd/isolinux/isohdpfx.bin
# Extract the Desktop system
#Extract the SquashFS filesystem
sudo unsquashfs mnt/casper/filesystem.squashfs
sudo mv squashfs-root edit
#We are finished with the source .iso image. Unmount it.
sudo umount mnt
#Delete the source .iso copy.
rm $CDIMAGENAME
# add here. 修改安装过程中是否定制分区
# echo "d-i partman-auto/init_automatically_partition select custom" >> ~/custom-image/extract-cd/preseed/cli.seed
# Prepare and chroot
sudo cp /etc/resolv.conf edit/etc/
# sudo cp /root/soft/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb edit/tmp/ # add here.
sudo cp /root/install-bft.sh edit/tmp/
sudo cp -rf /usr/tms edit/usr/
sudo mount --bind /dev/ edit/dev
# Learned this inline scripting from https://askubuntu.com/questions/551195/scripting-chroot-how-to
cat << EOF | sudo chroot edit
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts
# "To avoid locale issues and in order to import GPG keys..."
export HOME=/root
export LC_ALL=C
dbus-uuidgen > /var/lib/dbus/machine-id
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
#Customizations
# Add Google Chrome's stable repository to apt (hey, I like Chrome)
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
#Update and Upgrade (distributions)
apt-get update
apt-get purge thunderbird -y
apt-get dist-upgrade -y
apt-get install google-chrome-stable yubikey-luks -y
#dpkg -i /tmp/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb # add here.
/tmp/install-bft.sh
apt-get autoremove -y
apt-get autoclean -y
#Clean up
rm -rf /tmp/* ~/.bash_history
rm /var/lib/dbus/machine-id
rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl
# "now umount (unmount) special filesystems and exit chroot"
umount /proc || umount -lf /proc
umount /sys
umount /dev/pts
EOF
sudo umount edit/dev
echo "Regenerate the manifest"
#Regenerate the manifest
sudo chmod +w extract-cd/casper/filesystem.manifest
sudo chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee extract-cd/casper/filesystem.manifest
sudo cp extract-cd/casper/filesystem.manifest extract-cd/casper/filesystem.manifest-desktop
sudo sed -i '/ubiquity/d' extract-cd/casper/filesystem.manifest-desktop
sudo sed -i '/casper/d' extract-cd/casper/filesystem.manifest-desktop
#Compress the filesystem
# Delete any existing squashfs - normally nothing to delete/rm.
sudo rm extract-cd/casper/filesystem.squashfs
sudo mksquashfs edit extract-cd/casper/filesystem.squashfs -b 1048576
#"Update the filesystem.size file, which is needed by the installer"
printf $(sudo du -sx --block-size=1 edit | cut -f1) | sudo tee extract-cd/casper/filesystem.size
#"Remove old md5sum.txt and calculate new md5 sums"
cd extract-cd
sudo rm md5sum.txt
find -type f -print0 | sudo xargs -0 md5sum | grep -v isolinux/boot.cat | sudo tee md5sum.txt
#"Create the ISO image"
#manpage for genisoimage http://manpages.ubuntu.com/manpages/trusty/man1/genisoimage.1.html
#original
#sudo genisoimage -D -r -V "$IMAGE_NAME" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../$IMAGE_NAME.iso .
#from EFI Q&A: https://askubuntu.com/questions/457528/how-do-i-create-an-efi-bootable-iso-of-a-customized-version-of-ubuntu
#sudo mkisofs -U -A "Custom1604" -V "Custom1604" -volset "Custom1604" -J -joliet-long -r -v -T -o ../Custom1604.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot .
# From https://linuxconfig.org/legacy-bios-uefi-and-secureboot-ready-ubuntu-live-image-customization
# THIS WORKS for creating a .iso that can boot a PC from USB after dd to the USB drive, and as a file referenced as the boot image for a VM (e.g. VirtualBox)
sudo xorriso -as mkisofs -isohybrid-mbr isolinux/isohdpfx.bin -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -o ../$IMAGE_NAME.iso .
# Not necessary, but you can check that a bootable partition is visible to fdisk.
# If no bootable partiction is visible to fdisk, my experience is that the ISO will not boot from USB.
# If so, we should be good to go.
sudo fdisk -lu ../$IMAGE_NAME.iso