[关闭]
@zhongdao 2019-10-01T12:55:13.000000Z 字数 20868 阅读 2627

定制ubuntu16.04安装盘的需求与相关资料

未分类


1. 需求

两个实现方案
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的安装规范及其了解并且可以定制它。

2. 目前测试情况

已经试验成功的方法

systemback 在vmware上测试通过,据反映,有些只有uefi的新硬件无法启动,为了支持uefi启动,需要将efi的启动分区加入,步骤见下面第3章的systemback部分。

自己通过脚本定制安装内容,在安装BFT的情况下,vmware测试通过。
为了制作完整的tms母盘,需要将tms进行安装并测试其可用性。

人员需求

大家各自有自己工作任务,时间不充沛,需要大量公司内部沟通,这事要有一个人负责和主导。
这个人要熟悉 tms的母盘安装和验证,了解各种硬件,跟研发有充分沟通。
在vmware上验证通过的安装盘定制方法,需要此人进一步在不同实际硬件上,TMS的各类软件硬件功能上进行仔细而认真的验证。

3. 制作定制的ubuntu分发版资料分类

需要看的重点文章

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#.E4.BF.AE.E6.94.B9pool.E7.9B.AE.E5.BD.95.EF.BC.8C.E5.A2.9E.E5.8A.A0.E6.88.96.E5.88.A0.E9.99.A4.E8.BD.AF.E4.BB.B6.E5.8C.85

定制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

使用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

先下载

  1. wget 47.92.93.51/grub-do-it-yourself.img.xz
  2. wget 47.92.93.51/grub-do-it-yourself.img.xz.md5.asc
  3. gpg --keyserver keyserver.ubuntu.com --recv-keys EB0FC2C8
  4. gpg --verify grub-do-it-yourself.img.xz.md5.asc
  5. md5sum -c grub-do-it-yourself.img.xz.md5.asc
  6. wget 47.92.93.51/ubuntu-16.04.6-desktop-amd64.iso
  7. sudo mkdir -p /mnt/lp1
  8. sudo mount -o loop ubuntu-16.04.1-desktop-amd64.iso /mnt/lp1

检测当前系统是bios还是uefi

  1. test -d /sys/firmware/efi && echo efi || echo bios

A. 安装

  1. sudo add-apt-repository ppa:nemh/systemback
  2. sudo apt-get update && sudo apt-get install systemback unionfs-fuse
  3. sudo apt-get install live-boot -y
  4. sudo apt-get autoremove --purge casper

B. 通过systemback制作live system,然后制作为 systemback.iso
C. 添加uefi分区到 iso ( efi.img 来自 安装盘 extract-cd/boot/grub/efi.img)

  1. cd /home
  2. cat `ls -1 -t syst*.iso|head -1` efi.img >/tmp/live.iso
  3. echo -e "n\np\n2\n\n\nt\n2\nef\nw\n"|fdisk /tmp/live.iso

D. 制作到u盘上。通过netbootin软件或者dd命令。

  1. pv /tmp/live.iso | dd of=/dev/sdb conv=notrunc,noerror

Distroshare Ubuntu Imager 从已安装的Ubuntu或衍生分发中创建可安装的Live CD:

https://github.com/Distroshare/distroshare-ubuntu-imager
其工作原理为:
https://help.ubuntu.com/community/MakeALiveCD/DVD/BootableFlashFromHarddiskInstall

  1. apt install xorriso -y
  2. git clone https://github.com/Distroshare/distroshare-ubuntu-imager
  3. cd distroshare-ubuntu-imager/
  4. ./distroshare-ubuntu-imager.sh

可以制作成功,但是没有安装选项。

Ubuntu Customization Kit

https://sourceforge.net/projects/uck/

respin

http://www.linuxrespin.org/

http://www.linuxrespin.org/create-your-distro/

https://launchpad.net/~sergiomejia666/+archive/ubuntu/respin

安装

  1. sudo add-apt-repository ppa:sergiomejia666/respin
  2. sudo add-apt-repository ppa:sergiomejia666/xresprobe
  3. sudo apt-get update
  4. sudo apt-get install respin isolinux
  5. # 可安装程序。
  6. apt-get install ubiquity ubiquity-frontend-gtk

