• 主页
  • 相册
  • 随笔
  • 目录
  • 存档
Total 244
Search AboutMe

  • 主页
  • 相册
  • 随笔
  • 目录
  • 存档

无人值守ISO的制作与安装

2020-03-27

1. 实验要求

  • 完成“无人值守”ISO镜像制作
    • 定制一个普通用户名和默认密码
    • 定制安装OpenSSH Server
    • 安装过程禁止自动联网更新软件包
  • 利用制作好的ISO镜像,在VirtualBox上执行无人安装

2. 实验环境

  • ubuntu-18.04.4-server-amd64.iso

  • Vbox-6.14

  • 题外话

    • wsl1暂不支持(2020.3.27, 具体见参考资料2)
      1
      2
      3
      ~ mkdir exp
      ~ sudo mount -o loop ubuntu-18.04.4-server-amd64. iso exp/
      mount: exp: mount failed: Operation not permitted.
    • wsl2不是好选择:至今没有解决Hyper—v冲突

3. 实验原理

3.1. 无人值守(kickstart)

  • 概念

    Suppose you are installing Ubuntu on a bunch of identical computers, and you already know the answers to certain questions (what country and time zone you’re in, what keyboard you have, how the network should be configured, how you want to partition the hard disk, etc). You can “preseed“ the answers to these questions in a very simple configuration file.

  • 实现方式

    When the CD boots up, a Linux kernel is started and the installation tasks are initiated. The installer’s default behavior can be modified through the use of a “preseed” file, which feeds d-i answers to questions normally asked by debconf, or in other contexts. If you look in the preseed folder in the install CD, you’ll see th
    at certain options (e.g. “server”, “expert”, “oem”) already have preseed files assigned to them

  • .seed

    Linux操作系统磁盘上随附的安装程序文件,例如Ubuntu Linux安装CD; 以文本格式保存,每行四个字段; 每行包括应该运行命令的程序的名称,以及变量的名称,类型和值

  • .cfg

    CFG is a configuration file format used for storing settings. CFG files are created by many programs to store information and settings that differ from the factory defaults.

    CFG files usually appear as text documents, and can be opened by word processors though it is not recommended.

  • d-i
    • Abbreviation forDebianInstaller
  • preseed语法
    1
    2
    3
    4
    5
    6
    A preseed file has 4 fields per line:

    identity of the program which will pick up this command
    name of the variable whose value will be passed
    variable type
    value of variable

3.2. SYSLINUX

The SYSLINUX Project is a suite of lightweight master boot record (MBR) boot loaders for starting up IBM PC compatible computers with the Linux kernel.

  • Wikipedia contributors. (2019, April 14). SYSLINUX. In Wikipedia, The Free Encyclopedia. Retrieved 10:52, March 27, 2020
  • mkisofs
    • 功能说明:建立ISO 9660映像文件。

3.3. 挂载

  • 概念

    挂载(mounting)是指由操作系统使一个存储设备(诸如硬盘、CD-ROM或共享资源)上的电脑文件和目录可供用户通过计算机的文件系统访问的一个过程

    • 维基百科编者. 挂载[G/OL]. 维基百科, 2018(20180910)[2018-09-10].
  • mount
    • 用于挂载Linux系统外的文件

      将 /dev/hda1 挂在 /mnt 之下。

      #mount /dev/hda1 /mnt

3.4. 文件传递

  • scp
    • 用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的
      • 源文件:指定要复制的源文件。
      • 目标文件:目标文件。格式为user@host:filename(文名为目标文件的名称)。

4. 实验内容

4.1. 挂载并拷贝ISO镜像内容

  • (可选)将文件从宿主机传到虚拟机

    • scp -P 8888 ubuntu-18.04.4-server-amd64.iso hejueyun@127.0.0.1:/home/hejueyun
  • 挂载

    • sudo mount -o loop ubuntu-18.04.4-server-amd64.iso exp/
  • 将文件拷出

    • sudo cp -r exp/ cd-image/
  • 卸载

    • sudo umount exp

4.2. 修改SYSLINUX引导配置和Linux引导内核配置

  • 修改isolinux/txt.cfg文件

    • 编辑Ubuntu安装引导界面,增加一个新菜单项入口Auto Installation
      1
      2
      3
      4
      label autoinstall
      menu label ^Auto Installation
      kernel /install/vmlinuz
      append preseed/file=/cdrom/preseed/autoinstall.seed debian-installer/locale=en_US console-setup/layoutcode=us keyboard-configuration/layoutcode=us console-setup/ask_detect=false localechooser/translation/warn-light=true localechooser/translation/warn-severe=true initrd=/install/initrd.gz root=/dev/ram rw quiet
  • (可选)修改isolinux/isolinux.cfg

    • 安装程序自动选择默认选项并在超时后开始安装:timeout 3

