Core Configurator 2.0

Illustration

For those that use Windows Server Core installations there is new candy in store - Core Configurator 2.0.

Not only that this collection of scripts will help with quite a few of administration tasks, but it will do it with basic graphical interface.

Lovers of GUI, rejoice.

Google Public DNS

Illustration

Few days ago Google announced new project. This time, DNS is thing they wish to change.

What they decided to offer is public DNS service for anybody willing to re-configure his IP settings. Since having DNS at 8.8.8.8 and 8.8.4.4 is quite easy to remember, there is no problem to change it at all computers that you use.

What Google gives here is promise of speed and I must say that they deliver. Their DNS is quite speedy and stable. While I cannot say that I would miss it much if they decide to pull a plug, I must say that I had no issues with it. And little bit of speed is not a bad thing.

How to Make Sausage

Illustration

Here is recipe that I use for making sausages. These sausages can be made with pure pork, but I like to also add some beef meat.

First step is to grind meat in meat grinder. Pieces should be small, but not in paste-like form. If you don’t have meat grinder just ask your butcher to grind meat for you. Or buy minced meat. Just don’t use food processor because it will completely destroy meat texture.

Spread salt, pepper and paprika (both sweet and hot) over minced meat. In another bowl add garlic into boiling hot water and leave it to rest for fifteen minutes. Filter garlic out and pour hot water over minced meat with spices. Mix thoroughly.

After all spices are distributed evenly take a taste of meat. This step is quite necessary since hot paprika can vary from batch to batch. If it is not hot enough, just add hot paprika. During smoking sausage will loose quite a lot of water and hot paprika will surface so don’t go too wild.

Once you are satisfied with taste, fill casings (I usually use salted pig casings). You will need sausage stuffer for this step since consistency needs to be quite dense.

This sausage mix is intended for smoking and I would not recommend frying it. However, if you wish instant results, you can cook it with water on medium fire for fifteen minutes.

Ingredients:

  • 7.5 kg Minced pork
  • 2.5 kg Minced beef
  • 200 g Salt
  • 20 g Black pepper
  • 25 g Hot paprika (ground)
  • 250 g Sweet paprika (ground)
  • 250 g Garlic

Structure Alignment

Let’s begin with example:

struct Test {
    Int16 A;
    Int32 B;
}

Since Int16 has length of two bytes and Int32 has length of 4 bytes one would expect total length of 6 bytes. However, upon check (with Marshal.SizeOf) we will discover that total length is 8 bytes. This difference is expected and allocated length is due to alignment of data structures.

When 32-bit processor reads data, it will do that in chunks of 4 bytes. If we want whole value to be read in one pass, it needs to be placed on alignment boundaries. If we want to read 4 bytes, we need those bytes to be at offset 0, 4, 8… or any other multiple of 4. This also explains length of first structure. First two bytes belong to variable A, then there are two padding bytes and final four bytes are variable B. Only function of those two bytes of padding is to ensure proper offset for variable B. Exact values of padding bytes are not of interest to us.

Alignment is almost always done on natural boundary of data type. 8-bit data types (e.g. Byte) will be aligned on 1-byte boundary, 16-bit data types (e.g. Int16) will be aligned on 2-byte boundary, 32-bit data types (e.g. Int32, Single, Boolean) will be aligned on 4-byte boundary and 64-bit data (e.g. Int64, Double) will be aligned on 8-byte boundary. All data types larger than that will be also aligned on 8-byte boundary.

To show it with example:

struct Test {
    Int16 A;
    Int16 B;
    Int16 C;
}

Length of this structure will be 6. This is because every variable is on natural boundary and there is no padding needed. If we decide that B needs to be Int32, length will jump to 12. This is because byte boundary needs to be aligned on 4-byte values and we will have padding after both A and C. This also shows how important careful ordering can be. If we make C Int32, total length will be 8 - no padding.

Calculating everything by hand can be sometimes quite annoying. This is why I made this function:

using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
static void DebugStructureAlignment(object structure) {
    var t = structure.GetType();
    if (t.IsValueType) {
        Debug.WriteLine("Offset  Length  Field");
        int realTotal = 0;
        foreach (var iField in t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) {
            Debug.Write(Marshal.OffsetOf(t, iField.Name).ToString().PadLeft(6));
            Debug.Write("  ");
            int size = Marshal.SizeOf(iField.GetValue(structure));
            realTotal += size;
            Debug.Write(size.ToString().PadLeft(6));
            Debug.Write("  ");
            Debug.WriteLine(iField.Name);
        }
        Debug.WriteLine("        " + Marshal.SizeOf(structure).ToString().PadLeft(6) + " bytes total");
        Debug.WriteLine("        " + realTotal.ToString().PadLeft(6) + " bytes total (data without padding)");
    }
}

