Self-built KVM template second article

Source: Internet
Author: User

First, win platform
The win platform may involve two main issues, one is the host name and the template hostname duplicate, and the SID value will be the same as before.

1, change the host name

Set name=pc-%date:~2,2%%date:~5,2%%date:~8,2%%time:~6,2%%random:~0,3%
netdom renamecomputer%computername%/newname:%name%/force
Generate host names based on Point-in-time, avoid duplication of host names, or be interactive, as follows:

set/p name= Please lose your computer name:
WMIC ComputerSystem where "name= '%computername% '" Call rename%newname%
There is a netdom way to change, instead of WMIC mode change, provide a more method. There may be a lot of online changes based on the registry, personal feeling too cumbersome.

2. Modify SID

A SID is also a security Identifiers, a unique number that identifies users, groups, and computer accounts.

First through the PSGETSID program to view the SID value, the tool is a pstools, the system is not taken, can be downloaded through the following address: http://technet.microsoft.com/en-us/sysinternals/ Bb896649.aspx, look at the following methods:

If you do not modify this value to install a variety of services may have unexpected problems, win2003 after the system has been unable to use the NewSID generation, need to be rebuilt with the system's own Sysprep tool. The default path for the tool is C:windowssystem32sysprepsysprep.exe, which defaults to a graphical configuration interface (something Microsoft seems to be best at doing this), as follows:

But I still like to use the command to operate:

C:windowssystem32sysprepsysprep.exe/oobe/reboot
The above two functions are combined to write in batch processing, after the installation completes, runs directly under the batch processing to be OK. The commands for viewing system information are: SystemInfo, Nbtstat-n, PsGetSid.

Second, Linux Platform
There are two common problems with the main Linux platform, one host name problem, one IP address problem.

1, change the host name

There are two files involved, and the contents of the file may resemble the following:

#cat/etc/sysconfig/network
Networking=yes
Hostname=361way.com
#cat/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 361way 361way.com
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
This step can be easily implemented using a cat EOF script, as follows:

Cat << EOF >/etc/sysconfig/network
Networking=yes
Hostname=361way.com
Eof
Cat << EOF >/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 361way 361way.com
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Eof
After saving the above content as the sh script, the execution, will overwrite the original content completely, but the later host name often is an unknown name, at this time we can in the script through the reference way to fix, also may through the read interactive way solves, like:

#!/bin/bash
Read-p "Enter your hostname, like:361way.com!" "Name
echo "You hostname'll be change to $name"
Exit 0
All we have to do is to put the above $name in the cat EOF foot sentence and replace it with the variable in the OK.

2, IP address

The IP address needs to do two operations after doing the IMG mirroring module:

One is: Execute rm-rf/etc/udev/rules.d/70-persistent-net.rules the file, which is equivalent to a Mac and IP cache file, if you do not delete the file in the use of templates to create virtual machines (note, Mac when created) will still use the original template host's Mac in the file. The deletion does not affect the system, because the file is automatically regenerated when the system starts.

The second is: When the img template is done, do not configure the MAC address and UUID in the file/etc/sysconfig/network-scripts/ifcfg-eth0. Although the contents of the following file are to be replaced by a cat EOF statement, it is recommended that you take this step.

The contents of cat EOF are similar to the following:

Cat << EOF >/etc/sysconfig/network-scripts/ifcfg-eth0
Device=eth0
Type=ethernet
Onboot=yes
Nm_controlled=yes
#IPADDR =192.168.1.251
Prefix=24
netmask=255.255.255.0
gateway=192.168.1.1
#BOOTPROTO =DHCP
Eof
This can also be resolved in an interactive way. Here's the steps to interacting with Python:

#!/usr/bin/env python
Ip=raw_input (' Please input your ipaddress! ')
Print IP
Note that Python variables do not need to add $ symbol, so simple a feature is not recommended to use Python to implement, or shell more concise.

Iii. a new reflection
After completing the changes to the v2.0 version of the script, we found 3.0 requirements. To make the template more versatile, the guest host is ready to detach itself from the system count and the data disk, a similar approach to cloud platforms such as Aliyun and AWS. And whether the back of the data disk to be increased, how much space is needed, can also be implemented in the script. This function will be implemented when there is energy in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.