4.3. 创建并修改preseed文件

  • 参考官方D-I文件:preseed.cfg
  • 在cd-image/preseed目录下创建文件autoinstall.seed并修改

4.3.1. 定制一个普通用户名和默认密码

1
2
3
4
5
6
7
8
9
# To create a normal user account.
d-i passwd/user-fullname string flser
d-i passwd/username string flser

# Normal user's password, either in clear text
d-i passwd/user-password password 123123
d-i passwd/user-password-again password 123123

d-i user-setup/allow-password-weak boolean true
  • 默认用户名usrN
  • 默认密码usr
    • 开启允许弱密钥

4.3.2. 定制安装OpenSSH Server

1
2
# Individual additional packages to install
d-i pkgsel/include string openssh-server build-essential

4.3.3. 安装过程禁止自动联网更新软件包

1
2
3
# Whether to upgrade packages after debootstrap.
# Allowed values: none, safe-upgrade, full-upgrade
d-i pkgsel/upgrade select none

4.3.4. 其他可选配置

  • 时间地区等设置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # Uncomment content below
    # Optionally specify additional locales to be generated.
    d-i localechooser/supported-locales multiselect en_US.UTF-8, nl_NL.UTF-8
    d-i time/zone string Asia/Shanghai
    d-i apt-setup/use_mirror boolean false
    # To install to the first device (assuming it is not a USB stick):
    d-i grub-installer/bootdev string default
    d-i partman-auto/init_automatically_partition select biggest_free

    # comment content below
    # tasksel tasksel/first multiselect ubuntu-desktop

  • Apt setup

    Setup of the /etc/apt/sources.list and basic configuration options is fully automated based on your installation method and answers to earlier questions. You can optionally add other (local) repositories.

  • Package selection

    You can choose to install any combination of tasks that are available.

    You can also choose to install no tasks, and force the installation of a set of packages in some other way. We recommend always including the standard task.

  • Boot loader installation
  • Partitioning

    Using preseeding to partition the harddisk is limited to what is supported by partman-auto. You can choose to partition either existing free space on a disk or a whole disk. The layout of the disk can be determined by using a predefined recipe, a custom recipe from a recipe file or a recipe included in the preconfiguration file.

4.3.5. 重新制作ISO镜像

  • 重新计算哈希值:find . -type f -print0 | xargs -0 md5sum > md5sum.txt

    • 注意su切换到root
  • custom_iso.sh

    1
    2
    3
    4
    5
    6
    7
    8
    9
    IMAGE=custom.iso
    BUILD=~/cd-image/

    mkisofs -r -V "Custom Ubuntu Install CD" \
    -cache-inodes \
    -J -l -b isolinux/isolinux.bin \
    -c isolinux/boot.cat -no-emul-boot \
    -boot-load-size 4 -boot-info-table \
    -o $IMAGE $BUILD
    • sudo bash custom_iso.sh

4.4. (可选)导出ISO文件

  • 在宿主机下执行scp -P 8888 hejueyun@127.0.0.1:/home/hejueyun/custom.iso .

5. 实验结果

  • 无人值守镜像安装

6. 参考资料

  • InstallCDCustomization - Community Help Wiki
  • mount - WSL - /dev/loop0 workaround - Ask Ubuntu
  • B.4. Contents of the preconfiguration file (for bionic)
  • Operating System
  • Linux
mysql cluster搭建实验
《任航-没有救赎的躯体》笔记
  1. 1. 1. 实验要求
  2. 2. 2. 实验环境
  3. 3. 3. 实验原理
    1. 3.1. 3.1. 无人值守(kickstart)
    2. 3.2. 3.2. SYSLINUX
    3. 3.3. 3.3. 挂载
    4. 3.4. 3.4. 文件传递
  4. 4. 4. 实验内容
    1. 4.1. 4.1. 挂载并拷贝ISO镜像内容
    2. 4.2. 4.2. 修改SYSLINUX引导配置和Linux引导内核配置
    3. 4.3. 4.3. 创建并修改preseed文件
      1. 4.3.1. 4.3.1. 定制一个普通用户名和默认密码
      2. 4.3.2. 4.3.2. 定制安装OpenSSH Server
      3. 4.3.3. 4.3.3. 安装过程禁止自动联网更新软件包
      4. 4.3.4. 4.3.4. 其他可选配置
      5. 4.3.5. 4.3.5. 重新制作ISO镜像
    4. 4.4. 4.4. (可选)导出ISO文件
  5. 5. 5. 实验结果
  6. 6. 6. 参考资料
© 2024 何决云 载入天数...