CentOS on Windows Subsytem for Linux (WSL)

I read about the Windows Subsystem for Linux a while back, and thought it was only available using Ubuntu. Today I wanted to play around with it and fish shell, but I prefer centos to ubuntu. A quick google found this github project – WSL Distribution Switcher –

Excellent! It allows you to switch from ubuntu to other linux distro’s. I’m not going to pretend I have taken the time to understand how WSL works ‘under the hood’ but as WSL Switcher gets docker layers / images, I’m guessing it based on docker in some shape or form?

I enabled WSL on my W10 1703 (Creators Update) build, started bash and created myself a user. Installed Python 3 (a requirement for WSL Switcher). Then I cloned the WSL Switcher git project and used the following commands to switch to centos and confirm it worked :

  • get-prebuilt.py centos:latest
  • install.py centos:latest
  • bash
  • cat /etc/centos-release

Everything seemed fine, but then I tried to run yum (the centos package manager). It wouldn’t run as a non root user, fine – tried “sudo yum”. Command not found – grrrrrr

Then I tried su – got prompted for password and thought I had made progress – entered the password for my linux user… nope!

Luckily, I’m not the first person to run into this problem 🙂 I found an issue in the WSL Distro Switcher github with the information I needed. I needed to switch the default user that WSL used, enter WSL / bash, change the passwd, then change the default user back to my non root user.

  • lxrun /setdefaultuser root
  • Found UNIX user: root
    Default UNIX user set to: root
  • bash
  • passwd
    • (enter your desired root password)
  • exit
  • lxrun /setdefaultuser *username*

Now when I went into WSL, I was logged in as my normal user – I could “su” and run commands as root – perfect! However, I like to sudo rather than switch to root using su – more to be done…

I thought the next bits would be easy – but alas no. yum wont work, even now I have access to root user – looks like a network issue. Should be simple to figure out right? I wish, no ifconfig, so i tried “ip addr” – neither work. Why do people insist on taking so much stuff out of an OS as to make it almost useless!

 

I thought that the networking was messed up – it was fine, but DNS resolution was messed up – I ‘resolved’ this by editing resolv.conf, which had a really random IP set for the nameserver! I fixed this and then moved onto to sorting out sudo!

  • yum install sudo
  • exit (to exit su shell back to normal user)
  • sudo yum
    • user is not in the sudoers file. This incident will be reported.
    • so we need to add to the sudoers file
  • su
  • vi /etc/sudoers
    • add a line near the bottom
    • username ALL=(ALL) ALL
  • exit (exit su shell)
  • sudo yum (testing)
    • It works!

Now onto fish commandline…

Its not in the main repos – so I had to first install epel

  • sudo yum install epel-release
  • sudo yum install fish

Now I can enter fish shell after entering WSL bash – i tried a few things to try and set fish as the default shell – but none of them worked. Probably something to do with docker / wsl. I will update this post if i can figure out how to go straight into fish…

 

 

 

Advertisements

HowTo Deploy an Additional File with MSI using InstEd!

Sometimes when you need to deploy an application, you may need to add additional files to get installed onto the target machine, they could be configuration or license files etc… The first thing you need to do is create a CAB file with the additional files you want to install / deploy with the MSI. A CAB file is a Microsoft compressed archive from before Zip files were widely adopted. Every version of Windows since 2000, has shipped with a tool built in to create CAB files called “makecab”.

Makecab Utility Help Output
Microsoft Makecab commandline utility.

Make CAB file with desired additional files
For this example I only needed to add one additional file, so the commandline was easy – if you need to add multiple files you may need to explore the /F switch and directive files. Or the features built into InstEd! to help with this (see their online help page).
makecab filename.xml LicenseFile.cab
Where filename.xml is the name of the license file and LicenseFile.cab is the name of the destination CAB file to be created.

InstEd! is a great little tool for editing MSI files. Its very similar in functionality to Orca if you have ever used that – but it is more user friendly and offers more functionality. The instructions provided assume you are using InstEd! There are two main methods you can use, edit the existing MSI – OR – create a transform file and reference it during the install. I will be creating a transform file, as I think if you edit an already signed MSI you will need to sign it again using certificates etc…

Create New Transform File
Open the MSI file in InstEd! and select Transform -> New Transform. Choose a filename for the new MST file. I called mine “LicenseFile.mst”
Add Component to component table
Go to the “Component” Table, right click in the rows pane on the right hand side and select “Add Row” – complete the details as follows :

Component LicenseFile (What you want the Component to be called)
ComponentId (Use button to generate new GUID)
Directory license_Dir (Use Directory Table to find name of desired target directory)
Attributes 0x0000 (Default value)
Condition <null>
KeyPath <null>

