2010년 5월 2일 일요일

우분투 리눅스 설치 자동화에 도전해보다! - Preseeding

HP나 델에서 PC를 구매할 경우 윈도우가 설치되어 있기 때문에 사내 표준 데스크탑 운영체제가 윈도우일 경우 문제가 되지 않을 것이다. 하지만 사내 표준 데스크탑 시스템으로 리눅스를 사용한다면 어떨까? 국내에서 100명 이상이 근무하는 기업들 중 리눅스를 표준 데스크탑 시스템으로 사용하는 기업은 거의 없을 것이라 생각한다. 하지만 외국의 여러 기업들은 리눅스를 사내 표준 데스크탑으로 사용하고 있다. (참고 : 어떤 기업 혹은 단체에서 리눅스를 사용하나?) 100여대 이상의 데스크탑에 운영체제를 설치하는 일을 시간이 오래 걸리는 작업이며 또 단순 작업의 연속일 것이다.

자동화된 설치란 간단하게 말하면 운영체제 설치에 필요한 정보들을 특정 파일에 지정된 형식으로 작성하여 설치 과정에서 작업자의 일련의 입력 과정을 최소화한 방법이라고 할 수 있을 것이다. 운영체제 설치를 자동화하는 방법에는 윈도우에서는 무인 설치, 레드햇의 Kickstart, 우분투의 Preseed 등을 들 수 있다. 본 포스트에서는 우분투 10.04 LTS를 사용하여 자동화된 설치에 대해 알아보도록 한다.

본 포스트의 목적은 설치 대상 컴퓨터에서의 입력 과정을 가능한 최소화하고 더 나아가 동일한 컴퓨터에 적용할 수 있도록 표준화하는 것에 있다. 그리고 Lab환경 구축을 위해 VMware를 사용하였다.

1. 준비

설치 대상 데스크탑에서의 작업을 가능한 최소화하기 위해 CD 혹은 플로피디스켓을 이용한 부팅방법을 지양하고 네트워크 부팅을 이용할 것이다. 이를 위해서는 대상 컴퓨터가 PXE (Pre-boot eXecution Environment)을 지원해야 한다. 지원 여부는 BIOS를 확인해보기 바란다. 참고로 vmware의 가상 머신은 이를 지원한다. 하지만 서버쪽에서는 PXE 부팅을 위해 몇가지 준비해야할 것들이 있다.  

  • DHCP 서버 // 대상 컴퓨터의 IP 주소를 자동으로 할당한다
  • TFTP 서버 // 부팅에 필요한 커널을 내려준다
  • HTTP 서버 // 응답 파일(preseed.cfg)을 내려준다

위 서버들을 설치하기 전에 먼저 vmware에 서버로 사용할 시스템을 설치하도록 하자. 위 서버들을 실행할 수 있는 리눅스 배포판이면 된다. 여기서 편의상 우분투 시스템에 위 서버들을 설치하도록 하자. vmware에 우분투를 설치하는 방법은 따로 설명하지 않을 것이다. (참고 tsimson : [우분투 설치] 3. vmware에 설치)

DHCP 설치 및 설정

위에서 설명하였듯이 DHCP는 호스트에 IP 주소를 자동으로 할당한다. 우분투 시스템에 DHCP 서버를 설치하자. 

#apt-get install dhcp3-server


DHCP의 역할은 호스트에게 가용 IP 대역에서 하나를 할당하는 것뿐 아니라 TFTP 서버주소와 부팅 이미지에 대한 정보를 제공한다. dhcp 설치가 완료되면 /etc/dhcp3/dhcp.conf의 설정을 수정한다.

option domain-name-servers 8.8.8.8, 8.8.4.4 ; // 자신이 사용하는 DNS 서버주소를 사용한다. 본인은 외우기 쉬워 구글의 DNS를 선택하였다

default-lease-time 86400;

max-lease-time 604800;

authoritative;


subnet 192.168.111.0 netmask 255.255.255.0 { // vmware의 nat의 기본 IP 대역

        range 192.168.111.200 192.168.111.253;

        filename "pxelinux.0"; // 우분투 설치 부팅 이미지

        next-server 192.168.111.128; // TFTP 서버 주소

        option subnet-mask 255.255.255.0;

        option broadcast-address 192.168.111.255;

        option routers 192.168.111.2;

}

 
설정을 저장한 후 dhcp 서버를 가동시키자.

 # service dhcp3-server start

 
TFTP 설치 및 설정

