게시물 2건
 
libguestfs-tools - virt-sysprep
글쓴이 : 최고관리자 날짜 : 2015-09-10 (목) 13:00 조회 : 5588
글주소 :
                                

virt-sysprep 설치
 :: 가상머신 이미지를 복제해서 사용할 수 있도록 reset or unconfigure
     로그및 기본설정을....초기화
# apt-get install libguestfs-tools 

# virt-sysprep -a ${IMG_NAME}
Examining the guest ...
Performing "yum-uuid" ...
Performing "utmp" ...
Performing "udev-persistent-net" ...
Performing "tmp-files" ...
Performing "sssd-db-log" ...
Performing "ssh-userdir" ...
Performing "ssh-hostkeys" ...
Performing "smolt-uuid" ...
Performing "script" ...
Performing "samba-db-log" ...
Performing "rpm-db" ...
Performing "rhn-systemid" ...
Performing "random-seed" ...
Performing "puppet-data-log" ...
Performing "password" ...
Performing "pam-data" ...
Performing "package-manager-cache" ...
Performing "pacct-log" ...
Performing "net-hwaddr" ...
Performing "net-hostname" ...
Performing "mail-spool" ...
Performing "machine-id" ...
Performing "logfiles" ...
Performing "hostname" ...
Performing "firstboot" ...
Performing "dovecot-data" ...
Performing "dhcp-server-state" ...
Performing "dhcp-client-state" ...
Performing "cron-spool" ...
Performing "crash-data" ...
Performing "blkid-tab" ...
Performing "bash-history" ...
Performing "abrt-data" ...
Performing "lvm-uuids" ...

example1) root 패스워드 설정
# virt-sysprep --root-password password:${PASSWORD} -a ${IMG_NAME}

example2) hostname 설정 
virt-sysprep --hostname -a ${IMG_NAME}

example3) firstboot vs script
The two options --firstboot and --script both supply shell scripts that are run against the guest.  However these two options are significantly different.
--firstboot script uploads the file "script" into the guest and arranges that it will run, in the guest, when the guest is next booted.  (The script will only run once, at the "first boot").
--script script runs the shell "script" on the host, with its current directory inside the guest filesystem.
If you needed, for example, to "yum install" new packages, then you must not use --script for this, since that would (a) run the "yum" command on the host and (b) wouldn't have access to the same resources (repositories, keys, etc.) as the guest.  Any command that needs to run on the guest must be run via --firstboot.
On the other hand if you need to make adjustments to the guest filesystem (eg. copying in files), then --script is ideal since (a) it has access to the host filesystem and (b) you will get immediate feedback on errors. Either or both options can be used multiple times on the command line.

두 옵션은 GuestOS가 부팅시에 스크립트를 동작시키는 점에서는 같으나 차이점이 존재한다.
옵션 적용시 --firstboot, --script 모두 /tmp/XXXX 디렉토리를 마운트 시키고 작업
--firstboot : 스크립트를 GuestOS에 업로드 시키고 첫번째 부팅시 GuestOS 에서 실행
--script : HOST(부모 시스템)내에 있는 스크립트를 실행

--firstboot
# cat > test_firstboot.sh
#!/bin/bash
touch /root/test.img
touch /root/test2.img
touch /root/test3.img
virt-sysprep --firstboot test_firstboot.sh -a ${IMG_NAME}

script 삽입위치 
# ls -l /mnt/etc/rc.d/rc3.d/S99virt-sysprep-firstboot 
lrwxrwxrwx 1 root root 34  9월 10 15:52 /etc/rc.d/rc3.d/S99virt-sysprep-firstboot -> /usr/lib/virt-sysprep/firstboot.sh

# cat /usr/lib/virt-sysprep/firstboot.sh 
#!/bin/sh -

### BEGIN INIT INFO
# Provides:          virt-sysprep
# Required-Start:    $null
# Should-Start:      $all
# Required-Stop:     $null
# Should-Stop:       $all
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# Short-Description: Start scripts to run once at next boot
# Description:       Start scripts to run once at next boot
# These scripts run the first time the guest boots,
# and then are deleted. Output or errors from the scripts
# are written to ~root/virt-sysprep-firstboot.log.
### END INIT INFO

d=/usr/lib/virt-sysprep/scripts
logfile=~root/virt-sysprep-firstboot.log

echo "$0" "$@" >>$logfile
echo "scripts dir: $d" >>$logfile

if test "$1" = "start"
then
  for f in $d/* ; do
    if test -x "$f"
    then
      echo '=== Running' $f '===' >>$logfile
      $f >>$logfile 2>&1
      rm -f $f
    fi
  done
fi

# ls -l /mnt/usr/lib/virt-sysprep/scripts/0001-1441867932-azw3p6uu 
# tree
.
├── firstboot.sh
└── scripts
    └── 0001-1441867932-azw3p6uu    =>> 부팅이후 삭제
1 directory, 2 files
==>> 첫부팅이후 해당 위치에 파일들은 실행스크립트만 제외하고 그대로 위치되어있음 
※ VM 동작중에 작업을 하게 될경우 재시작과정에서 파일시스템 에러 발생


--script 
  :: 스크립트 경로와 퍼미션 주의
     VM이 켜지는 순간에 스크립트 실행
# chmod +x script.sh
virt-sysprep --script ${PATH}/test_firstboot.sh -a ${IMG_NAME}
※ VM 동작중에 작업을 하게 될경우 스크립트는 바로 실행됨


help
# virt-sysprep --version
virt-sysprep 1.24.5 (1.20.x 에서는 password 옵션은 존재하지 않음)


이름 패스워드
비밀글 (체크하면 글쓴이만 내용을 확인할 수 있습니다.)
왼쪽의 글자를 입력하세요.
 

 



 
사이트명 : 모지리네 | 대표 : 이경현 | 개인커뮤니티 : 랭키닷컴 운영체제(OS) | 경기도 성남시 분당구 | 전자우편 : mojily골뱅이chonnom.com Copyright ⓒ www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.