°Ô½Ã¹° 1,358°Ç
   
libguestfs-tools - virt-sysprep
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2015-09-10 (¸ñ) 13:00 Á¶È¸ : 9887
±ÛÁÖ¼Ò :
                                

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.