I used an already existing entry in the Directory Table “license_Dir” – you may need to add a row to the directory table for your requirements.

The new row should now be visible and highlighted in green. The reason its green, is to show you which rows have been updated, added or deleted from the original MSI file by the transform file.

Screenshot of new Component Dialog
Screenshot of new Component Dialog

Associate the created component with a feature
Now we need to tell the MSI to install this new component when it installs the main application in my case this feature is called “MainFeature”.

Feature MainFeature (Choose appropriate feature from dropdown)
Component_ LicenseFile (Choose the component you created)
Screenshot of New FeatureComponent Dialog
Screenshot of New FeatureComponent Dialog

Add the file entry in file table
Next we will add an entry in the file table for the actual file we want to add to the installation, in my case this is a license file which is getting installed to a subdirectory of the main program files folder. Luckily the developer of the application had anticipated people would want to install their license file during deployment so the MSI already had a directory entry for “license_Dir”. If this didnt exist we would need to create an entry in the Directory table as well.
Sort the “File” table by the field “Sequence” scroll to the bottom to find the highest sequence number and make a note of it (in my example the last Sequence number is 773, so my file will be 774). Add a row with the following values :

File filename.xml (The filename as stored in the CAB file)
Component LicenseFile (Choose the component you created earlier)
FileName filename.xml (The destination filename)
FileSize 1
Version <null>
Language <null>
Attributes <null>
Sequence 774
Screenshot of new file row dialog
Screenshot of new file row dialog

Add the media entry in media table
The last table we need to edit in the MSI is the media table. This table tells the MSI where the files are to install, you will need the file sequence number from the previous step (774). I think the reason for this, is that when installers still came on disks this is the method by which the installer knew to ask for the next disk.

DiskId 2 (My example already had a disk with id 1)
LastSequence 774 (LastSequence number of first disk + 1)
DiskPrompt <null>
Cabinet <null>
VolumeLabel <null>
Source <null>
Screenshot of new media dialog.
Screenshot of new media dialog.

Save and Test!
Once you have finished adding rows etc… you need to save the transform file. Just underneath the File and Edit menu should be a small box with the name of the mst file and a little asterix to indicate changes have been made. Right click this box and select save. Now you have saved the transform you can test the installation to see if it works. Put the *.mst and *.cab files in the same folder as the *.msi file and run the following commandline from an elevated (run as admin) command prompt.
msiexec /i filename.msi /qn /l*v %TEMP%\TransformTest.log TRANSFORMS=filename.mst
Note you do not need to reference the cab file in the commandline.
If all went well, the application plus the additional file should have installed succesfully – and a verbose msi install log will have been created in %TEMP% folder. Use this to troubleshoot any issues you encounter.

Delete User Profile – Windows 10

Strange issue’s are my favourite!

I wanted to delete a user profile on W10 1511 today. But when I went into User Profiles through control panel – only the current user i was logged in was displayed.

To see all user profiles, I had to go to Computer Properties -> “Advanced system settings” -> User Profiles Group -> Settings.

I’m not sure what causes this issue – it could be that UAC is disabled and if was enabled when I went in through Control Panel i would have been prompted to accept the UAC prompt then it would display more than current user.del_user_profile_screenshot

Making sense of error codes in System Center

The logs for System Center Configuration Manager (SCCM) are full of error codes – well they are in the environment I look after! Making sense of them can be difficult. It took me a while to realise that these error codes are not specific to SCCM but are generic Windows error codes.

To make sense of the error code, we can pass it to a command line application and get a string / message which explains things a bit more.

The syntax is :

net helpmsg x

Where x is a decimal integer error code.

But all the error codes I see are in the format “0x8007565”. If we pass this error code into the helpmsg command it doesnt return the message. We first need to convert it from a hex value to a decimal value, the easiest way to do this is using the built in calculator.

  • Open calculator and change to programmer mode
  • Switch from decimal (DEC) to hexadecimal (HEX) mode.
  • Type the second ‘nibble‘ of the value (the last four characters of the hex value)
  • Switch from HEX back to DEC and the value should be converted to a whole number.
  • Put the number into your “net helpmsg x” command line and you get a message back.

Capture

What does this message mean?

I have found that searching the internet for these error codes and messages, can waste a lot of time. They are generic and all sorts of windows components return them. The best way to troubleshoot is to find out which SCCM component logged the message and what was it doing at the time, use this information and the error message to try and deduce what is wrong. Sometimes google isn’t the answer!