Ubuntu14.04安装镜像定制


需求

安装操作系统(Ubuntu14.04 Server)以后,还需要安装一些基础的软件(OpenSSH, Docker, DockerCompose, wget,curl,vim,telnet等),纯内网环境安装这些软件需要联网安装,离线安装比较麻烦,因此根据14.04制作一个预先安装好这些软件的镜像系统。


准备
  • 下载Ubuntu14.04 server操作系统安装镜像
  • 安装squashfs-tools(根文件系统解压缩工具)、genisoimage(根文件系统打包工具)
  • 切换到root用户(sudo -i),以下所有操作均以root用户自行
定制步骤
  • 提取根文件系统

    • 挂载iso镜像到空目录

        mount -o loop ubuntu-14.04-server-amd64.iso /mnt
      
    • 拷贝文件

        mkdir newiso
        cp -rp /mnt newiso (不能使用/mnt/*,这样不能拷贝隐藏文件)
      
    • 解压filesystem.squashfs文件 将filesystem.squashfs文件解压到当前目录,解压出来的目录为squashfs-root

        unsquashfs newiso/install/filesystem.squashfs
      
    • 卸载iso镜像

        umount /mnt
      
  • 虚拟根环境网络配置

    如果在虚根环境中要使用网络连接,则需要拷贝主机的网络配置文件到虚拟根目录。

      cp /etc/hosts squashfs-root/etc/
      cp /etc/resolv.conf squashfs-root/etc/
    
  • 拷贝软件安装包及其依赖包到虚拟根目录/root目录下
  • 切换到新系统

    切换到squashfs-root目录,使其成为系统的当前根目录,并挂载相关目录

      chroot sqkuashfs-root
      mount -t proc none /proc
      mount -t sysfs none /sys
      mount -t devpts none /dev/pts
    
  • 定制系统
    • 修改软件源/etc/apt/sources.list
      deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
      deb http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
      deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
      deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
      deb http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
      deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
      deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
      deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
      deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
      deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
      
    • 基础软件安装
      apt-get update
      apt-get install -y telnet curl wget vim openssh-server
      
    • docker安装
      curl -sSL https://get.daocloud.io/docker | sh
      
    • docker-compose安装
      curl -L https://get.daocloud.io/docker/compose/releases/download/1.13.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
      chmod +x /usr/local/bin/docker-compose
      
  • 回到原主机系统
    • 清理安装包和临时文件
      apt-get clean
      apt-get autoremove
      rm -rf /tmp/*
      
    • 卸载目录
      umount /proc(若无法卸载就加 -lf选项)
      umount /sys
      umount /dev/pts
      
    • 退出
      exit
      
  • 重新配置并压缩根文件系统
    • 生成新的filesystem.manifest
      chmod +w newiso/install/filesystem.manifest
      chroot squashfs-root dpkg-query -W --showformat='${Package} ${Version}\n' > newiso/install/filesystem.manifest
      
    • 生成新的filesystem.squashfs
      rm newiso/install/filesystem.squashfs
      mksquashfs squashfs-root newiso/install/filesystem.squashfs 
      
    • 生成新的filesystem.size
      printf $(du -sx --block-size=1 squashfs-root | cut -f1) > newiso/install/filesystem.size
      
    • 生成新的md5sum.txt
      cd newiso
      rm md5sum.txt
      find -type f -print0 | xargs -0 md5sum | grep -v isolinux/boot.cat | tee md5sum.txt
      
  • 重新制作ISO镜像
      mkisofs -D -r -V "Signit-ubuntu-14.04" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../signit-ubuntu-14.04-server-amd64.iso .
    
后续操作

用生成的ISO镜像安装操作系统后,需要将创建的普通用户添加到docker组中

    sudo usermod -aG docker $USER
    sudo reboot
测试

在本地简单测试时,定制镜像在操作系统安装过程中正常,镜像定制过程中安装的软件可以正常使用。但不清楚是否存在其他问题。

results matching ""

    No results matching ""