制作:

  1. sudo respin dist cdfs
  2. sudo respin dist iso cutstom.iso

这样安装完后,iso可以启动可install, 但是安装一半时 install crash.

Linux Live Kit

https://www.linux-live.org/

cubic

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

uck

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

https://www.google.com/search?ei=99ZsXfW9GsnG-gShoaawBQ&q=build+your+own+ubuntu+distro&oq=building+own+ubun&gs_l=psy-ab.1.1.0i22i30l10.210140.219892..244933...0.2..0.421.5742.2-23j0j1......0....1..gws-wiz.......0i71j35i39j0j0i131j0i3j0i22i10i30.iifhR8rV5ac

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/

4. 为ubuntu 制作新的deb安装包

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/

5. 从ubuntu源码库中下载修改并制作软件安装包

ubuntu 下下载源码并制作安装包

https://blog.packagecloud.io/eng/2015/04/13/working-with-deb-ubuntu-source-packages/

  1. 增加源代码的源
    /etc/apt/sources.list中添加了deb-src, 反注释掉deb下面的deb-src行
  1. sudo su -c "grep '^deb ' /etc/apt/sources.list" | sed 's/^deb/deb-src/g' > /etc/apt/sources.list.d/deb-src.list
  1. apt update
  1. 查看是否有源码
    sudo apt showsrc ctorrent
  2. 下载源码
  1. sudo apt install dpkg-dev
  2. sudo apt-get source ctorrent
  1. 下载依赖
    sudo apt build-dep ctorrent
  2. 进入源码目录 cd ctorrent-1.3.4.dnh3.3.2
  3. 修改源码
  4. 提交源码修改
    dpkg-source --commit
  5. 编译更新的代码
    sudo dpkg-buildpackage
  6. 回到父目录
    cd ..
  7. 安装 sudo dpkg -i ctorrent_1.3.4.dnh3.3.2-4_amd64.deb

源码中的torrent大小限制修改.

vi btconfig.h 修改meta文件大小限制以便支持超大文件传输.
原代码不能支持比较大的原文件(不能支持单文件大于200G左右, 具体下限不确定),其中一个原因是生成的metainfofile: ctorrent文件过大,程序认为不合理。所以将限制改大即可。

  1. #define MAX_METAINFO_FILESIZ (48*1024*1024)
  2. slice
  3. piece length
  4. size_t arg_piece_length = 4193300

具体的diff如下:

  1. diff ctorrent-1.3.4.dnh3.3.2/btconfig.cpp ctorrent-1.3.4.dnh3.3.2-large/btconfig.cpp
  2. 41c41
  3. < size_t arg_piece_length = 262144;
  4. ---
  5. > size_t arg_piece_length = 4193300;
  1. diff ctorrent-1.3.4.dnh3.3.2/btconfig.h ctorrent-1.3.4.dnh3.3.2-large/btconfig.h
  2. 8,9c8,9
  3. < #define MAX_METAINFO_FILESIZ (4*1024*1024)
  4. < #define DEFAULT_SLICE_SIZE (16*1024)
  5. ---
  6. > #define MAX_METAINFO_FILESIZ (64*1024*1024)
  7. > #define DEFAULT_SLICE_SIZE (128*1024)

为了区分执行程序的版本,修改了帮助usage的输出

  1. diff ctorrent-1.3.4.dnh3.3.2/ctorrent.cpp ctorrent-1.3.4.dnh3.3.2-large/ctorrent.cpp
  2. 445c445
  3. < fprintf(stderr,"ctorrent -s new_filename -e 12 -C 32 -p 6881 example.torrent\n");
  4. ---
  5. > fprintf(stderr,"ctorrent -s new_file -e 12 -C 32 -p 6881 example.torrent\n");

