Windows Server Core 2016 Initial (XenServer) Template Setup

After installing Windows Server Core 2016 you might wander what to do with yourself next. If, like most people, you have always used Windows via the GUI then you are entering a whole new world. Being presented with only a CMD window on startup will be a little daunting at first. But you will learn how to drive it with a little practise. Here are some tips to get you started with configuring your first Server Core install and converting it to a Template so that you can create many more instances.

server core first command
The Windows Server Core 2016 User Interface

Launching Programs

As you have probably already noticed, Windows Server Core does still have a GUI of sorts. There is still a desktop that the CMD window sits on. You can also still open and run programs. For example:
notepad will launch a notepad window.
taskmgr will launch the Task Manager.
powershell will launch a powershell session (in the current CMD window)
start powershell will launch a seperate powershell window.

server core programs
Programs running in Windows Server Core 2016

These programs can still be minimised and maximised, they just don’t sit on a ‘Task Bar’. Instead they just minimise down to small tiles that live along the bottom of the screen. For those of you that used Windows 3.1 you will remember how this works (showing my age here).

minimised programs on server core
Minimised programs on Windows Server Core 2016

Installing XenTools

  • Insert the XenTools ISO into the VM via XenCenter
  • start powershell to open a seperate powershell window because it’s much more… powerful.
  • cd d: to change to our CD drive (replace d: with whatever letter your CD drive would be)
  • start .\Setup.exe to launch the setup wizard. Even though we have no GUI, this will still run like it always has.
  • Run through the wizard selecting the usual options. I usually disable the automatic updates for better control.

Configuring the Basics

The ‘Server Configuration’ command line utility is a great way to configure the basic settings on your server to get it on the network and connected to your domain etc. This screen may just handle the bulk of the configuration that you require on your server. You can launch it from CMD or powershell by typing sconfig.

sconfig-main-menu
Windows Server Configuration Utility Main Menu

Network Settings

  • sconfig
  • Select option 8) Network Settings
  • Follow the prompts to configure your network adapters

Remote Desktop

  • sconfig
  • Select option 7) Remote Desktop
  • At this point you should be able to connect to the VM via XenCenter’s Remote Desktop console or any orther RDP client.

Windows Updates

  • sconfig
  • Select option 6) Download and Install Updates
  • Follow the prompts to install your updates.

NB: If you are behind a firewall or on a private network with no Internet access, you may need to point your VM at a WSUS server.

Configuring Windows Updates to point to a WSUS Server

If you have a WSUS server on your LAN, you can configure the VM to use it by substituting the relevant address into the commands below. For example for servers on Softlayer/IBM’s private LAN you can use http://wsus01.service.softlayer.com. This may not be required if you push out the WSUS settings via a Group Policy on your domain. I always like to do updates before I join VM’s to the domain though, just out of habit (best practise?).

  • start powershell
  • Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name WUServer -Value http://your.wsus.hostname
  • Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name WUStatusServer -Value http://your.wsus.hostname
  • Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name UseWUServer -Value 1
  • To check that these registry settings have all saved properly you can use the powershell Get-Item commandlet:
  • Get-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
  • Get-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
  • If you re-run the Windows Updates in sconfig now you should now pull updates from the WSUS server.

In the old ‘GUI’ days, this would have done this by opening MMC, adding the Group Policy Snap-in and then finding the policies that control the registry keys we are editing here. MMC does not come with Server Core but you can connect to it from a remote ‘full install’ windows machine that has MMC. There is some setup required to make this work however which I won’t cover here.

Converting the VM to a Template (SysPrep)

To convert this VM to a template we need to ‘reset’ Windows using the System Preparation Tool. This will mean that when we clone the VM Template we will be creating a fresh new VM rather than a copy of the existing one with the same hostname etc.

