The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for October, 2016

Multi-line comments in a bash shell script

Posted by jpluimers on 2016/10/18

I’m used to multiline comments in many languages, but since I don’t use bash very often, I only recently learned it can do that too.

So this is how to have comments span multiple lines in bash by using the : command which according to the bash man page does nothing:

: [arguments]
No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned.

So the syntax is:

: '
your comments here
'

–jeroen

via: Shell Script Put Multiple Line Comment.

Posted in bash, Development, Scripting, Software Development | Leave a Comment »

When a PC lost its trust relationship with a domain controller: “The trust relationship between this workstation and the primary domain failed”

Posted by jpluimers on 2016/10/17

(Don’t ask for details; at a site with Microsoft Data Protection Manager an external company monitoring that DPM didn’t notice various backups – including the domain controller – were months old despite daily tape changes; so then the RAID fell out because multiple disks failed within hours, contingency aftermath took weeks)

When you logon to a client machine and get “The trust relationship between this workstation and the primary domain failed”

  1. do not rejoin your client machine to the domain
  2. ensure on the client machine:
    1. you can logon without a domain account (part of any contingency plan should be logging in with a local account or without a domain controller if you have the – potential risky – cached domain logon enabled, otherwise you’ve to do more nasty measures)
    2. you have PowerShell v3 or later on the client machine
  3. on the client machine
    1. Ensure it’s connected to the same network as the domain controller
    2. Ensure you can ping the domain controller
    3. Test with Powershell Test-ComputerSecureChannel to see if the connection is indeed lost:
      1. if it returns True then you have a different problem (have not seen this, but just in case: this blog post won’t solve that)
      2. if it returns False, then continue with the next step
    4. Run Powershell Test-ComputerSecureChannel -Repair and check if the output is True (when False there )

Note there are various posts suggesting to use Powershell Reset-ComputerMachinePassword and netdom.exe resetpwd /s:dc-hostname.domain /ud:domainadminusername /pd:*. Though faster than rejoining the domain, the Powershell Test-ComputerSecureChannel is even faster and easier.

–jeroen

via:

Posted in Power User, Windows | Leave a Comment »

VMware ESXi – converting a thick disk to a thin disk – via: Server Fault

Posted by jpluimers on 2016/10/17

There are various places that tell you you cannot resize a thick disk to a thin disk using vmkfstools.

When you do it wrong, you get this error:

DiskLib_Check() failed for source disk. The file specified is not a virtual disk (15).

This happens when you directly try to resize the physical disk image:

# vmkfstools --clonevirtualdisk msmxp-flat.vmdk --diskformat thin msmxp-flat.thin.vmdk
DiskLib_Check() failed for source disk The file specified is not a virtual disk (15).

Whereas you should point vmkfstools to the disk descriptor file which has the shortest name:

# vmkfstools --clonevirtualdisk msmxp.vmdk --diskformat thin msmxp.thin.vmdk
Destination disk format: VMFS thin-provisioned
Cloning disk 'msmxp.vmdk'...
Clone: 100% done.

(Note that many people shorten the --clonevirtualdisk to -i and --diskformat to -d).

For performance, it doesn’t matter much if your disk is thick or thin as explained by Death to false myths: The type of virtual disk used determines your performance.

But various people issues expanding a thick disk. With thin disks, that usually works fine.

This post explains the correct steps of resizing: VMWare ESXi 5.1–convert virtual disk (vmdk) from thick to thin provision.

Here is a summary:

Step zero: shutdown the VM and ensure you have a backup!

For instance with rsync is great for making a local backup:

# time ./850EVO1TBR1B/bin/rsync -aiv --info=progress2 --progress ./850EVO1TBR1B/Raid6SSD-VM/msmxp/ ./850EVO1TBR1A/Raid6SSD-VM/msmxp/

Step one: show the disk files:

/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # du -h *.vmdk
12.0G   msmxp-flat.vmdk
0   msmxp.vmdk

There are two: msmxp.vmdk describes the disk and msmxp-flat.vmdk has the data.

Step two: ensure you have enough free space on the volume:

# ls -al /vmfs/volumes | grep "552f5788-33e30274-8dba-001f29022aed"
drwxr-xr-t    1 root     root          2660 Aug  5 04:35 552f5788-33e30274-8dba-001f29022aed
lrwxr-xr-x    1 root     root            35 Aug  5 06:11 850EVO1TBR1B -> 552f5788-33e30274-8dba-001f29022aed
# df -h | grep "850EVO1TBR1B\|Use%"
Filesystem   Size   Used Available Use% Mounted on
VMFS-5     930.8G 736.8G    194.0G  79% /vmfs/volumes/850EVO1TBR1B

Convert the disk:

# vmkfstools --clonevirtualdisk msmxp.vmdk --diskformat thin msmxp.thin.vmdk
Destination disk format: VMFS thin-provisioned
Cloning disk 'msmxp.vmdk'...
Clone: 100% done.

Observe the size:

In my case the flat disk was almost full and fragmented, so the thin disk is not smaller:

/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # du -h *.vmdk
12.0G   msmxp-flat.vmdk
12.0G   msmxp.thin-flat.vmdk
0   msmxp.thin.vmdk
0   msmxp.vmdk

Rename both disks

Use vmkfstools (do not use mv as that will not keep the descriptor/data vmdk files bound together) and check the rename.

You can replace --renamevirtualdisk with -E:

/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --renamevirtualdisk msmxp.thin.vmdk msmxp.vmdk
## /vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools -E msmxp.vmdk msmxp.thick.vmdk
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # du -h *.vmdk
12.0G   msmxp-flat.vmdk
12.0G   msmxp.thick-flat.vmdk
0   msmxp.thick.vmdk
0   msmxp.vmdk

Turn on the Virtual Machine to verify it still works.

If it does, then delete it (you can replace --deletevirtualdisk with -U) which will remove both both the descriptor and data vmdk file:

/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --deletevirtualdisk msmxp.vmdk 
## /vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools -U msmxp.vmdk 
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # du -h *.vmdk
12.0G   msmxp-flat.vmdk
0   msmxp.vmdk

After shutting down the VM again and making a new backup, you can now expand the disk as described in VMware KB: Adding space to an ESXi/ESX host virtual disk.

You can replace --extendvirtualdisk with -X.

/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --extendvirtualdisk 14G msmxp.vmdk 
## /vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools -X 14G msmxp.vmdk 
Grow: 100% done.
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # du -h *.vmdk
12.0G   msmxp-flat.vmdk
0   msmxp.vmdk


/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --renamevirtualdisk msmxp.vmdk msmxp.thick.vmdk
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --clonevirtualdisk msmxp.thick.vmdk msmxp.vmdk --diskformat thin
Destination disk format: VMFS thin-provisioned
Cloning disk 'msmxp.thick.vmdk'...
Clone: 100% done.
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # diff msmxp.thick.vmdk msmxp.vmdk
--- msmxp.thick.vmdk
+++ msmxp.vmdk
@@ -7,18 +7,18 @@
 createType="vmfs"
 
 # Extent description
-RW 29360128 VMFS "msmxp.thick-flat.vmdk"
+RW 29360128 VMFS "msmxp-flat.vmdk"
 
 # The Disk Data Base 
 #DDB
 
-ddb.adapterType = "ide"
-ddb.thinProvisioned = "1"
-ddb.geometry.sectors = "63"
-ddb.geometry.heads = "16"
-ddb.geometry.cylinders = "29127"
-ddb.uuid = "60 00 C2 9f 5e f8 33 76-6e c5 48 3c f2 84 d8 1e"
-ddb.longContentID = "5659579edebed2ebdd8e0c8fda15abd4"
 ddb.toolsVersion = "9221"
 ddb.virtualHWVersion = "8"
 ddb.deletable = "true"
+ddb.longContentID = "5659579edebed2ebdd8e0c8fda15abd4"
+ddb.uuid = "60 00 C2 95 66 1b cf 7a-e3 db 3f 30 17 7e 00 2d"
+ddb.geometry.cylinders = "29127"
+ddb.geometry.heads = "16"
+ddb.geometry.sectors = "63"
+ddb.thinProvisioned = "1"
+ddb.adapterType = "ide"
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # du -h *.vmdk
12.0G   msmxp-flat.vmdk
12.0G   msmxp.thick-flat.vmdk
0   msmxp.thick.vmdk
0   msmxp.vmdk
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --extendvirtualdisk 14G msmxp.vmdk
Failed to extend disk : One of the parameters supplied is invalid (1).
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --extendvirtualdisk 14G msmxp.vmdk
Failed to extend disk : One of the parameters supplied is invalid (1).
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --extendvirtualdisk 14G msmxp.vmdk
Failed to extend disk : One of the parameters supplied is invalid (1).
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --extendvirtualdisk 15G msmxp.vmdk
Grow: 100% done.
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # du -h *.vmdk
12.0G   msmxp-flat.vmdk
12.0G   msmxp.thick-flat.vmdk
0   msmxp.thick.vmdk
0   msmxp.vmdk
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # vmkfstools --deletevirtualdisk msmxp.thick.vmdk 
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # du -h *.vmdk
12.0G   msmxp-flat.vmdk
0   msmxp.vmdk
/vmfs/volumes/552f5788-33e30274-8dba-001f29022aed/Raid6SSD-VM/msmxp # 

–jeroen

via: vmware esxi – vmkfstools returns error when trying to copy thin vmdk – Server Fault.

Posted in ESXi4, ESXi5, ESXi5.1, ESXi5.5, ESXi6, Power User, Virtualization, VMware, VMware ESXi | Leave a Comment »

OK Google – all you can ask Google

Posted by jpluimers on 2016/10/14

An interactive list of over 150 commands and 1000 variations that you can ask Google’s voice assistant. Made by @thekitze

Source: OK Google

Via: Amazing site lists nearly every ‘OK Google’ voice command

Posted in Google, GoogleVoice, Power User | Leave a Comment »

