参考阅读Debian关于Preseeding的中文介绍:
注意:对于希望尝试自动安装的读者,千万要小心自己的硬盘数据,建议在虚拟机或者没有
重要数据的硬盘上尝试。我自己是用公司的闲置电脑实验的。
Preseeding将安装过程中需要回答的问题的答案放到预置
文件中,这样在安装系统的过程中就无需手动输入问题的答案,这是Preseeding实现的原理。preseeding是针对Debian的系统来说的。
作为在Debian基础上开发的Ubuntu,同样支持Preseeding,我们可以像编写Debian下的预置文件一样编写Ubuntu的预置文件。
Preseeding和预置文件的其他信息我就不再详细介绍了,感兴趣的读者可以参考我上面给出的链接。
我们没有必要重新创建一个新的预
置文件,通过对现有预置文件的修改可以帮我们更方便的得到我们自己所需要的预置文件。Debian预置文件的范例可以通过以下链接得到:。
Ubuntu预置文件的范例在上面Ubuntu官方关于Preseeding的介绍中有一个链接,不过这个链接已经失效了。我是通过比较另类的方法得到
ubuntu的预置文件范例的,通过Wubi安装Ubuntu,但是并不重
启电脑真正安装,在wubi创建的Ubuntu文件夹下就有个预置文件,具体的路径是:ubuntu\install\custom-
installation\preseed.cfg。这里的preseed.cfg就是我们需要的预置文件了。
在讲解如何
配置预置文件之前,还有一点需要指出:Ubuntu在安装过程中需要回答7个问题,分别是:1.语言环境;2.地区;3.键盘布局;4.硬盘分区;5.用
户名和密码;6.文件迁移;7.最终确认(GRUB安装位置),事实上,Ubuntu在安装过程中不止需要配置这7个方面的环境,还有很多其他方面也需要
配置,比如网络,镜像,套件,APT等等,那么为什么我们没有看到关于这些设置的问题呢?其实是Ubuntu的安装器Ubiquity自己回答了这些问
题。下面这段代码是Ubuntu-8.04.0-i386-desktop中isolinux.cfg文件关于live-install的相关代码,我们
执行Ubuntu的Live CD安装时都是执行的这段代码:
代码:
LABEL live-install
menu label ^Install Ubuntu
kernel /casper/vmlinuz
append file=/cdrom/preseed/ubuntu.seed
boot=casper only-ubiquity initrd=/casper/initrd.gz quiet splash --
注
意看append中有一个“only-ubiquity ”
的参数,这个参数表明在Live
CD安装的过程中,Ubituity使用的only-ubiquity这种模式,在这种模式下,我们只需要回答那7个问题,其他的问题由Ubiquity
自动回答。而我们在实现自动安装的过程中,需要把Ubiquity的模式修改为“automatic-ubiquity”,同时,还需要配置除了7个常规问题之外的其他问题。
下面我以
Live USB实现自动安装的方法为例来讲解如何实现Ubuntu的自动安装。制作Live
USB的方法有很多种,我是使用UltraISO来制作的,具体的实现过程见如下网页:,
事实上,只要是通过syslinux方法实现Live
USB的,下面的操作都是大同小异的,比如UNetBootin,或者Ubuntu8.10自带的工具Live USB
Creator。我们需要完成以下两个步骤:
1.配置preseed.cfg文件,将安装过程中需要回答的问题全部回答好并且回答正确;
2.
在syslinux.cfg文件中添加对preseed.cfg的指引;
其中,对7个问题的回答分别如下所示:
1.中文(简体)
2.
中国(上海)
3.USA-USA
4.向导-使用整个硬盘
5.账号:abc,密码:123
6.无用户文件导入
7.GRUB
默认安装在第一个硬盘
其他的问题采用自动配置。这样,我修改完成后的preseed.cfg文件如下所示:
注意:preseed.cfg与Ubuntu具体的版本也有关系,千万不可混用,我这里
使用的版本是ubuntu-8.04.1-i386-desktop版本。
代
码:
## LOCALE
# Locale sets language
and country.
d-i debian-installer/locale string zh_CN
##
KEYBOARD
# Keyboard selection.
# d-i console-setup/modelcode
string pc104
d-i console-setup/layoutcode string us
# To select a
variant of the selected layout (if you leave this out, the
# basic
form of the layout will be used):
#d-i console-setup/variantcode
string dvorak
#d-i console-tools/archs select at
#d-i
console-keymaps-at/keymap select us
## NETWORKING
# netcfg
will choose an interface that has link if possible. This makes it
#
skip displaying a list if there is more than one interface.
d-i
netcfg/choose_interface select auto
# To pick a particular interface
instead:
#d-i netcfg/choose_interface select eth1
# If you have a
slow dhcp server and the installer times out waiting for
# it, this
might be useful.
#d-i netcfg/dhcp_timeout string 60
# If you
prefer to configure the network manually, uncomment this line and
#
the static network configuration below.
#d-i netcfg/disable_dhcp
boolean true
# If you want the preconfiguration file to work on
systems both with and
# without a dhcp server, uncomment these lines
and the static network
# configuration below.
d-i
netcfg/dhcp_failed note
d-i netcfg/dhcp_options select Do not
configure the network at this time
# Static network configuration.
#
d-i netcfg/get_nameservers string 192.168.1.1
# d-i
netcfg/get_ipaddress string 192.168.1.42
# d-i netcfg/get_netmask
string 255.255.255.0
# d-i netcfg/get_gateway string 192.168.1.1
#
d-i netcfg/confirm_static boolean true
# Any hostname and domain
names assigned from dhcp take precedence over
# values set here.
However, setting the values still prevents the questions
# from being
shown, even if values come from dhcp.
d-i netcfg/get_hostname string
ubuntu
d-i netcfg/get_domain string ubuntu-domain
# Disable that
annoying WEP key dialog.
d-i netcfg/wireless_essid string essid
d-i
netcfg/wireless_wep string
# The wacky dhcp hostname that some ISPs
use as a password of sorts.
#d-i netcfg/dhcp_hostname string radish
##
UBIQUITY
ubiquity ubiquity/summary note
ubiquity
ubiquity/reboot boolean true
ubiquity ubiquity/success_command
string [ -x /custom-installation/hooks/success-command.sh ] &&
/custom-installation/hooks/success-command.sh
ubiquity
ubiquity/failure_command string [ -x
/custom-installation/hooks/failure-command.sh ] &&
/custom-installation/hooks/failure-command.sh
#ubiquity
ubiquity/automation_failure_command [ -x
/custom-installation/hooks/failure-command.sh ] &&
/custom-installation/hooks/failure-command.sh
## SKIP
Security-Update-Error
d-i apt-setup/security-updates-failed note
##
MIRRORS
#~ d-i mirror/country string enter information manually
#~
d-i mirror/http/hostname string archive.ubuntu.com
#~ d-i
mirror/http/directory string /ubuntu
d-i mirror/http/proxy string
##
SUITE
# Suite to install.
d-i mirror/suite string hardy
#
Suite to use for loading installer components (optional).
#d-i
mirror/udeb/suite string edgy
## PARTITIONING
# If the system
has free space you can choose to only partition that space.
# Note:
this must be preseeded with a localized (translated) value.
#d-i
partman-auto/init_automatically_partition \
# select Use the
largest continuous free space
# Alternatively, you can specify a disk
to partition. The device name can
# be given in either devfs or
traditional non-devfs format.
# For example, to use the first SCSI
hard disk:
d-i partman-auto/disk string /dev/sda
d-i
partman-auto/method string regular
# Or, if you want to use LVM:
#d-i
partman-auto-lvm/disk string /dev/sda
# You can choose from any of
the predefined partitioning recipes.
# Note: this must be preseeded
with a localized (translated) value.
##
d-i
partman-auto/choose_recipe \
select All files in one partition
(recommended for new users)
#d-i partman-auto/choose_recipe \
#
select Separate /home partition
#d-i partman-auto/choose_recipe \
#
select Separate /home, /usr, /var, and /tmp partitions
# Or
provide a recipe of your own...
# The recipe format is documented in
the file devel/partman-auto-recipe.txt.
# If you have a way to get a
recipe file into the d-i environment, you can
# just point at it.
#d-i
partman-auto/expert_recipe_file string /hd-media/recipe
# If not,
you can put an entire recipe the preconfiguration file in one
#
(logical) line. This example creates a small /boot partition, suitable
#
swap, and uses the rest of the space for the root partition:
#LoopInstallFolder=/ubuntu/disks
#d-i
partman-auto/disk string LIDISK
#d-i partman-auto/method string loop
#d-i
partman-auto-loop/partition string LIPARTITION
#d-i
partman-auto-loop/recipe string \
# /ubuntu/disks/root.disk 3000
9000 9000 ext3 method{ format } format{ } use_filesystem{ } filesystem{
ext3 } mountpoint{ / } . \
# /ubuntu/disks/swap.disk 100 1000 1000
linux-swap method{ swap } format{ } . \
# \
# \
#d-i
partman-auto/expert_recipe string \
#
boot-root :: \
#
40 50 100 ext3 \
#
$primary{ } $bootable{ } \
#
method{ format } format{ } \
#
use_filesystem{ } filesystem{ ext3 } \
#
mountpoint{ /boot } \
# .
\
# 500 10000
1000000000 ext3 \
#
method{ format } format{ } \
#
use_filesystem{ } filesystem{ ext3 } \
#
mountpoint{ / } \
# .
\
# 64 512 300%
linux-swap \
# method{
swap } format{ } \
# .
# This makes
partman automatically partition without confirmation.
d-i
partman/confirm_write_new_label boolean true
#
d-i
partman/choose_partition \
select Finish partitioning and
write changes to disk
d-i partman/confirm boolean true
##
CLOCK AND TIME ZONE
# Controls whether or not the hardware clock is
set to UTC.
d-i clock-setup/utc boolean false
# You may set this
to any valid setting for $TZ; see the contents of
#
/usr/share/zoneinfo/ for valid values.
d-i time/zone string
Asia/Shanghai
## APT
# You can choose to install restricted
and universe software, or to install
# software from the backports
repository.
#d-i apt-setup/restricted boolean true
#d-i
apt-setup/universe boolean true
#d-i apt-setup/backports boolean true
#
Uncomment this to avoid adding security sources, or
# add a hostname
to use a different server than security.ubuntu.com.
#d-i
apt-setup/security_host string
# Additional repositories, local[0-9]
available
#d-i apt-setup/local0/repository string \
# deb
edgy main
#d-i apt-setup/local0/comment
string local server
# Enable deb-src lines
#d-i
apt-setup/local0/source boolean true
# URL to the public key of the
local repository
#d-i apt-setup/local0/key string
## USER ACCOUNT
# Skip creation of a
root account (normal user account will be able to
# use sudo). The
default is false; preseed this to true if you want to set
# a root
password.
d-i passwd/root-login boolean false
# Alternatively, to
skip creation of a normal user account.
#d-i passwd/make-user boolean
false
# Root password, either in clear text
#d-i
passwd/root-password password r00tme
#d-i passwd/root-password-again
password r00tme
# or encrypted using an MD5 hash.
#d-i
passwd/root-password-crypted password [MD5 hash]
# To create a normal
user account.
d-i passwd/user-fullname string abc User
d-i
passwd/username string abc
# Normal user's password, either in clear
text
#d-i passwd/user-password password 123
#d-i
passwd/user-password-again password 123
# or encrypted using an MD5
hash.
#d-i passwd/user-password-crypted password
$1$2SGVV3Ue$mI3IzQ08IArdeVnTctxaK/
#An MD5 hash for a password can be
generated using the following command.
#$ echo "r00tme" | mkpasswd
-s -H MD5
## BASE SYSTEM INSTALLATION
# Select the initramfs
generator used to generate the initrd for 2.6 kernels.
#d-i
base-installer/kernel/linux/initramfs-generators string yaird
##
BOOT LOADER
# Grub is the default boot loader (for x86). If you want
lilo installed
# instead, uncomment this:
#d-i grub-installer/skip
boolean true
d-i lilo-installer/skip boolean true
# This is
fairly safe to set, it makes grub install automatically to the MBR
#
if no other operating system is detected on the machine.
#d-i
grub-installer/only_debian boolean true
# This one makes
grub-installer install to the MBR if if finds some other OS
# too,
which is less safe as it might not be able to boot that other OS.
#d-i
grub-installer/with_other_os boolean true
# Alternatively, if you
want to install to a location other than the mbr,
# uncomment and
edit these lines:
# d-i grub-installer/bootdev string (hd0,0)
#d-i
grub-installer/bootdev_directory string /ubuntu/disks
d-i
grub-installer/only_debian boolean true
#d-i
grub-installer/with_other_os boolean true
## PACKAGE SELECTION
tasksel
tasksel/first multiselect ubuntu-desktop
#tasksel tasksel/first
multiselect ubuntu-standard
#tasksel tasksel/first multiselect
ubuntu-standard, lamp-server
#tasksel tasksel/first multiselect
ubuntu-standard, kubuntu-desktop
#d-i pkgsel/include string
openssh-server build-essential
# Some versions of the installer can
report back on what software you have
# installed, and what software
you use. The default is not to report back,
# but sending reports
helps the project determine what software is most
# popular and
include it on CDs.
#popularity-contest popularity-contest/participate
boolean false
## FINISH FIRST STAGE
# Avoid that last message
about the install being complete.
d-i
finish-install/reboot_in_progress note
# This will prevent the
installer from ejecting the CD during the reboot,
# which is useful
in some situations.
d-i cdrom-detect/eject boolean false
## X
CONFIGURATION
# X can detect the right driver for some cards, but if
you're preseeding,
# you override whatever it chooses. Still, vesa
will work most places.
#xserver-xorg
xserver-xorg/config/device/driver select vesa
# A caveat with mouse
autodetection is that if it fails, X will retry it
# over and over.
So if it's preseeded to be done, there is a possibility of
# an
infinite loop if the mouse is not autodetected.
#xserver-xorg
xserver-xorg/autodetect_mouse boolean true
# Monitor autodetection is
recommended.
xserver-xorg xserver-xorg/autodetect_monitor boolean
true
# Uncomment if you have an LCD display.
#xserver-xorg
xserver-xorg/config/monitor/lcd boolean true
# X has three
configuration paths for the monitor. Here's how to preseed
# the
"medium" path, which is always available. The "simple" path may not
#
be available, and the "advanced" path asks too many questions.
##
#xserver-xorg
xserver-xorg/config/monitor/selection-method \
# select medium
##
#xserver-xorg
xserver-xorg/config/monitor/mode-list \
# select 1024x768 @ 60
Hz
## PRESEEDING OTHER PACKAGES
# Depending on what software
you choose to install, or if things go wrong
# during the
installation process, it's possible that other questions may
# be
asked. You can preseed those too, of course. To get a list of every
#
possible question that could be asked during an install, do an
#
installation, and then run these commands:
# debconf-get-selections
--installer > file
# debconf-get-selections >> file
##
MIGRATION-ASSISTANT
#UserFolder=/Users/yanchen
#d-i
anna/choose_modules multiselect migration-assistant
#d-i
migration-assistant/partitions multiselect Windows XP Professional
(/dev/MADEVICE)
#d-i migration-assistant/MADEVICE/users multiselect
yanchen
#d-i migration-assistant/MADEVICE/yanchen/items multiselect
AIM Triton, Internet Explorer, Yahoo, MSN, Opera, Firefox, Wallpaper,
User Picture, Outlook Express, Gaim
# d-i
migration-assistant/MADEVICE/hostuser/items multiselect My Documents,
Internet Explorer
#d-i migration-assistant/MADEVICE/yanchen/user
string ubuntu
# d-i migration-assistant/new-user/linuser/password
password xyz
# d-i
migration-assistant/new-user/linuser/password-again password xyz
#
d-i migration-assistant/new-user/linuser/fullname string fullusername
#
d-i migration-assistant/new-user/linuser/administrator boolean true
##
SHELL COMMANDS.
# d-i preseeding is inherently not secure. Nothing
in the installer checks
# for attempts at buffer overflows or other
exploits of the values of a
# preseed file like this one. Only use
preseed files from trusted
# locations! To drive that home, and
because it's generally useful, here's
# a way to run any shell
command you'd like inside the installer,
# automatically.
#
This first command is run as early as possible, just after
#
preseeding is read.
d-i preseed/early_command string [ -x
/custom-installation/hooks/early-command.sh ] &&
/custom-installation/hooks/early-command.sh
# This command is run
just before the install finishes, but when there is
# still a usable
/target directory.
#d-i preseed/late_command string echo foo >
/target/etc/bar
# d-i preseed/late_command string rm
/target/usr/lib/base-config/menu/apt-setup; rm
/target/usr/lib/base-config/menu/apt-setup.mnu
#~ d-i
preseed/late_command string /sbin/late_command
其中
Ubiquity一段调用了另外几个脚本,这里我们仍然借用wubi安装方法得到的文件,即Ubuntu/install/custom-
installation这个文件夹,我们需要做的是将我们配置好的preseed.cfg文件替换掉原来的文件,然后我们将custom-
installation这个文件夹拷贝到Live USB中。
接下来,我们需要在syslinux.cfg文件中添加对custom-
installation这个预置文件夹的指引。syslinux.cfg在Live
USB的syslinux文件夹下,如果是CD的话,对应的文件是isolinux文件夹下的isolinux.cfg。
在
syslinux.cfg文件里,在live-install的那段代码后增加如下这段代码:
代
码:
LABEL auto-install
menu label
^Install Ubuntu Automatically
kernel /casper/vmlinuz
append
boot=casper initrd=/casper/initrd.gz ro
debian-installer/custom-installation=/custom-installation
automatic-ubiquity noprompt quiet splash --
另外将DEFAULT和后面的
timetou改为如下所示:
代码:
DEFAULT auto-install
……
timeout 1
这
样的话,如果从Live USB启动,Ubuntu就会全自动安装而无需手动回答问题了。
如果是Live CD,则前面修改syslinux.cfg的地方全部换做isolinux.cfg就可以
了。同时Live CD还需要将这些安装文件整合成ISO镜像,在Ubuntu的终端下,输入如下命令可以帮我们做到:
代码:
sudo mkisofs
-r -cache-inodes \
-J -l -b isolinux/isolinux.bin -c
isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-o
ubuntu.iso path-of-install-file
其中,ubuntu.iso是输出的ISO镜像的名
称,path-of-install-file是这些安装文件所在的路径。ISO镜像制作完成之后,可以在虚拟机下进行安装,刻录成光盘?实用性好像不是
很大。
将预置文件放到server上,然后自动安装,还在学习中。
另外:我自己还有不懂的地方,请高人指点一二。
1.我通过以上预置文件制作的Live
USB,在实现自动安装的过程中,其他问题都能自动回答,只有在配置apt的时候,会弹出一个警告的消息,提示从光盘上读取apt信息错误,点击“确定”
后,安装也能顺利进行下去。而通过Live
CD安装过程中,则没有这个错误出现。两种方法使用的预置文件相同,我不知道我是什么地方配置错误了,请高人指点。
2.预置文件的分区信息中,关
于自定义分区,有下面这段代码:
代码:
#d-i partman-auto/expert_recipe string
\
# boot-root ::
\
# 40 50 100 ext3
\
# $primary{ } $bootable{ } \
#
method{ format } format{ } \
#
use_filesystem{ } filesystem{ ext3 } \
#
mountpoint{ /boot } \
#
. \
# 500
10000 1000000000 ext3 \
#
method{ format } format{ } \
#
use_filesystem{ } filesystem{ ext3 } \
#
mountpoint{ / } \
# .
\
# 64 512 300%
linux-swap \
# method{
swap } format{ } \
40,50,100这些数字代表什么含义。其中最后的
300%指的是内存大小的三倍。我通过自动分区方法得到的分区中有/和swap两个分区,其中swap分区是内存三倍,其他硬盘空间全部分给/。所以我知
道这里的300%的含义,那么其他的数字呢?请高人指点。
阅读(5471) | 评论(0) | 转发(0) |