patch

  1. lijun@ctserver:~/diff$ diff -u ctorrent-1.3.4.dnh3.3.2/btconfig.h ctorrent-1.3.4.dnh3.3.2-large/btconfig.h
  2. --- ctorrent-1.3.4.dnh3.3.2/btconfig.h 2009-07-15 20:17:07.000000000 +0800
  3. +++ ctorrent-1.3.4.dnh3.3.2-large/btconfig.h 2018-01-25 18:19:15.000000000 +0800
  4. @@ -5,8 +5,8 @@
  5. extern size_t cfg_req_slice_size;
  6. -#define MAX_METAINFO_FILESIZ (4*1024*1024)
  7. -#define DEFAULT_SLICE_SIZE (16*1024)
  8. +#define MAX_METAINFO_FILESIZ (64*1024*1024)
  9. +#define DEFAULT_SLICE_SIZE (128*1024)
  10. // According to specs the max slice size is 128K. While most clients now do
  11. // not accept a value that large, we want max compatibility.
  12. #define cfg_max_slice_size (128*1024)
  13. lijun@ctserver:~/diff$ diff -u ctorrent-1.3.4.dnh3.3.2/btconfig.cpp ctorrent-1.3.4.dnh3.3.2-large/btconfig.cpp
  14. --- ctorrent-1.3.4.dnh3.3.2/btconfig.cpp 2009-07-15 20:17:07.000000000 +0800
  15. +++ ctorrent-1.3.4.dnh3.3.2-large/btconfig.cpp 2018-01-25 18:19:15.000000000 +0800
  16. @@ -38,7 +38,7 @@
  17. unsigned char arg_allocate = 0;
  18. unsigned char arg_daemon = 0;
  19. -size_t arg_piece_length = 262144;
  20. +size_t arg_piece_length = 4193300;
  21. char *arg_announce = (char*) 0;
  22. char *arg_comment = (char*) 0;
  23. lijun@ctserver:~/diff$ diff -u ctorrent-1.3.4.dnh3.3.2/ctorrent.cpp ctorrent-1.3.4.dnh3.3.2-large/ctorrent.cpp
  24. --- ctorrent-1.3.4.dnh3.3.2/ctorrent.cpp 2009-07-15 20:17:07.000000000 +0800
  25. +++ ctorrent-1.3.4.dnh3.3.2-large/ctorrent.cpp 2018-01-25 18:32:11.000000000 +0800
  26. @@ -442,7 +442,7 @@
  27. fprintf(stderr, "%-15s %s\n", "-c comment", "Include a comment/description");
  28. fprintf(stderr,"\nExample:\n");
  29. - fprintf(stderr,"ctorrent -s new_filename -e 12 -C 32 -p 6881 example.torrent\n");
  30. + fprintf(stderr,"ctorrent -s new_file -e 12 -C 32 -p 6881 example.torrent\n");
  31. fprintf(stderr,"\nhome page: http://ctorrent.sourceforge.net/\n");
  32. fprintf(stderr,"see also: http://www.rahul.net/dholmes/ctorrent/\n");
  33. fprintf(stderr,"bug report: %s\n",PACKAGE_BUGREPORT);

对ubuntu的源文件进行patch

  1. # diff -u 目录_apt source 下来的; 目录_修改过的支持大文件的
  2. 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
  3. 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
  4. 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
  5. # cd sourcedir need to patch
  6. cp *.patch tmp/ctorrent-1.3.4.dnh3.3.2/
  7. cd tmp/ctorrent-1.3.4.dnh3.3.2/
  8. patch < btconfig.cpp.patch
  9. patch < btconfig.h.patch
  10. 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

6. 通过脚本自定制安装cd

