使用preseed一键安装Ubuntu Server 1604

简介: 准备preseed配置文件

准备preseed配置文件

d-i debian-installer/locale string en_US.UTF-8
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i netcfg/choose_interface select auto
d-i netcfg/dhcp_timeout string 60
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/wireless_wep string
d-i base-installer/kernel/override-image string linux-server
d-i mirror/http/mirror select gb.archive.ubuntu.com
d-i mirror/http/proxy string
d-i clock-setup/utc boolean true
d-i localechooser/shortlist/zh_CN select
d-i time/zone string Asia/Chongqing
d-i clock-setup/ntp boolean true
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto/choose_recipe select multi
d-i partman/default_filesystem string ext4
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i passwd/user-fullname string scutech.com
d-i passwd/username string scutech
d-i passwd/user-password password dingjia
d-i passwd/user-password-again password dingjia
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
tasksel tasksel/first multiselect none
d-i pkgsel/include string openssh-server curl
d-i pkgsel/language-packs multiselect en,zh
d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select unattended-upgrades
d-i debian-installer/quiet  boolean false
d-i debian-installer/splash boolean false
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/timeout string 0
d-i debian-installer/add-kernel-opts string vga=normal nomodeset audit=0 intel_idle.max_cstate=0 processor.max_cstate=1 cgroup_enable=memory swapaccount=1
d-i finish-install/reboot_in_progress note
d-i preseed/late_command string in-target wget --output-document=/tmp/post-install.sh http://192.168.?.?/post-install.sh; in-target /bin/sh /tmp/post-install.sh



为了节省版面我把空行和注释都删除了,大家如果想知道每一个配置项的涵义可以查看ubuntu的官方文档Contents of the preconfiguration file

几点说明:


这里的语言,地区,键盘等设置都是适合大陆的情况的;

hostname在preseed里面设置了没有用,这应该是Xenial的bug,不知道Bionic改好了没有;

最后一项是调用一个shell脚本,这个很实用的功能,但我实际测试时这个不支持tftp(wget和curl都不行),只能用http。

准备post-install程序

#!/bin/bash
HOSTNAME='infosemper'
USERNAME='scutech'
PACKAGES='htop nano sudo python-minimal vim rsync dnsutils less ntp'
apt-get update && apt-get upgrade -y
apt-get -y dist-upgrade
apt-get install $PACKAGES -y
# Add SSH Key for default user
mkdir /home/$USERNAME/.ssh/
cat > /home/$USERNAME/.ssh/authorized_keys <<EOF
SSH-KEY HERE
EOF
chmod 700 /home/$USERNAME/.ssh
chmod 600 /home/$USERNAME/.ssh/authorized_keys
chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh
# Add SSH Key for root user
mkdir /root/.ssh/
cat > /root/.ssh/authorized_keys <<EOF
SSH-KEY HERE
EOF
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
chown -R root:root /root/.ssh
# Edit /etc/ssh/sshd_config
sed -i '/^PermitRootLogin/s/prohibit-password/yes/' /etc/ssh/sshd_config
sed -i -e 's/#PasswordAuthentication/PasswordAuthentication/g' /etc/ssh/sshd_config
hostn=$(cat /etc/hostname)
sudo sed -i "s/$hostn/$HOSTNAME/g" /etc/hosts
sudo sed -i "s/$hostn/$HOSTNAME/g" /etc/hostname
sudo reboot



这个程序只是一个例子,让大家知道你在preseed里可以调用shell的各种命令。


配置tftp服务器

安装包


apt-get install tftpd-hpa


修改tftp的配置文件到如下格式:


cat /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp" 
TFTP_DIRECTORY="/home/scutech/tftp" 
TFTP_ADDRESS=":69" 
TFTP_OPTIONS="--secure --create"

查看69端口占用情况:


# ss -naup|grep :69
UNCONN     0      0            *:69                       *:*                   users:(("in.tftpd",pid=20534,fd=4))
UNCONN     0      0           :::69                      :::*                   users:(("in.tftpd",pid=20534,fd=5))

查看服务状态


# systemctl status tftpd-hpa
● tftpd-hpa.service - LSB: HPA's tftp server
   Loaded: loaded (/etc/init.d/tftpd-hpa; bad; vendor preset: enabled)
   Active: active (running) since Thu 2019-10-10 17:23:33 CST; 2min 25s ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/tftpd-hpa.service
           └─20534 /usr/sbin/in.tftpd --listen --user tftp --address :69 --secure /var/lib/tftpboot