Just give it instance of structure as parameter and you will get offsets and lengths of all fields inside of it. While this function is not perfect and I would not be surprised that there are some errors inside, mostly it will just work. In case you are playing with Windows API a lot, chances are that you have something like this already written.

Installing Windows 7 From USB Drive - XP Version

Illustration

I already wrote about creating USB installation media for Windows 7. However, that procedure worked only on Windows Vista and above. I stumbled upon problems when I tried to apply same procedure on Windows XP.

In this walk-through I will have USB drive on letter W: and Windows 7 installation CD (either real one or just mounted iso) on drive F:.

For this to work, we need to first format USB as NTFS drive:

FORMAT W: /FS:ntfs /Q
 Insert new disk for drive W:
 and press ENTER when ready...
 The type of the file system is FAT32.
 The new file system is FAT32.
 QuickFormatting 7647M
 Initializing the File Allocation Table (FAT)...
 ...

CONVERT W: /fs:ntfs
 The type of the file system is FAT32.
 Volume Serial Number is 8CD3-E43F
 Windows is verifying files and folders...
 ...
 Converting file system
 Conversion complete

One thing that is problematic on XP is making USB bootable in first place. There is DISKPART tool available, but only for internal disks. External USB memory will just not be recognized there. In order to go around this, you will need MBRWizzard. That tool gives you DISKPART-like commands and it works on Windows XP.

First we need to see what do we have:

MBRWIZ /list
 MBRWiz - Version 2.0 **beta** for Windows XP/2K3/PE         April 30, 2006
   Copyright (c) 2002-2006 Roger Layton                    http://mbr.bigr.net
 Disk: 0   Size: 153G CHS: 19457 255 63
 Pos MBRndx Type/Name  Size Active Hide Start Sector   Sectors    DL Vol Label
 --- ------ ---------- ---- ------ ---- ------------ ------------ -- ----------
  0    0    07-NTFS    152G   No    No            63  312,576,642 C: <None>
 Disk: 1   Size: 153G CHS: 19457 255 63
 Pos MBRndx Type/Name  Size Active Hide Start Sector   Sectors    DL Vol Label
 --- ------ ---------- ---- ------ ---- ------------ ------------ -- ----------
  0    0    07-NTFS    152G   No    No            63  312,576,642 D: <None>
 Disk: 2   Size: 7.6G CHS: 974 255 63
 Pos MBRndx Type/Name  Size Active Hide Start Sector   Sectors    DL Vol Label
 --- ------ ---------- ---- ------ ---- ------------ ------------ -- ----------
  0    0    07-NTFS    7.6G    No   No         2,048   15,661,056 W: <None>

As you can see, USB is recognized as drive 2. Do remember this. In order to make first partition bootable, we need to activate it.

Command parameters are easy. Disk takes number of disk (2 in this case), part is partition number (always zero - Windows have problems with multiple partitions on USB drive). Active works as simple boolean operation: 1 to make partition active and 0 to deactivate it.

MBRWIZ /disk=2 /part=0 /active=1
 MBRWiz - Version 2.0 **beta** for Windows XP/2K3/PE         April 30, 2006``
   Copyright (c) 2002-2006 Roger Layton                    http://mbr.bigr.net``
 Are you sure you want to set the partition(s) Active? (Y/N): y``
 Partition successfully set to Active``

Once partition layout is done, copy operation can commence. Just copy everything from Windows 7 CD to your USB drive.

XCOPY F:\*.* /s /e /f W:\

After everything is copied, we just need to update boot code on USB drive. We can do this with BOOTSECT program located on your Windows 7 installation CD in boot folder.

F:
CD boot
BOOTSECT /nt60 W:
 Target volumes will be updated with BOOTMGR compatible bootcode.
 W: (\\?\Volume{2f3c3a5d-1913-11de-a3ee-003005c321bd})
    Successfully updated NTFS filesystem bootcode.
 Bootcode was successfully updated on all targeted volumes.

Now your installation is ready to go!

Unlike Windows 7 procedure, here we need NTFS formatted media. I tried to do same with FAT32 formatted media, but my laptop would not recognize it. Since Windows 7 do work from such media, there is probably just small adjustment needed but I decided not to bother with it.