自己定制的资料

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:

  1. /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:

  1. 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:

  1. 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:

  1. ubiquity countrychooser/shortlist select US
  2. ubiquity languagechooser/language-name select English
  3. ubiquity localechooser/supported-locales multiselect en_US.UTF-8
  4. ubiquity ubiquity/summary note
  5. ubiquity ubiquity/reboot boolean true
  6. ubiquity ubiquity/poweroff boolean true
  7. 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的安装。

  1. # Prepare and chroot
  2. sudo cp /etc/resolv.conf edit/etc/
  3. sudo cp /root/soft/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb edit/tmp/ # add here.
  4. sudo cp /root/install-bft.sh edit/tmp/
  5. ....
  6. apt-get install google-chrome-stable yubikey-luks -y
  7. dpkg -i /tmp/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb # add here.
  8. /tmp/install-bft.sh
  9. chmod 755 /etc/rc.local
  10. apt-get autoremove -y
  11. 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

  1. #!/bin/bash
  2. # 2017-July-04 - having difficulties building a custom Live CD that boots from a USB stick
  3. #
  4. # Tried https://nathanpfry.com/how-to-customize-an-ubuntu-installation-disc/, but no joy.
  5. #
  6. # So, reverting to 'base' documentation, I attempted a
  7. # Simple extraction/decompression/re-manifest/compress/make iso image
  8. # based on https://help.ubuntu.com/community/LiveCDCustomization
  9. #
  10. # Could NOT get this to work using genisoimage, even with adaptations from
  11. # https://askubuntu.com/questions/457528/how-do-i-create-an-efi-bootable-iso-of-a-customized-version-of-ubuntu which
  12. # pointed me toward "-eltorito-alt-boot and -e boot/grub/efi.img -no-emul-boot"
  13. #
  14. # 2017-July-05 - success, but only with xorriso
  15. #
  16. # Eventually, Google pointed me to yet another tool to install, xorriso, thanks to
  17. # https://linuxconfig.org/legacy-bios-uefi-and-secureboot-ready-ubuntu-live-image-customization
  18. #
  19. # It works. If anyone cares to propose updates to the script that do not require the 'dd' of isohdpfx.bin
  20. # and still result in a USB-stick-bootable .iso using genisoimage, I would be pleased to drop xorriso.
  21. # Assumptions:
  22. # 0. I need this to work for ubuntu 16.04. I don't care about earlier releases, or necessarily later ones (TODO)
  23. # 1. Host is a fully-patched Ubuntu 16.04.2 server. (I tried a VM, but no loop device)
  24. # 2. I have downloaded "ubuntu-mate-16.04.2-desktop-amd64.iso" using wget
  25. # This script sits at ~/.
  26. # e.g. wget http://mirrors.aliyun.com/ubuntu-releases/16.04/ubuntu-16.04.6-desktop-amd64.iso
  27. # Always good to check http://releases.ubuntu.com/
  28. CDIMAGENAME='ubuntu-16.04.6-desktop-amd64.iso'
  29. IMAGE_NAME='Custom1604'
  30. echo "Copying $CDIMAGENAME to working directory..."
  31. cd ~/.
  32. mkdir custom-img
  33. cp $CDIMAGENAME custom-img
  34. cd custom-img
  35. # Extract the CD .iso contents
  36. #Mount the .iso to a local mount point. 'loop' is a read-only device, so mount will
  37. # warn that it is mounting it read-only. You can use "-o loop,ro" to avoid that warning, if you like.
  38. mkdir mnt
  39. echo "Mounting the .iso as 'mnt' in the local directory. Password-up, please."
  40. sudo mount -o loop $CDIMAGENAME mnt
  41. #Extract the .iso contents into dir 'extract-cd'
  42. mkdir extract-cd
  43. sudo rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
  44. #Extract the isohybrid MBR 'isohdpfx.bin' from the source ISO image using dd
  45. sudo dd if=$CDIMAGENAME bs=512 count=1 of=extract-cd/isolinux/isohdpfx.bin
  46. # Extract the Desktop system
  47. #Extract the SquashFS filesystem
  48. sudo unsquashfs mnt/casper/filesystem.squashfs
  49. sudo mv squashfs-root edit
  50. #We are finished with the source .iso image. Unmount it.
  51. sudo umount mnt
  52. #Delete the source .iso copy.
  53. rm $CDIMAGENAME
  54. # add here. 修改安装过程中是否定制分区
  55. # echo "d-i partman-auto/init_automatically_partition select custom" >> ~/custom-image/extract-cd/preseed/cli.seed
  56. # Prepare and chroot
  57. sudo cp /etc/resolv.conf edit/etc/
  58. # sudo cp /root/soft/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb edit/tmp/ # add here.
  59. sudo cp /root/install-bft.sh edit/tmp/
  60. sudo cp -rf /usr/tms edit/usr/
  61. sudo mount --bind /dev/ edit/dev
  62. # Learned this inline scripting from https://askubuntu.com/questions/551195/scripting-chroot-how-to
  63. cat << EOF | sudo chroot edit
  64. mount -t proc none /proc
  65. mount -t sysfs none /sys
  66. mount -t devpts none /dev/pts
  67. # "To avoid locale issues and in order to import GPG keys..."
  68. export HOME=/root
  69. export LC_ALL=C
  70. dbus-uuidgen > /var/lib/dbus/machine-id
  71. dpkg-divert --local --rename --add /sbin/initctl
  72. ln -s /bin/true /sbin/initctl
  73. #Customizations
  74. # Add Google Chrome's stable repository to apt (hey, I like Chrome)
  75. echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list
  76. wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
  77. #Update and Upgrade (distributions)
  78. apt-get update
  79. apt-get purge thunderbird -y
  80. apt-get dist-upgrade -y
  81. apt-get install google-chrome-stable yubikey-luks -y
  82. #dpkg -i /tmp/ctorrent_1.3.4.dnh3.3.2-4_amd64.deb # add here.
  83. /tmp/install-bft.sh
  84. apt-get autoremove -y
  85. apt-get autoclean -y
  86. #Clean up
  87. rm -rf /tmp/* ~/.bash_history
  88. rm /var/lib/dbus/machine-id
  89. rm /sbin/initctl
  90. dpkg-divert --rename --remove /sbin/initctl
  91. # "now umount (unmount) special filesystems and exit chroot"
  92. umount /proc || umount -lf /proc
  93. umount /sys
  94. umount /dev/pts
  95. EOF
  96. sudo umount edit/dev
  97. echo "Regenerate the manifest"
  98. #Regenerate the manifest
  99. sudo chmod +w extract-cd/casper/filesystem.manifest
  100. sudo chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee extract-cd/casper/filesystem.manifest
  101. sudo cp extract-cd/casper/filesystem.manifest extract-cd/casper/filesystem.manifest-desktop
  102. sudo sed -i '/ubiquity/d' extract-cd/casper/filesystem.manifest-desktop
  103. sudo sed -i '/casper/d' extract-cd/casper/filesystem.manifest-desktop
  104. #Compress the filesystem
  105. # Delete any existing squashfs - normally nothing to delete/rm.
  106. sudo rm extract-cd/casper/filesystem.squashfs
  107. sudo mksquashfs edit extract-cd/casper/filesystem.squashfs -b 1048576
  108. #"Update the filesystem.size file, which is needed by the installer"
  109. printf $(sudo du -sx --block-size=1 edit | cut -f1) | sudo tee extract-cd/casper/filesystem.size
  110. #"Remove old md5sum.txt and calculate new md5 sums"
  111. cd extract-cd
  112. sudo rm md5sum.txt
  113. find -type f -print0 | sudo xargs -0 md5sum | grep -v isolinux/boot.cat | sudo tee md5sum.txt
  114. #"Create the ISO image"
  115. #manpage for genisoimage http://manpages.ubuntu.com/manpages/trusty/man1/genisoimage.1.html
  116. #original
  117. #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 .
  118. #from EFI Q&A: https://askubuntu.com/questions/457528/how-do-i-create-an-efi-bootable-iso-of-a-customized-version-of-ubuntu
  119. #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 .
  120. # From https://linuxconfig.org/legacy-bios-uefi-and-secureboot-ready-ubuntu-live-image-customization
  121. # 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)
  122. 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 .
  123. # Not necessary, but you can check that a bootable partition is visible to fdisk.
  124. # If no bootable partiction is visible to fdisk, my experience is that the ISO will not boot from USB.
  125. # If so, we should be good to go.
  126. sudo fdisk -lu ../$IMAGE_NAME.iso
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注