Creating an import lib from a dll

dumpbin /exports somelib.dll > exports.txt
echo LIBRARY some > somelib.def
echo EXPORTS >> somelib.def
for /f "skip=19 tokens=4" %name in (exports.txt) do echo %name >> somelib.def
lib /def:somelib.def /out:somelib.dll.lib /machine:somelib.dll

To get the value for machine do dumpbin /headers somelib.dll | findstr machine
The options in the for command mean skip the first 19 lines and then output the 4th field which is the name of the exported function.

git line ending handling on a project that is using multiple platforms

# for osx and linux this uses lf in the repo and will convert any cr/lf to lf on commit.
git config --global core.autocrlf input

# for windows if you want your working copy to use cr/lf this will covert on checkout.
git config --global core.autocrlf true

# for windows if you want your working copy to use what comes from the remote
# and to convert windows cr/lf to just lf on commit.
git config --global core.autocrlf input

# for windows only dev's you can keep both the wc and the remote as cr/lf.
git config --global core.autocrlf false

Upgrading Windows subsystem for Linux

I’m running Windows 10 Enterprise and using ubuntu 14.04 trusty which is what you get when you install the software.

I wanted 16.04 (xenial) which is available on the early release channel from MS but I’m not a subscriber.
The command to do this is simple: do-release-upgrade.
If it doesn’t work due to screen, then apt-get remove screen and reinstall after the upgrade.

Hope this helps,

-Martin

sudo: no tty present and no askpass program specified

After upgrading Windows subsystem for Linux from Ubuntu 14.04 to 16.04 I was getting the following:
mjs@IMAGE:/mnt/c/Users/mjs/Desktop$ sudo hostname localhost
sudo: unable to resolve host IMAGE
sudo: no tty present and no askpass program specified

The hostname needed to be set to localhost and I obviously needed to be able to enter a password.
But, in order to hostname, I needed to either use sudo or su.
I tried su and the password was set but not what it was prior to the upgrade 🙁

man sudo came to the rescue as man pages so often do.

mjs@IMAGE:/mnt/c/Users/mjs/Desktop$ sudo -S -h localhost hostname localhost
[sudo] password for mjs:
mjs@IMAGE:/mnt/c/Users/mjs/Desktop$

-h localhost solves the hostname problem by temporarily specifying the hostname.
-S requests that sudo use stdin for the password request which solves the askpass problem.

The next task was to edit /etc/hostname to contain localhost to make it permanent and to use sudo to change the root password.

Hope this helps,

-Martin

Checking for and installing GRUB on both disks of an md RAID 1 array

If you are using a two disk md RAID 1 for your system to provide for redundancy then you want to be able to boot from either drive in the event of a disk failure. That means you need to have GRUB installed on both boot blocks. The check is easy:

-bash-4.1# dd if=/dev/sdb bs=1 count=512 | grep -o -a --color '[\x20\x30-\x7a]\{2,4\}' 
ZR
;D
GRUB
Ha
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.000566734 s, 903 kB/s
-bash-4.1#

The command above intentionally shows the use of grep rather than the more convenient strings because if you boot into linux rescue from a flash drive you won’t have strings! If you are being proactive and setting this up before a disk failure then you can use strings. The dd dumps the first 512 bytes of the disk to stdout and pipes it into grep. The -a tells grep to process the bytes as if they were text, and the -o instructs grep to only show the matched strings. If you see GRUB you are good to go. Continue reading Checking for and installing GRUB on both disks of an md RAID 1 array

Script for EDAC Diagnosis

Here is a bash script that I wrote to grab the important information using dmidecode. The problem with “Having to invert the logic” as Sebastian mentioned in his comment on my previous post on “How To Diagnose Memory Errors on AMD x86_64 using EDAC” is handled by using the switch -b.

Sorry that there are no comments. I was just playing around when I wrote this and never cleaned it up. Continue reading Script for EDAC Diagnosis

How To Diagnose Memory Errors on AMD x86_64 using EDAC

This is a writeup I put together to help identify the defective DIMM from EDAC errors on linux x86_64.

Over several years of managing a linux cluster I have occaisionally had systems with a bad memory DIMM. An early manifestation of these errors is EDAC errors (Error Detection and Correction kernel module) reported in the kernel ring buffer. One frustrating problem is identifying the bad DIMM. In the past I have used a brute force approach to diagnose this by running the system with a single DIMM at a time until I found the offending DIMM. However, as systems have become larger with more CPUs and more DIMMS this has become very impractical. It seems that the information in the EDAC error messages should be sufficient to identify the offending DIMM. Unfortunately, it is not obvious how to do this, and I have found no single source that explained the process. As a result, using information from a number of sources I have figured it out for some of our current motherboards (e.g. SuperMicro AMD64). The following is a summary of the steps that I used which I believe can be generalized to other motherboards.
Continue reading How To Diagnose Memory Errors on AMD x86_64 using EDAC

Editing initrd (Initial ramdisk)

Editing an initrd is often simpler than creating one.

I needed to create a new node for the system md device because while working on the system RAID1 md after a power failure under linux rescue, the minor device number changed. init was throwing the error “mount: could not find filesystem /dev/root
The following steps are what I did to fix it…
Continue reading Editing initrd (Initial ramdisk)