You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在KVM创建Ubuntu 16.04虚拟机时跳过安装配置流程?

Automating Ubuntu 16.04 KVM Installation (Skip Interactive Prompts)

Absolutely! You can skip the username, password, hostname, and timezone setup prompts when installing Ubuntu 16.04 via KVM using a preseed file—Ubuntu's built-in method for unattended installations. Here's how to pull it off:

Step 1: Create a Preseed Configuration File

This file tells the installer exactly what settings to use, eliminating all interactive steps. Create a file named preseed.cfg with the following content (customize the values marked with comments):

# Preseed file for unattended Ubuntu 16.04 Server installation
d-i debian-installer/locale string en_US.UTF-8
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us

# Timezone (replace with your preferred timezone, e.g., Europe/London)
d-i time/zone string America/New_York
d-i clock-setup/utc boolean true

# Hostname and domain
d-i netcfg/get_hostname string my-ubuntu-1604-vm
d-i netcfg/get_domain string localdomain
d-i netcfg/choose_interface select auto

# User account setup (replace with your desired credentials)
d-i passwd/user-fullname string Admin User
d-i passwd/username string admin
d-i passwd/user-password password myStrongPassword123!
d-i passwd/user-password-again password myStrongPassword123!
# Optional: Allow weak passwords (not recommended for production)
# d-i user-setup/allow-password-weak boolean true

# Disk partitioning (uses entire disk with LVM; adjust if needed)
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select atomic
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

# Package selection (installs base system + SSH server)
tasksel tasksel/first multiselect standard
d-i pkgsel/include string openssh-server
d-i pkgsel/upgrade select none

# Automatically reboot after installation
d-i finish-install/reboot_in_progress note

Step 2: Prepare the Ubuntu 16.04 ISO

Make sure you have the Ubuntu 16.04 Server ISO downloaded (grab it from the official Ubuntu archive if you don't already have it).

Step 3: Launch the Unattended KVM Installation

Use the virt-install command to start the VM, injecting the preseed file and telling the installer to use it. There are two easy ways to do this:

Option 1: Inject Preseed Directly (No HTTP Server Needed)

This method embeds the preseed file into the installer's initrd, so you don't need to host it separately:

virt-install \
  --name my-ubuntu-1604-vm \
  --ram 2048 \
  --vcpus 2 \
  --disk path=/var/lib/libvirt/images/my-ubuntu-1604-vm.qcow2,size=20 \
  --cdrom /path/to/ubuntu-16.04.7-server-amd64.iso \
  --initrd-inject /path/to/preseed.cfg \
  --extra-args "auto preseed/file=/preseed.cfg"

Option 2: Host Preseed via HTTP (Useful for Multiple Installs)

If you plan to set up multiple VMs, host the preseed file on a temporary HTTP server on your Ubuntu host:

  1. Start a simple HTTP server in the directory where your preseed.cfg is stored:
    python3 -m http.server 8000
    
  2. Run the virt-install command pointing to the HTTP URL of your preseed file (replace HOST_IP with your host's actual IP address):
    virt-install \
      --name my-ubuntu-1604-vm \
      --ram 2048 \
      --vcpus 2 \
      --disk path=/var/lib/libvirt/images/my-ubuntu-1604-vm.qcow2,size=20 \
      --cdrom /path/to/ubuntu-16.04.7-server-amd64.iso \
      --extra-args "auto url=http://HOST_IP:8000/preseed.cfg"
    

Key Notes

  • Double-check the preseed values (timezone, credentials, hostname) before launching—typos can cause installation failures.
  • If you need a custom disk partitioning scheme, adjust the partman-* lines in the preseed file to match your needs.
  • Ubuntu 16.04 is end-of-life, so ensure you have appropriate security measures in place if you're using this VM in a production environment.

That's all! The installation will run entirely unattended, skipping all the interactive prompts you wanted to avoid. You can monitor progress via the VM console, or connect via SSH once the installation completes.

内容的提问来源于stack exchange,提问作者nadermx

火山引擎 最新活动