datetime – Round time to nearest 15min interval in Excel – Stack Overflow

Posted by jpluimers on 2016/10/14

Easy, but I always forget:

= (ROUND((A1 * 1440) / 15, 0) * 15) / 1440

Thanks David for answering.

–jeroen

via datetime – Round time to nearest 15min interval in Excel – Stack Overflow.

Posted in Excel, Office, Power User | Leave a Comment »

letsenctrypt certbot-auto – finding what certificates are there and which apache configurations use them

Posted by jpluimers on 2016/10/13

IRC #letsencrypt-dev today:

wiert

Is there any way for `certbot-auto` to show for which domains/apache-configs it has certificates?

pdeee

wiert, we actually made a ticket for 0.10.0 to do that

https://github.com/certbot/certbot/issues/3615

in the mean time, your imperfect options are:

for file in /etc/letsencrypt/live/*/fullchain.pem ; do echo -n $file ;  openssl x509 -text -noout -in $file | grep DNS; done

for installation in Apache configs, you can follow that with:

grep /etc/letsencrypt/live /etc/apache2/sites-enabled/*

wiert

@pdeee on OpenSuSE, the last statement should be

grep -r /etc/letsencrypt/live /etc/apache2/*

–jeroen

Posted in *nix, Encryption, Let's Encrypt (letsencrypt/certbot), Linux, openSuSE, Power User, Security, SuSE Linux | Leave a Comment »

Differences between SFTP and “FTP over SSH” – Stack Overflow

Posted by jpluimers on 2016/10/13

As I will likely have to secure some external FTP sessions soon and the endpoints the current FTP connects to are vague in what they support:

Here is the difference:

  • SFTP (SSH file transfer protocol) is a protocol that provides file transfer and manipulation capabilities. It can work over any reliable data stream, but is typically used with SSH
  • “FTP over SSH” uses the regular old FTP protocol, but an SSH tunnel is placed between client and server.

Source: Kristopher Johnson answering in c# – Differences between SFTP and “FTP over SSH” – Stack Overflow

–jeroen

Posted in Communications Development, Development, Internet protocol suite, Software Development, SSH, TCP, TLS | Leave a Comment »

TCP and the lower bound of web performance… is a must watch talk on plumbing,…

Posted by jpluimers on 2016/10/13

Thanks Ilya Grigorik for sharing this a long while ago:

TCP and the lower bound of web performance… is a must watch talk on plumbing, history, and people behind TCP. Awesome.

–jeroen

via: TCP and the lower bound of web performance… is a must watch talk on plumbing,….

Posted in Communications Development, Development, Internet protocol suite, Power User, TCP | Leave a Comment »

Delphi – unmangle names in BPL’s – Stack Overflow

Posted by jpluimers on 2016/10/12

Check out $(BDS)\source\cpprtl\Source\misc\unmangle.c – it contains the source code for the unmangling mechanism used by TDUMP, the debugger and the linker. (C++Builder and Delphi use the same mangling scheme.)

This has been around as long as BCC itself. However the file was called um.c instead of unmangle.c in older versions

Source: [WayBackDelphi – unmangle names in BPL’s – Stack Overflow both by User Moritz Beutel.

It’s the same mangling used in the TD32/TDS and MAP symbols.

And neede to improve https://github.com/jpluimers/map2dbg (which is my fork of https://github.com/andremussche/map2dbg) which contrary to it’s name also supports TDS/TD32 conversions in tds2pdb. The code is C# and works in virtually any Visual Studio version of 2012 and younger.

–jeroen

 

Posted in Debugging, Delphi, Development, MAP Symbol Information, Software Development, TD32/TDS Symbol information | Leave a Comment »

A great way to interactively browse xml/xhtml/html on the console: xmllint –shell

Posted by jpluimers on 2016/10/12

A while ago, I heard about xmllint, a program that can parse and query xml from the command-line.

Later, I discovered it can also parse html, can recover from xml/html errors and has an interactive shell that has a lot of commands (see table below) to navigate through the loaded command.

The relevant command-line options:

--recover
--html
--shell

Note that --recover will output failing input to stderr. You can ignore that using 2> /dev/null

Some good examples of usage are here:

The table of shell commands:

Shell

xmllint offers an interactive shell mode invoked with the –shell command. Available commands in shell mode include:
Command Parameter Description
base display XML base of the node
bye leave shell
cat node Display node if given or current node.
cd path Change the current node to path (if given and unique) or root if no argument given.
dir path Dumps information about the node (namespace, attributes, content).
du path Show the structure of the subtree under path or the current node.
exit Leave the shell.
help Show this help.
free Display memory usage.
load name Load a new document with the given name.
ls path List contents of path (if given) or the current directory.
pwd Display the path to the current node.
quit Leave the shell.
save name Saves the current document to name if given or to the original name.
validate Check the document for error.
write name Write the current node to the given filename.

–jeroen

via xmllint.

Posted in Development, HTML, HTML5, Software Development, Web Development, XML, XML/XSD, XPath | Leave a Comment »