sysprep
System Preparation Tool
  • start powershell
  • C:\Windows\System32\Sysprep\sysprep.exe
  • Under System Cleanup Action select Enter System Out-of-Box Experience (OOBE)
  • Tick Generalize
  • Under Shutdown Options select Shutdown
  • Wait for the VM to completely shutdown
  • In XenCenter, right click the VM
  • Select Convert to Template…
  • Click Convert
  • The template is now ready to be used to create new VM from

Creating a new VM

  • In XenCenter, click VM (Top Menu)
  • Select New VM…
  • Select the template you just created
  • Continue through the wizard selecting the relevant options.

In the next post I’ll show you how to configure our new VM as an IIS server.

Removing Old Kernel Images from /lib/modules

So using my handy-dandy ‘HDGraph for Linux’ command, I recently identified an Ubuntu (10.04.4 LTS) server that had a bloated /lib/modules directory.

me@there:/lib/modules$ ls -al
total 140
drwxr-xr-x 33 root root  4096 2017-06-02 18:10 .
drwxr-xr-x 13 root root 12288 2015-04-02 06:42 ..
drwxr-xr-x  4 root root  4096 2014-05-29 12:25 2.6.32-41-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:25 2.6.32-42-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:25 2.6.32-43-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:25 2.6.32-44-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:25 2.6.32-45-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:25 2.6.32-46-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:26 2.6.32-47-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:26 2.6.32-48-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:26 2.6.32-49-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:26 2.6.32-50-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:26 2.6.32-51-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:26 2.6.32-52-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:27 2.6.32-53-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:27 2.6.32-54-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:27 2.6.32-55-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:27 2.6.32-56-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:27 2.6.32-57-generic
drwxr-xr-x  4 root root  4096 2014-05-29 12:27 2.6.32-58-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:55 2.6.32-60-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:55 2.6.32-61-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:55 2.6.32-62-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:55 2.6.32-64-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:56 2.6.32-65-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:56 2.6.32-66-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:56 2.6.32-67-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:56 2.6.32-68-generic
drwxr-xr-x  4 root root  4096 2015-01-16 16:56 2.6.32-70-generic
drwxr-xr-x  4 root root  4096 2017-03-29 16:08 2.6.32-71-generic
drwxr-xr-x  4 root root  4096 2017-03-29 16:08 2.6.32-72-generic
drwxr-xr-x  4 root root  4096 2017-03-29 16:08 2.6.32-73-generic
drwxr-xr-x  4 root root  4096 2015-04-30 06:52 2.6.32-74-generic

These files are most likely on your system because you have automatic apt-get updates enabled, which is a good thing, but disk space is important also. It should be fine to remove the files, but files that are related to system updates, especially anything that mentions the ‘kernel’ make me nervous, how about you?

After a small amount of googling to see whether it was safe to just delete these files or not, I think I found the ‘correct’ way to clean them up.

One guy suggested using ‘sudo apt-get autoremove’ but this didn’t help at all.

Another forum thread had a suggestion to use the dpkg command with the -r or ‘remove’ parameter. This not only removes the large file itself but also marks the debian package that created the file as ‘removed’ (and it probably does some other cool stuff that will stop you having problems later on also).

If you are anything like me, you will want to understand things a little bit better before blindly copying and pasting commands that you have never seen before. So here goes:

To list all installed packages:
me@there:/lib/modules$ sudo dpkg-query -l | grep linux-image

To show only the relevant entries:

me@there:/lib/modules$ sudo dpkg-query -l | grep linux-image
rc  linux-image-2.6.32-40-generic   2.6.32-40.87                        Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-41-generic   2.6.32-41.91                        Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-42-generic   2.6.32-42.96                        Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-43-generic   2.6.32-43.97                        Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-44-generic   2.6.32-44.98                        Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-45-generic   2.6.32-45.104                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-46-generic   2.6.32-46.108                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-47-generic   2.6.32-47.109                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-48-generic   2.6.32-48.110                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-49-generic   2.6.32-49.111                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-50-generic   2.6.32-50.112                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-51-generic   2.6.32-51.113                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-52-generic   2.6.32-52.114                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-53-generic   2.6.32-53.115                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-54-generic   2.6.32-54.116                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-55-generic   2.6.32-55.117                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-56-generic   2.6.32-56.118                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-57-generic   2.6.32-57.119                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-58-generic   2.6.32-58.121                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-60-generic   2.6.32-60.122                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-61-generic   2.6.32-61.124                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-62-generic   2.6.32-62.126                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-64-generic   2.6.32-64.128                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-65-generic   2.6.32-65.131                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-66-generic   2.6.32-66.132                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-67-generic   2.6.32-67.134                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-68-generic   2.6.32-68.135                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-70-generic   2.6.32-70.137                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-71-generic   2.6.32-71.138                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-72-generic   2.6.32-72.139                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-73-generic   2.6.32-73.141                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-2.6.32-74-generic   2.6.32-74.142                       Linux kernel image for version 2.6.32 on x86
ii  linux-image-generic             2.6.32.74.81                        Generic Linux kernel image

Now that we can see all the relevant info, let’s try deleting the oldest package:

me@there:/lib/modules$ sudo dpkg -r linux-image-2.6.32-41-generic 
(Reading database ... 148158 files and directories currently installed.)
Removing linux-image-2.6.32-41-generic ...
Running postrm hook script /usr/sbin/update-grub.
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-74-generic
Found initrd image: /boot/initrd.img-2.6.32-74-generic
Found linux image: /boot/vmlinuz-2.6.32-73-generic
Found initrd image: /boot/initrd.img-2.6.32-73-generic
Found linux image: /boot/vmlinuz-2.6.32-72-generic
Found initrd image: /boot/initrd.img-2.6.32-72-generic
Found linux image: /boot/vmlinuz-2.6.32-71-generic
Found initrd image: /boot/initrd.img-2.6.32-71-generic
Found linux image: /boot/vmlinuz-2.6.32-70-generic
Found initrd image: /boot/initrd.img-2.6.32-70-generic
Found linux image: /boot/vmlinuz-2.6.32-68-generic
Found initrd image: /boot/initrd.img-2.6.32-68-generic
Found linux image: /boot/vmlinuz-2.6.32-67-generic
Found initrd image: /boot/initrd.img-2.6.32-67-generic
Found linux image: /boot/vmlinuz-2.6.32-66-generic
Found initrd image: /boot/initrd.img-2.6.32-66-generic
Found linux image: /boot/vmlinuz-2.6.32-65-generic
Found initrd image: /boot/initrd.img-2.6.32-65-generic
Found linux image: /boot/vmlinuz-2.6.32-64-generic
Found initrd image: /boot/initrd.img-2.6.32-64-generic
Found linux image: /boot/vmlinuz-2.6.32-62-generic
Found initrd image: /boot/initrd.img-2.6.32-62-generic
Found linux image: /boot/vmlinuz-2.6.32-61-generic
Found initrd image: /boot/initrd.img-2.6.32-61-generic
Found linux image: /boot/vmlinuz-2.6.32-60-generic
Found initrd image: /boot/initrd.img-2.6.32-60-generic
Found linux image: /boot/vmlinuz-2.6.32-58-generic
Found initrd image: /boot/initrd.img-2.6.32-58-generic
Found linux image: /boot/vmlinuz-2.6.32-57-generic
Found initrd image: /boot/initrd.img-2.6.32-57-generic
Found linux image: /boot/vmlinuz-2.6.32-56-generic
Found initrd image: /boot/initrd.img-2.6.32-56-generic
Found linux image: /boot/vmlinuz-2.6.32-55-generic
Found initrd image: /boot/initrd.img-2.6.32-55-generic
Found linux image: /boot/vmlinuz-2.6.32-54-generic
Found initrd image: /boot/initrd.img-2.6.32-54-generic
Found linux image: /boot/vmlinuz-2.6.32-53-generic
Found initrd image: /boot/initrd.img-2.6.32-53-generic
Found linux image: /boot/vmlinuz-2.6.32-52-generic
Found initrd image: /boot/initrd.img-2.6.32-52-generic
Found linux image: /boot/vmlinuz-2.6.32-51-generic
Found initrd image: /boot/initrd.img-2.6.32-51-generic
Found linux image: /boot/vmlinuz-2.6.32-50-generic
Found initrd image: /boot/initrd.img-2.6.32-50-generic
Found linux image: /boot/vmlinuz-2.6.32-49-generic
Found initrd image: /boot/initrd.img-2.6.32-49-generic
Found linux image: /boot/vmlinuz-2.6.32-48-generic
Found initrd image: /boot/initrd.img-2.6.32-48-generic
Found linux image: /boot/vmlinuz-2.6.32-47-generic
Found initrd image: /boot/initrd.img-2.6.32-47-generic
Found linux image: /boot/vmlinuz-2.6.32-46-generic
Found initrd image: /boot/initrd.img-2.6.32-46-generic
Found linux image: /boot/vmlinuz-2.6.32-45-generic
Found initrd image: /boot/initrd.img-2.6.32-45-generic
Found linux image: /boot/vmlinuz-2.6.32-44-generic
Found initrd image: /boot/initrd.img-2.6.32-44-generic
Found linux image: /boot/vmlinuz-2.6.32-43-generic
Found initrd image: /boot/initrd.img-2.6.32-43-generic
Found linux image: /boot/vmlinuz-2.6.32-42-generic
Found initrd image: /boot/initrd.img-2.6.32-42-generic
Found memtest86+ image: /boot/memtest86+.bin
done

