Playing with LXD containers

Lately I have been playing around with LXD containers, and its actually pretty cool.

Lets create a new container:

lxc-create -t download -n TestCont

This will download the default Ubuntu image from the official repository and create a container named TestCont.

Fire it up with “lxc-start -n TestCont”, connect to it with “lxc-attach -n TestCont”. Now you are in the shell of your new container.

Install dnsmasq, configure it for DHCP and DNS and assign IP’s to your containers based on Name or MAC address. The entry in the dnsmasq conf file should look something like this:

dhcp-host=TestCont,10.0.0.205

Lets create 10 new containers, have them set to autostart, fire them up, and watch the process go along:

for i in `seq 1 10`; do lxc-copy -n TestCont -N TestCont$i;echo “lxc.start.auto = 1” | tee -a .local/share/lxc/TestCont$i/config;lxc-start -n TestCont$i; done; watch -n 5 lxc-ls -f

Maybe we can also configure the dnsmasq at the same time:

for i in `seq 1 10`; do echo “dhcp-host=Cont$i,10.0.0.$i” | tee -a /etc/dnsmasq.d/static-hosts.conf;lxc-copy -n TestCont -N TestCont$i;echo “lxc.start.auto = 1” | tee -a .local/share/lxc/TestCont$i/config;lxc-start -n TestCont$i; done; watch -n 5 lxc-ls -f

As you can see my dnsmasq conf file is called static-hosts.conf. Now i got 10 new containers with fixed IP addresses in 5 minutes – thats cool 🙂

Before copying the original container I have some tips on what to install in it:

sshd
vim
bash-completion

You could do it like this:

lxc-execute -n TextCont apt install ssh vim bash-completion -y

Now you got a nice base image with ssh for remote access, vim for file editing and bash completion. This image will have a ~420 MB footprint.
Another option is to put your public SSH key in the base image, now where getting somewhere 🙂

 

 

Push adbkey to device.

When flashing mobile devices with custom ROMs, I have often experienced that the initial screen resolution when booting the new image the first time is terrible wrong. When this happens I usually change the screen resolution with the following commands (this is for my Xiaomi Mi Note Pro, find your setting on www.gsmarena.com or another phone site)

adb shell wm size 1440×2560
adb shell wm density 560

This will fix the resolution, but i still have bad resolution in the boot process, I haven’t figured out how to change that yet. If you know please leave a comment.

Sometimes the resolution is so bad that i cant even push the accept button on the USB debug prompt, this means that I cannot use adb to change the screen resolution. If this happens you have to reboot into the recovery (I prefer TWRP) and copy your adbkey.pub to the /data/misc/adb/adb_keys file. You can do it like this:

adb push adbkey.pub /data/misc/adb/adb_keys

Reboot your device and you are now able to use adb to change the screen resolution.

Kill unresponsive VM from ESXi cli

Sometimes a VM can go in an unresponsive mode and you cannot shut it down or reboot it from the vSphere client. When this happens we need to be more persuasive in telling the VM to shut down. Log in to the ESXi server with SSH, find the World ID for the unresponsive VM and kill the process, this is done like this:

esxcli vm process list

This will list all the running VMs on the server, use grep -A2 to filter the VM name and the world ID, like this:

esxcli vm process list |  grep -A2 “VM Name”

Kill the process with this command:

esxcli vm process kill -t=soft -w=”WORLD_ID”

This will kill the process in a “soft” way, use -t=hard to be even more persuasive and as a last resort attempt you can use -t=force. If none of the three shuts down the VM, a reboot of the host is required.
To automate things a bit i assembled this one-liner for easy use:

esxcli vm process kill -t=soft -w=`esxcli vm process list | grep -A2 “VM Name” | grep World | awk ‘{print $3}’`

This will softly shut down the VM with “VM Name”

Add new virtualportgroup to vSwitch on multiple VMHosts with Powercli

If you dont have dvSwitches (Distributed vSwitches) in your vSphere cluster, or dont even have a cluster, you may have to add new portgroups manually, depending on the number of VMHosts this can be a pretty cumbersome task.

Luckily, we can use powercli to automate the task. In the following example i will use the -location parameter to define my tagets in the variable $hosts

Lets go ahead and define the VMhosts we want to target:

$hosts=get-vmhost -location “location”

Then, we create the new portgroup for every VMhost in the location by using a foreach loop:

foreach ($vmhost in $hosts) {Get-VMHost $vmhost | Get-VirtualSwitch -name “vSwitch0” | New-VirtualPortGroup -VLanId “10” -Name “Name”}

This will create a new VirtualPortGroup with VLAN ID 10 named “Name” on vSwitch0 on all the VMHosts in the specified location.

Remove the port again by doing this:

foreach ($vmhost in $hosts) {Get-VMHost $vmhost | Get-VirtualSwitch -name “vSwitch0” | Get-VirtualPortGroup -Name “Name” | Remove-VirtualPortGroup -Confirm:$false}

Remember that -Confirm:$false will remove the port without confirmation! Make sure you have the right targets in the $hosts variable!!!

Saving and restoring ESXi configuration, and fixing VMKCore coredump partition dump issues

Hi all.
Today i had to reinstall some ESXi 5.5 hosts as we were upgrading to SSD disks, in order to have more performance on the Citrix environment we are hosting.

Before i powered off the server, i saved the configuration to use for easy reconfiguration with the following command from powercli:

Get-VMHostFirmware -VMHost xxx-hostname-xxx -BackupConfiguration -DestinationPath C:\HostBackups\

Now i got a xxx.tgz file containing the full configuration of the original ESXi host, ready for importing back when the reinstall is done.

When the server was installed on the new disks, i connected directly to the reinstalled server by its IP address,  put the server in maintenance mode and imported the configuration backup with these commands from powercli:

Set-VMHost -State Maintenance

 

Set-VMHostFirmware -VMHost xxx-hostname-xxx -Restore -SourcePath c:\HostBackups\xxx.tgz -HostUser user -HostPassword password

Because of the new disks i got an error regarding my vmkcore vmkdumpfile that was missing. I was able to list the partition table, which showed that i had two different dump partitions, but none of them were configured for use.
To get it fixed i had to unconfigure the existing coredump partition with this command from the ESXi shell:

esxcli system coredump partition set -u

And then reconfigure the partition with this command, also from the ESXi shell:

esxcli system coredump partition set –enable true –smart

This command will let the system choose which partition to use for the coredumps. The system will now use the choosen partition, no reboot needed.

Re-Volt, Wine, Multiplayer

My kids are beginning to play on their computers, and when one of them where invited to a socalled LAN-Party it woke up memories in my mind. I remembered how I used to play at LAN parties my self, and I remembered how simple it was to set up a game and play against each others. Todays gaming is all about joining public servers, creating accounts, and answering questions about this and that.

That made me think back on one of my favourite games from around 2000, Re-Volt. I searched the web and found that Re-Volt isn’t dead at all, fan communities are still alive, and theres even a small patch for the latest version that will support modern wide screens, easier multiplayer, etc. Check it out here: http://www.revoltrace.net/ where you will also be able to download the latest version and patch.

The kids are running Windows 7 and Windows 10 and we had no issues installing it, the installer will ask for the directplay module and download it when needed. In order to play multiplayer we had to allow some firewall ports to be used even though the firewall is disabled on the local network. When hosting a game I noticed that it’s using my public IP and not my private, thats probably why I had to allow additional ports to be used – 🙁

Now, lets get back to the actual point for my post. I am running Ubuntu Linux 14.04 on my laptop, and I thought I would be able to play Re-Volt using Wine. No problem at all, it installed just fine and worked like a charm, until I wanted to play multiplayer over the LAN. I got different erros depending if I wanted to host or join a game, but quickly I found out that on Linux I also needed the so-called directplay module, which is easily installed with winetricks that comes with the Wine installation on my system. After some googling I found out that all I needed to do was:

winetricks directplay

This command will install the directplay module and now the game is running smoothly with or without multiplayer. Wine documentation states to run “sh winetricks directplay” which will not work for the package-manager installed version.

Using Vim as editor in PowerShell

If you are used to using Vim or Vi as your editor, you might miss it when using powershell. Good news is, theres a way to get it. Download and install Vim for windows, create a profile.ps1 file in this path: (for me at least) c:\users\%username%\documents\WindowsPowerShell\ and type in the following:

$VIMPATH    = “C:\Program Files (x86)\Vim\vim74\vim.exe”

Set-Alias vi   $VIMPATH
Set-Alias vim  $VIMPATH

# for editing your PowerShell profile
Function Edit-Profile
{
vim $profile
}

# for editing your Vim settings
Function Edit-Vimrc
{
vim $home\_vimrc
}

Remember to change the $VIMPATH to your installation.

Now you have a fully functional vim from powershell.

/Kasper

Steam (and possible other) in 64 bit systems

Hi all.

I just tried to install Team Fortress 2 in Steam on my Ubuntu 15.04 64bit system, and I got this error message:

You are missing the following 32-bit libraries, and Steam may not run: libc.so.6

I asked google, and I found an article suggesting to do this: apt-get install lib6* – this will install a hell of a lot of software that you probably don’t need.

So instead of just following the suggestion I did an apt-search libc6, and found this package: libc6-i386, I installed it, and now I was able to install Team Fortress 2 in steam.

/Kasper