• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Yellow Bricks

by Duncan Epping

  • Home
  • ESXTOP
  • Stickers/Shirts
  • Privacy Policy
  • About
  • Show Search
Hide Search

Scripted install

Duncan Epping · Jun 27, 2008 ·

A while back I wrote a scripted install aka “cfg” file, and I just noticed I never published it. Check it out, it might be useful in one way or another. It also available for download here!

Especially changing the amount of active nics in a team can be useful(I’ve commented this out again, as of ESX 3.5 U3 this isn’t necessary anymore. Enabling vmotion via the vimsh command is still valid. This changed since ESX 3.5. Setting IP-Hash was also a nice one to figure out


# Regional Settings
keyboard us
lang en_US
langsupport --default en_US
timezone Europe/Amsterdam

# Installatition settings
skipx
mouse none
firewall --disabled
# Unencrypted root password:
rootpw --iscrypted
reboot
install

# Driver disks

# Load drivers

# Bootloader options
bootloader --location=mbr --driveorder=sda

# Authentication
auth --enableshadow --enablemd5

# Partitioning
clearpart --all --drives=sda --initlabel
part /boot --fstype ext3 --size=250 --ondisk sda --asprimary
part / --fstype ext3 --size=6144 --ondisk sda --asprimary
part /var/log --fstype ext3 --size=2048 --ondisk sda
part swap --size=1600 --ondisk sda --asprimary
part /tmp --fstype ext3 --size=1024 --ondisk sda
part None --fstype vmkcore --size=110 --ondisk sda
part None --fstype vmfs3 --size=1 --grow --ondisk sda

# Network Configurations # VARIABEL
network --device eth0 --bootproto static --ip 10.40.254.201 --netmask 255.255.254.0 --nameserver 10.40.1.251 --hostname esx01.yellow-bricks.local --addvmportgroup=0

# VMWare License options
vmaccepteula
vmlicense --mode=server [email protected] --edition=esxfull --features=backup,vsmp

%vmlicense_text

%packages
@base

%post

cat > /tmp/esxcfg.sh <

#!/bin/sh

# enable SSH root-access
mv /etc/ssh/sshd_config /etc/ssh/sshd_config.old
/bin/sed -e "s/PermitRootLogin no/PermitRootLogin yes/g" /etc/ssh/sshd_config.old > /etc/ssh/sshd_config
/etc/init.d/sshd restart

# Upsize console memory
mv -f /etc/vmware/esx.conf /etc/vmware/esx.conf.old
/bin/sed -e 's/boot\/memSize = \"272\"/boot\/memSize = \"800\"/g' /etc/vmware/esx.conf.old >> /etc/vmware/esx.conf
mv -f /boot/grub/grub.conf /tmp/grub.conf.bak
/bin/sed -e 's/uppermem 277504/uppermem 818176/g' -e 's/mem=272M/mem=800M/g' /tmp/grub.conf.bak >> /boot/grub/grub.conf

# DNS and Gateway
mv /etc/resolv.conf /etc/resolv.conf.old
echo "search yellow-bricks.local" >> /etc/resolv.conf
echo "nameserver 10.40.1.251" >> /etc/resolv.conf
echo "nameserver 10.40.1.252" >> /etc/resolv.conf
echo "GATEWAY=10.40.254.1" >> /etc/sysconfig/network

# set uselunreset enabled and devicereset disabled
/usr/sbin/esxcfg-advcfg -s 0 /Disk/UseDeviceReset
/usr/sbin/esxcfg-advcfg -s 1 /Disk/UseLunReset

# set queuedepth for qlogic adapter
/usr/sbin/esxcfg-module -s ql2xmaxqdepth=64 qla2300_707_vmw
/usr/sbin/esxcfg-boot -b

# add extrra nic to vSwitch0
/usr/sbin/esxcfg-vswitch -L vmnic3 vSwitch0

# Create a vswitch with 2 nics, a vlan and ip-hash
/usr/sbin/esxcfg-vswitch -a vSwitch1
/usr/sbin/esxcfg-vswitch -A "Server vlan 10" vSwitch1
/usr/sbin/esxcfg-vswitch -L vmnic1 vSwitch1
/usr/sbin/esxcfg-vswitch -L vmnic4 vSwitch1

# Create a vswitch with 2 nics, a vlan
/usr/sbin/esxcfg-vswitch -a vSwitch2
/usr/sbin/esxcfg-vswitch -A VMotion vSwitch2
/usr/sbin/esxcfg-vswitch -L vmnic2 vSwitch2
/usr/sbin/esxcfg-vswitch -L vmnic5 vSwitch2
/usr/sbin/esxcfg-vmknic -a VMotion -i 10.40.199.201 -n 255.255.255.0
sleep 3

# refresh nic settings with vimsh
/usr/bin/vimsh -n -e "hostsvc/net/refresh"
/usr/bin/vimsh -n -e "internalsvc/refresh_network"

# Obsolete as of ESX 3.5 U3
# Active and standby setup and maxActive from 1 to 2
# mv /etc/vmware/esx.conf /tmp/esx.conf.bak
# /bin/sed -e 's/net\/vswitch\/child\[0001\]\/teamPolicy\/maxActive = \"1\"/net\/vswitch\/child\[0001\]\/teamPolicy\/maxActive = \"2\"/g' /tmp/esx.conf.bak >> /etc/vmware/esx.conf

/usr/bin/vimsh -n -e "hostsvc/net/portgroup_set --nicorderpolicy-active=vmnic2 --nicorderpolicy-standby=vmnic5 vSwitch2 VMotion"
/usr/bin/vimsh -n -e "hostsvc/net/portgroup_set --nicorderpolicy-active=vmnic0 --nicorderpolicy-standby=vmnic3 vSwitch0 'Service Console'"

/usr/bin/vimsh -n -e "hostsvc/net/refresh"
/usr/bin/vimsh -n -e "internalsvc/refresh_network"

# Activiate IP Hash and 2 actieve nics on vSwitch1
/usr/sbin/esxcfg-vswitch -U vmnic1 vSwitch1
sleep 3
/usr/sbin/esxcfg-vswitch -U vmnic4 vSwitch1
sleep 3
/usr/sbin/esxcfg-vswitch -L vmnic1 vSwitch1
sleep 3
/usr/sbin/esxcfg-vswitch -L vmnic4 vSwitch1
sleep 5
/usr/bin/vimsh -n -e "hostsvc/net/refresh"
/usr/bin/vimsh -n -e "internalsvc/refresh_network"

/usr/bin/vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy=loadbalance_ip vSwitch1"

# VLAN ID portgroups
/usr/sbin/esxcfg-vswitch -p "Server vlan 10" -v 10 vSwitch1
/usr/sbin/esxcfg-vswitch -p VMotion -v 199 vSwitch2
sleep 5
/usr/bin/vimsh -n -e "hostsvc/net/refresh"
/usr/bin/vimsh -n -e "internalsvc/refresh_network"

# fill up Host file
rm -rf /etc/hosts
echo "# Do not remove the following line, or various programs" >> echo /etc/hosts
echo "# that require network functionality will fail." >> /etc/hosts
echo "127.0.0.1 localhost.localdomain localhost" >> /etc/hosts
echo "10.40.254.201 esx01.yellow-bricks-nhn.local esx01" >> /etc/hosts
echo "10.40.254.202 esx02.yellow-bricks.local esx02" >> /etc/hosts
echo "10.40.254.200 vc01.yellow-bricks.local vc01" >> /etc/hosts

# enable and configure ntp
/usr/sbin/esxcfg-firewall --enableService ntpClient
mv /etc/ntp.conf /etc/ntp.conf.old
mv /etc/ntp/step-tickers /etc/ntp/step-tickers.old
echo "restrict 127.0.0.1" >> /etc/ntp.conf
echo "restrict default kod nomodify notrap" >> /etc/ntp.conf
echo "server 10.40.254.11" >> /etc/ntp.conf
echo "server 10.40.254.12" >> /etc/ntp.conf
echo "driftfile /var/lib/ntp/drift" >> /etc/ntp.conf
echo "10.40.254.11" >> /etc/ntp/step-tickers
echo "10.40.254.12" >> /etc/ntp/step-tickers
/sbin/chkconfig --level 345 ntpd on
/etc/init.d/ntpd restart
/sbin/hwclock --systohc

# Enable VMotion
/usr/bin/vimsh -n -e "hostsvc/vmotion/vnic_set vmk0"

/etc/init.d/mgmt-vmware restart

EOF1

/bin/chmod 755 /tmp/esxcfg.sh
cp /etc/rc.d/rc.local /etc/rc.d/rc.local.bak
cat >> /etc/rc.d/rc.local <
cd /tmp
/tmp/esxcfg.sh
mv -f /etc/rc.d/rc.local.bak /etc/rc.d/rc.local
EOF

Share it:

  • Tweet

Related

Management & Automation, Server 3.5, ESX, Scripting, VMware

Reader Interactions

Comments

  1. Virgil says

    30 June, 2008 at 03:55

    May I introduce you to perl -pie?

    # enable SSH root-access
    mv /etc/ssh/sshd_config /etc/ssh/sshd_config.old
    /bin/sed -e “s/PermitRootLogin no/PermitRootLogin yes/g” /etc/ssh/sshd_config.old > /etc/ssh/sshd_config

    becomes:

    # enable SSH root-access
    perl -p -i.old -e “s/PermitRootLogin no/PermitRootLogin yes/g” /etc/ssh/sshd_config

    Virgil

  2. Jonathan says

    3 July, 2008 at 03:02

    Thanks for posting this. I spent quite a few hours sorting out a proper .cfg file. But I was wondering if you could explain the reason you included these lines:

    # set uselunreset enabled and devicereset disabled
    /usr/sbin/esxcfg-advcfg -s 0 /Disk/UseDeviceReset
    /usr/sbin/esxcfg-advcfg -s 1 /Disk/UseLunReset

    # set queuedepth for qlogic adapter
    /usr/sbin/esxcfg-module -s ql2xmaxqdepth=64 qla2300_707_vmw.o

    We use qlogic adapters in our blade servers and I didn’t know optimal depth was 64.

  3. Duncan says

    3 July, 2008 at 07:39

    Check the SAN Guide for more specific details but in short:
    UseDeviceReset and UseLunReset is used for SAN’s. Setting Device to 0 and Lun to 1 results in only that LUN’s SCSI reservations being reset instead of the complete device. This is recommended for SAN’s cause there will be several hosts connected to the same system. Resetting the device could cause disruption in services.

    The queuedepth is something that I’ve experienced as in being the best value, and is a generally accepted value. Check the VMTN forum for more info on this.

  4. Hugo says

    11 February, 2009 at 16:16

    Duncan,

    What are the differences between these and is the second command required?

    hostsvc/net/refresh
    internalsvc/refresh_network

    Thanks,

    Hugo

  5. dawoo says

    20 October, 2009 at 11:07

    Thanks for the script, very useful.

    During my build I dropped the KS.cfg and jumped on the post build configuration. The environment I’m upgrading has a lot of Port Groups leaving a huge scope for error in a mis-type, especially for 17 x ESX 3.5 boxes.

    One item I noticed didn’t seem to work on my 3.5 Update 4 was the vMotion enable. From the reading of various blogs it appears the VMware hidden commands change over versions so I’ve included the line from my script here.

    I hope this is useful for anyone else choosing the scripting path.

    All one line:

    vmware-cim-cmd “hostsvc/vmotion/vnic_set” `esxcfg-vmknic -l | grep “VMotion” | awk ‘{print $1}`

    Regards,
    Darren.

  6. CP Cheats says

    29 December, 2009 at 16:56

    Your RSS feed is only working every now and then, i’m on a imac running shrook if that helps

  7. Club Penguin says

    13 February, 2010 at 20:48

    Great Post it just helped me a ton

  8. forex says

    20 September, 2010 at 13:18

    When I read a great blog post I do a few things:1.Show it to the close contacts.2.save it in all my best social bookmarking websites.3.Be sure to come back to the same website where I read the post.After reading this article I’m seriously concidering doing all of the above.

  9. Dale Dauila says

    24 September, 2010 at 09:24

    Exactly where can it be, i like you just read more about this particular posting, thank you.

  10. jackson says

    20 May, 2013 at 10:24

    hi, how to add drivers installation in script format of ks.cfg file
    i used ks.cfg file looking like..

    #
    # Sample scripted installation file
    #
    # Accept the VMware End User License Agreement
    vmaccepteula
    # Set the root password for the DCUI and Tech Support Mode
    rootpw password
    # Set the keyboard
    keyboard ‘US Default’
    # The install media is in the CD-ROM drive
    install –firstdisk –overwritevmfs
    #driver installation
    # Set the network to static on the first network adapater
    network –bootproto=static –device=vmnic0 –ip=10.0.3.44 –netmask=255.255.248.0 –gateway=10.0.0.14 –nameserver=10.0.0.4 –hostname=’amiindia’
    reboot
    %firstboot –interpreter=busybox
    esxcli software vib install -v /scsi-lpfc820-8.2.4.141.55-1OEM.500.0.0.472560.x86_64.vib
    reboot
    # A sample post-install script
    %post –interpreter=python –ignorefailure=true
    import time
    stampFile = open(‘/finished.stamp’, mode=’w’)
    stampFile.write( time.asctime() )

    can any help which command we have to use for driver installation any one can help with examples….

Primary Sidebar

About the author

Duncan Epping is a Chief Technologist in the Office of CTO of the Cloud Platform BU at VMware. He is a VCDX (# 007), the author of the "vSAN Deep Dive", the “vSphere Clustering Technical Deep Dive” series, and the host of the "Unexplored Territory" podcast.

Upcoming Events

Feb 9th – Irish VMUG
Feb 23rd – Swiss VMUG
March 7th – Dutch VMUG
May 24th – VMUG Poland
June 1st – VMUG Belgium

Recommended Reads

Sponsors

Want to support Yellow-Bricks? Buy an advert!

Advertisements

Copyright Yellow-Bricks.com © 2023 · Log in