주의 : tftp는 접속시 인증과정이 없기 때문에 실제 환경에서 사용할 때는 외부에서 접근이 되지 않도록 주의한다.

TFTP는 Trivial File Transfer Protocol의 약자로 보통 ftp와 유사하지만 일반 ftp와 달리 인증 과정이 없다. 다음 명령을 실행하면 tftp 서버가 설치된다.

 # apt-get install tftpd-hpa

 
tftp 서버를 선택할 때 한가지 주의해야할 사항은 'tsize' 옵션을 지원해야 한다는 점이다. tsize 옵션이 설정되어야 서버가 클라이언트에게 전송되는 파일의 크기를 보낼 수 있다.

설치가 완료되었으면 /etc/default/tftpd-hpa아래와 같이 추가 혹은 수정한다.

TFTP_USERNAME="nobody"

TFTP_DIRECTORY="/var/lib/tftpboot" // 중요 : 반드시 해당 디렉토리를 생성해주여야 한다

TFTP_ADDRESS="0.0.0.0:69"

TFTP_OPTIONS="--secure"


위 tftpboot 디렉토리가 없으면 nobody 권한으로 생성하도록 한다. tftp는 기본적으로 활성 상태가 아니기 때문에 아래 명령으로 활성화시킨다.

 # service tftpd-hpa start

 
명령어 'ss -ua'를 실행하면 tftp 서버가 실행되고 있는지 확인할 수 있다.

 # ss -ua

State      Recv-Q Send-Q      Local Address:Port          Peer Address:Port  

UNCONN     0      0                       *:bootps                   *:*      

UNCONN     0      0                       *:tftp                     *:*      

UNCONN     0      0                       *:mdns                     *:*      

UNCONN     0      0                       *:41714                    *:*      

 
HTTP 서버 설치 및 설정

preseeding 과정에서 웹서버는 설치 대상 컴퓨터에 응답 파일(preseed.cfg)을 전달하기 위해 반드시 필요하다. 따라서 자신이 사용하기 편한 웹서버를 선택하도록 하자.

 # apt-get install apache2


아파치 서버를 설치하면 자동으로 데몬이 구동되어 따로 설정할 것이 없다. 자동화된 설치를 위해서 응답파일(preseed.cfg)를 웹서버 루트 디렉토리(/var/www/)아래에 복사하면 끝이다. 응답 파일 작성은 아래에서 설명하도록 한다.

2. Netbooting에 필요한 파일 설치

우분투 부팅에 필요한 파일들을 우분투 사이트에서 내려 받아 tftp 루트디렉토리에 복사하도록 한다.

# wget http://ftp.ubuntu.com/ubuntu/dists/lucid/main/installer-i386/current/images/netboot/netboot.tar.gz

# cp netboot.tar.gz /var/lib/tftpboot/


tftp 루트디렉토리로 이동하여 내려 받은 파일의 압축을 푼다.

# cd /var/lib/tftpboot/

# tar zxvf netboot.tar.gz

 
이 시점에서 우분투를 설치할 컴퓨터를 켜면 네트워크로 부팅되며 아래와 같은 화면을 볼 수 있다. 설치 자동화를 위해서는 부팅 파라메터를 추가로 입력해야 한다. 하지만 설치 자동화를 위한 부팅 파라메터가 짧지 않고 수십대의 PC마다 입력하는 것은 시간 낭비일뿐만 아니라 입력 과정에서 실수라도 있으면 부팅을 다시해야 할 것이다. 이를 위해 부팅 화면을 수정하여 부팅 파라메터 입력 없이 설치가 진행되도록 하자.


부팅 화면과 관련된 파일들은 ubuntu-installer/i386/boot-screens/ 아래 존재한다. 설치 자동화를 위해 'Automated Install'이라는 메뉴 항목을 추가할 것이다. text.cfg 파일을 열어 아래와 같이 설정을 추가한다. 'Automated Install' 항목이 가장 상단에 위치할수 있도록 text.cfg의 위쪽에 삽입한다. 

 label automated

menu label ^Automated Install

menu default // 부팅 화면이 나타나면 커서가 이 메뉴에 위치하도록 한다

kernel ubuntu-installer/i386/linux

append auto=true priority=critical vga=normal initrd=ubuntu-installer/i386/initrd.gz url=http://192.168.111.128/preseed.cfg --quiet


 
저장한 후 대상 컴퓨터에서 부팅 화면을 확인해 보면 'Automated Install' 항목이 추가되어 있을 것이다. 



3. 응답 파일(preseed.cfg) 작성하기