Oct 10 17:23:33 ubuntu1604 systemd[1]: Starting LSB: HPA's tftp server...
Oct 10 17:23:33 ubuntu1604 tftpd-hpa[20491]:  * Starting HPA's tftpd in.tftpd
Oct 10 17:23:33 ubuntu1604 tftpd-hpa[20491]:    ...done.
Oct 10 17:23:33 ubuntu1604 systemd[1]: Started LSB: HPA's tftp server.


创建工作目录,并修改权限


mkdir -p /home/scutech/tftp/d-i/xenial/script
chmod 777 /home/scutech/tftp
chown -R tftp:tftp /home/scutech/tftp
systemctl restart tftpd-hpa


使用tftp进行测试(略)

将preseed.cfg拷贝到/home/scuteh/tftp/d-i/xenial目录下,将post-install程序拷贝到 /home/scuteh/tftp/d-i/xenial/script目录下


安装buntu时加载preseed

启动时修改参数,将“file-/cdrom/preseed/ubuntu-server.seed”改成 “auto=true url=tftp://192.168.??/preseed.cfg hostname=scutech”。

安装过程中自动从tftp服务器上下载preseed配置文件

image.png

加载这个preseed配置文件后后面就什么不用做了,等着吧:

image.png

完成后自动重新启动,我在做分区时选择的是multi,这样 /home, /usr, /var, /tmp 几个分区是分开的:

image.png

这是一个40G硬盘的分区例子,实际工作中分区可能比这要复杂,preseed配置文件中可以保护子文件,可以对每一种分区的不同情况调用不同的子文件,以后有机会我会贴一下例子上来。

相关文章
|
9月前
|
Ubuntu Linux
任何Ubuntu用户都应安装的四大Linux应用程序
当然,这款程序不需要太多介绍。我们面对的是网上最庞大最完整的多媒体中心,由于丰富的插件,我们能够高度细化地定制其每一项功能。这是我们的Linux发行版不可或缺的必备软件。 我们可以通过运行以下命令来轻松安装Kodi:sudo apt install kodi。
|
9月前
|
Ubuntu 物联网 Linux
从零安装一个Linux操作系统几种方法,以Ubuntu18.04为例
一切就绪后,我们就可以安装操作系统了。当系统通过优盘引导起来之后,我们就可以看到跟虚拟机中一样的安装向导了。之后,大家按照虚拟机中的顺序安装即可。 好了,今天主要介绍了Ubuntu Server版操作系统的安装过程,关于如何使用该操作系统,及操作系统更深层的原理,还请关注本号及相关圈子。
|
9月前
|
Ubuntu Linux 网络安全
Linux服务器之Ubuntu的安装与配置
Ubuntu Desktop是目前最成功、最流行的图形界面的Linux发行版;而Ubuntu Server也在服务器端市场占据了较大的份额。今天为大家详细介绍了Ubuntu Server的安装与配置,希望对你能有所帮助。关于VMware、VirtualBox等虚拟化软件的使用,朱哥还会在后续的文章中为大家详细介绍,敬请关注!
|
7月前
|
Ubuntu 安全 iOS开发
Nessus Professional 10.10 Auto Installer for Ubuntu 24.04 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for Ubuntu 24.04 - Nessus 自动化安装程序
902 5
|
7月前
|
NoSQL Ubuntu MongoDB
在Ubuntu 22.04上安装MongoDB 6.0的步骤
这些步骤应该可以在Ubuntu 22.04系统上安装MongoDB 6.0。安装过程中,如果遇到任何问题,可以查阅MongoDB的官方文档或者Ubuntu的相关帮助文档,这些资源通常提供了解决特定问题的详细指导。
747 18
|
8月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
437 18
|
8月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
569 15
|
8月前
|
存储 Ubuntu iOS开发
在Ubuntu 22.04系统上安装libimobiledevice的步骤
为了获取更多功能或者解决可能出现问题,请参考官方文档或者社区提供支持。
788 14
|
8月前
|
Ubuntu 安全 关系型数据库
安装与配置MySQL 8 on Ubuntu,包括权限授予、数据库备份及远程连接指南
以上步骤提供了在Ubuntu上从头开始设置、配置、授权、备份及恢复一个基础但完整的MySQL环境所需知识点。
882 7
|
9月前
|
XML Ubuntu Java
如何在Ubuntu系统上安装和配置JMeter和Ant进行性能测试
进入包含 build.xml 的目录并执行:
398 13