Now the file should be gone from /lib/modules. This can be confirmed by running ls -alh /lib/modules.

If you run the sudo dpkg-query -l | grep linux-image command again you will notice that the package still shows up, but it now has an ‘rc’ listed next to it rather than an ‘ii’. This means that rather than having an installed status, the package status is now ‘Config-Files’ and the desired action is ‘Remove’ rather than ‘Install’.

Now just repeat the process for each remaining file in the folder to clean up as much disk space as you require. It might be prudent to leave the few most recent ones just in case you need to switch between kernel versions later or something along those lines (I really don’t know what the best practise is here, please let me know in the comments if you do).

To check your disk is now nice and healthy of course you can use df -h.

Enjoy! 🙂

HDGraph Equivalent for *nix Command Line

We all run low or run out of disk space every now and then. In fact, I’ve found as a sysadmin that this is one of the more frequent and annoying problems that pop up. Especially if you don’t have an easy way to figure out what is using all of that disk space.

I use HDGraph on Windows systems to do this and find it really helpful. I couldn’t live without it. Well I could, but I would have no storage left. There are some similar tools available for Linux desktops and Mac OS X also but on a headless Linux server all you have is the command line and your wits.

After a lot of googling, I found this great little command will help you find large files/folders on a Linux system. Well perhaps little is not the best choice of words, and it’s not super user friendly, but it does a great job.

The path in the command can be changed to focus on a specific folder. So to be very general you could start at / and then work your way into the biggest folder until you figure out where all that disk space has gone.

Show top 10 largest files or sub-folders in /var:
sudo du -a /var | sort -n -r | head -n 10

Show top 20 largest files or subfolders in the root folder /:
sudo du -a / | sort -n -r | head -n 20

Show the 11th-20th largest files in /var/log/:
sudo du -a /var/log/ | sort -n -r | head -n 20 | tail -n 10

The beauty of this command is that it uses standard utilities that are included with almost all *nix based operating systems including Linux and Mac OS X.

If you get this error then your hard drive is most likely 100% full and you may need to do some manual cleaning up first before you can start using the above command.
sort: write failed: /tmp/sort0uH5NO: No space left on device

Take a quick look in your home folder and in the log folders to see if there are a couple of files that you could do without. You should only need to clear a few KB of space before our handy-dandy command will have enough room to work with.

Home Directory:
cd /home/[username] or simply cd ~
rm someoldfile.1

Log Folders:
cd /var/log/
rm someoldlog.5.gz