응답 파일과 관련된 설정은 매우 다양하며 네트워크 설정, 패키지 선택 등에 대해 선택할 수 있도록 준비되어 있다. 이를 모두 설명하는 일을 매우 괴로운 일이니 넘어가기로 하자. 본인은 우분투에서 제공하는 예제 파일을 기초로 하여 필요한 부분을 수정하여 사용하였다. 우분투 사이트에서 예제를 구할 수 있으며 본 포스트에서 사용한 응답 파일은 아래와 같다. 간단히 설명하면 DHCP로부터 IP을 할당 받고 archive.ubuntu.com에서 ubuntu-desktop 패키지를 내려받아 설치할 것이다.

#### Contents of the preconfiguration file
### Localization
# Locale sets language and country.
d-i debian-installer/locale string ko_KR

# Keyboard selection.
# Disable automatic (interactive) keymap detection.
d-i console-setup/ask_detect boolean false
#d-i console-setup/modelcode string pc105
d-i console-setup/layoutcode string us

### Network configuration
# 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

# 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 unassigned-hostname
d-i netcfg/get_domain string unassigned-domain

# Disable that annoying WEP key dialog.
d-i netcfg/wireless_wep string


### Mirror settings
# If you select ftp, the mirror/country string does not need to be set.
d-i mirror/country string manual
d-i mirror/http/hostname string archive.ubuntu.com
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy string

# Suite to install.
d-i mirror/suite string lucid;

### Clock and time zone setup
# Controls whether or not the hardware clock is set to UTC.
d-i clock-setup/utc boolean true

# 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/Seoul

# Controls whether to use NTP to set the clock during the install
d-i clock-setup/ntp boolean true

### Partitioning
# Alternatively, you can specify a disk to partition. The device name must
# be given in traditional non-devfs format.
# Note: A disk must be specified, unless the system has only one disk.
# For example, to use the first SCSI/SATA hard disk:
#d-i partman-auto/disk string /dev/sda
# In addition, you'll need to specify the method to use.
# The presently available methods are: "regular", "lvm" and "crypto"
d-i partman-auto/method string lvm

# If one of the disks that are going to be automatically partitioned
# contains an old LVM configuration, the user will normally receive a
# warning. This can be preseeded away...
d-i partman-lvm/device_remove_lvm boolean true
# The same applies to pre-existing software RAID array:
d-i partman-md/device_remove_md boolean true
# And the same goes for the confirmation to write the lvm partitions.
d-i partman-lvm/confirm boolean true

# You can choose one of the three predefined partitioning recipes:
# - atomic: all files in one partition
# - home:   separate /home partition
# - multi:  separate /home, /usr, /var, and /tmp partitions
d-i partman-auto/choose_recipe select multi

# This makes partman automatically partition without confirmation, provided
# that you told it what to do using one of the methods above.
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true

### Account setup
# To create a normal user account.
d-i passwd/user-fullname string Desktop User
d-i passwd/username string secmaster
# Normal user's password, either in clear text
d-i passwd/user-password password Password1
d-i passwd/user-password-again password Password1

### Package selection
tasksel tasksel/first multiselect ubuntu-desktop

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

### Boot loader installation
# 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

### Finishing up the installation
# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note

### 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

이제 응답파일을 HTTP 루트디렉토리(/var/www/)에 복사한다. 이제 설치 대상 컴퓨터를 부팅하면 tftp로부터 부팅 이미지를 받고 응답 파일을 읽어 자동으로 패키지를 내려받아 설치할 것이다. 위 응답파일로 진행할 때 파티션 설정을 확인하는 과정에서 사용자 응답을 요구하니 참고하기 바란다. 정식 버전 릴리즈 후 다시 시도해보니파티션 과정에서 사용자 응답없이 진행된다. 아마도 개발과정의 버그가 아닐까 생각한다. 기회가 된다면 버그가 리포트되었는지 찾아보도록 해야겠다.

설치 후 추가 패키지를 설치하고자 한다면 preseed/late_command를 이용하자.
#d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh

댓글 2개:

  1. 우분투를 이용하여 설치를 진행할 때 'Installing Base System' 단계에서 83%까지 진행하다 멈추는 현상이 계속 발생한다. Vmware 내에서만 발생하는 현상인지 파악이 안되고 있다. 혹시나 해서 데비안에서 비슷한 설정으로 설치 자동화 과정을 진행하니 무리없이 진행되었다. 무슨 문제인지. 실제 PC를 가지고 테스트해봐야하나..

    답글삭제