All posts by knarfalingus

Ubuntu : Recovering from /etc/fstab mistake

I wasted a bit of time on this today, so I decided to post the situation and a fix if it comes up for others.

I am running Ubuntu on a VM in HyperV. I edited the mount entry for a Windows share in /etc/fstab but made a mistake on the password.

Afterward, Ubuntu would not boot all the way though, it would get stuck on the boot screen with the message “Press S to skip mounting or M for manual recovery”. Well there is some issue here because at least in the hyperv machine connection, the M and S keys had no effect [note: key order intentionally reversed in last sentence to avoid unintended SEO 😉 ].

looking for solutions, I came up with some that recommended using fdisk etc. but I think those solutions are dated. The solution for me was:

1) In HyperV settings, Load Ubuntu Desktop ISO into DVD drive, in firmware set to boot first.
2) When the ISO image loads, it will offer an option to try Ubuntu without installing, select this.
3) Once the desktop is loaded, run terminal by pressing Ctrl-Alt-T

4) then run:

sudo gparted

if gparted isn’t installed, run the command

sudo apt-get install gparted

5) Inspect the drives listed in the GUI, just from what I knew about the drive sizes, I was able to determine the OS drive was ‘/dev/sda3’ and the file system type was listed as ‘ext4’

I then mounted this

sudo mount -t ext4 /dev/sda3 /mnt

Afterward I edited the /etc/fstab file, fixed the issue and then rebooted

sudo gedit /mnt/etc/fstab

Also, I added the “nobootwait” and “nofail” options to the fstab entry, and will add to future similar entries, so as not to have this issue again


References


nofail and nobootwait mount options in fstab prevent boot problems : http://techmonks.net/nofail-and-nobootwait-mount-options-in-fstab-prevent-boot-problems/

Ubuntu : Increasing screen resolution in VM

Quick tip for boosting resolution in a Ubuntu VM in HyperV

from terminal

sudo gedit /etc/default/grub

Edit or add the the assignment to RUB_CMDLINE_LINUX_DEFAULT

RUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1920x1080"

I chose 1920×1080 as this is the current maximum that the Hyper-V machine connection will support and it is less than what my monitor supports, change this to a value that makes sense for you.

After saving run:

sudo update-grub

And then reboot your virtual machine

ASP.NET 5 Pre-RC 2 On Linux – Part III

The next step is to try and run a web app.

There are samples under David Fowler’s (ASP.NET team member) github repository.

https://github.com/davidfowl/dotnetcli-aspnet5

I downloaded the .zip file, copied it to the Code folder from my previous post and extracted it.

I then switched to the HelloWeb sample folder in terminal

cd ~/Documents/Code/dotnetcli-aspnet5-master/HelloWeb

dotnet restore

(downloads 121 packages)

dotnet run

We get the following error

Screen Shot 2016-01-06 at 12.13.43 AM

So libuv needs to be installed as it is not present

install libuv per instructions

sudo apt-get install make automake libtool curl
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
cd /usr/local/src/libuv-1.4.2
sudo sh autogen.sh
sudo ./configure
sudo make
sudo make install
sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/
sudo ldconfig

Now we try again and success!

Screen Shot 2016-01-06 at 12.21.54 AM


Note that there looks like is a newer streamlined process for installing on Ubuntu here, but that doesn’t work for me, I reported it.

ASP.NET 5 Pre-RC 2 On Linux – Part II

So now it is time to improve my development experience on this fresh Ubuntu VM. First step is to get a better code editor, and I select Visual Studio Code (VSCode) for the job.

To get VSCode visit:

https://code.visualstudio.com

I downloaded the .zip and then created a new folder under ‘Home’ called ‘Apps’

Using file explorer (Nautilus) I moved the zip from Downloads to Apps and extracted it.

capture_2

Then per the instructions, I created a link using the command

sudo ln -s ~/Apps/VSCode-linux-x64/Code /usr/local/bin/code

This allows us to start VSCode in the current folder by typing

code . 

in terminal.

Also, to create the UI shortcuts I browsed to the Code executable using Nautilus, right clicked Code, selected ‘make link’ and dragged it to the desktop and rename it to VSCode.

capture_3

I started code by clicking the shortcut and since it will be commonly used,
I right clicked the icon on Ubuntu’s side toolbar (Launcher) and selected “Lock To Launcher”.

All seemed fine but then I noticed a message in the lower right corner of VSCode, ‘failed to start OmniSharp’. Clicking on that reveals the message

Capture4

VSCode uses Omnisharp for intellisense so this is a problem.

In the end the solution for me was to install the latest development version of Mono (4.2.1), using the command

sudo apt-get install mono-devel

ASP.NET 5 Pre-RC 2 On Linux – Part I

Now that I’ve dabbled with running RC1 (Release Candidate 1) on Linux, time to start using the pre-RC2 bits as they use the new ‘dotnet’ CLI (Command Line Interface).

I started by creating a new Ubuntu VM, just like I did before for RC1, so there would be no cross-contamination between dnvm/dnu/dnx and dotnet.

I then went to the dotnet CLI repository on github https://github.com/dotnet/cli, and since I am using Ubuntu I downloaded the Debian package per the instructions. The heavy lifting of installing was then handled by the Ubuntu Software Center.

Capture

Per the instructions, in Terminal I then executed

export DOTNET_HOME=/usr/share/dotnet/

I then created a directory for my project with the following commands

cd ~
cd Documents
mkdir Code
cd Code
mkdir ConsoleApp1
cd ConsoleApp1

I then executed

dotnet new

This creates a new empty console project, which conveniently creates a program.cs file that emits “Hello World” via the console. The files are as below

Program.cs:

using System;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

project.json:

{
    "version": "1.0.0-*",
    "compilationOptions": {
        "emitEntryPoint": true
    },

    "dependencies": {
        "NETStandard.Library": "1.0.0-rc2-23616"
    },

    "frameworks": {
        "dnxcore50": { }
    }
}

Note: Unlike in RC1, the “emitEntryPoint” compilation option is a requirement!

Now that we have a project.json file and a Program.cs file, we need to restore, just like we did with dnu, but instead we just issue the dotnet restore command.

Note that since we are using post RC1 tools, we need to set the source for our packages using the -s parameter to be the dotnet-core repository on MyGet, rather than the using the default NuGet repository. This most likely will not be necessary with RC2 and above.

dotnet restore -s https://myget.org/f/dotnet-core

Now we can run the program by executing

dotnet run

the result?

failed to locate CLR files at /usr/share/dotnet/runtime/coreclr

I did a little investigating and the issue is the files are being installed under /usr/share/dotnet-dev/, not /usr/share/dotnet/. I reported this as an issue on github.

I then set the DOTNET_HOME variable like so

export DOTNET_HOME=/usr/share/dotnet-dev/

I then tried the program again

dotnet run
Hello World!

ASP.NET 5 RC1 On Linux – INFO

Before I reset, I decided to lay out some basic info about ASP.NET 5

The current released (at present RC1) bits can be retrieved from

https://get.asp.net

Any bugs/issue or qualms should be posted to the appropriate repository on Github
https://github.com/aspnet

Recordings of the ASP.NET team standups can be found at

https://live.asp.net

The documentation (in progress) can be found at

https://docs.asp.net

Note any docs with a wrench icon has not been started yet.

There is also a freely available Microsoft Virtual Academy course available:

https://mva.microsoft.com/en-US/training-courses/introduction-to-asp-net-5-13786

ASP.NET 5 RC1 On Linux – Intermission

Well, in my last post I mentioned a Powershell/DNX case sensitivity issue related to commands. I logged this as an issue over on GitHub and was told that DNX,DNU and DNVM will be retired in RC2 in favor of a unified “dotnet” CLI (ETA February 2016). I had heard about these being possibly being replaced a few months ago at a regional .NET event, and also Scott Hanselman mentioned the new CLI last week on his blog

It’s possible to start try out some of these bits now so I will try re-starting with that in a future post (soon!).

ASP.NET 5 RC1 On Linux – Part IV – First App Analysis

Looking at the project.json from my last post

We see the following

{
  "version": "1.0.0-*",
  "description": "ConsoleApp1 Console Application",
  "authors": [ "knarfalingus" ],
  "tags": [ "hello", "world" ],
  "projectUrl": "https://www.knarfalingus.com",
  "licenseUrl": "https://opensource.org/licenses/MIT",

  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
  },

  "commands": {
    "ConsoleApp1": "ConsoleApp1"
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
       "Microsoft.CSharp": "4.0.1-beta-23516",
       "System.Console": "4.0.0-beta-23516",
      }
    }
  }
}

To simplify, we can actually remove the following

  "compilationOptions": {
    "emitEntryPoint": true
  }

This wasn’t required as the runtime will find the static Main() method.

Also we can remove the metadata, authors, projectUrl and licenseUrl etc. I added those arbitrarily anyway.

What is interesting is the commands

  "commands": {
    "ConsoleApp1”: “ConsoleApp1”
  }

The above is typical of what Visual Studio 2015 would create. The name “ConsoleApp1” doesn’t have to match the application/namespace, for example the following works just as well.

  "commands": {
    “xyz”: "ConsoleApp1”
  }

This can be explicitly run by executing

dnx xyz

The surprising part I found when trying this on Windows was, the value “ConsoleApp1” refers to the folder the app is in, not the namespace or application title. For example with this project.json

{
  "version": "1.0.0-*",

  "dependencies": {
  },

  "commands": {
    “xyz”: "ConsoleApp1"
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Console": "4.0.0-beta-23516",
      }
    }
  }
}

And the two files, project.json and Program.cs in a ConsoleApp1 directory, if I change into the directory from the parent directory using cd ConsoleApp1, dnx xyz works but if I do cd consoleapp1, in Powershell it doesn’t!, Powershell introduces case into the folder name see below. This doesn’t happen with the standard console.

Powershell can introduce case sensitivity issues when combined with commands

I am not sure if this is a bug or not due to the fact that ASP.NET is targeting systems with case sensitive file systems whereas in Windows the file system is not case sensitive (by default).

ASP.NET 5 RC1 On Linux – Part III – First App (Console)

Now that we have the VM set up, and ASP.NET 5 installed, lets do the bare minimum and create a console app.  In terminal type the following commands to create a folder for our project (you can create in an alternate location if you wish)

cd ~
mkdir Code
cd Code
mkdir ConsoleApp1
cd ConsoleApp1

Then fire up an editor, in this case I use nano (sadists can use vi)

nano

Let’s start with the C# program, enter the following code:

using System;

 namespace ConsoleApp1
 {
         public class Program
         {
                 public static void Main(string[] args)
                 {
                         Console.WriteLine("Hello World");
                 }
         }
 }

Now save the file as Program.cs

Fire up the editor again and create the project file:

{
  "version": "1.0.0-*",
  "description": "ConsoleApp1 Console Application",
  "authors": [ "knarfalingus" ],
  "tags": [ "hello", "world" ],
  "projectUrl": "https://www.knarfalingus.com",
  "licenseUrl": "https://opensource.org/licenses/MIT",

  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
  },

  "commands": {
    "ConsoleApp1": "ConsoleApp1"
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
       "Microsoft.CSharp": "4.0.1-beta-23516",
       "System.Console": "4.0.0-beta-23516",
      }
    }
  }
}

Save this file as project.json

Now we execute the following command to pull in the dependencies (Microsoft.CSharp and System.Console in this case). This will pull in quite a bit of files

dnx restore

If your project.json is incorrect in any way you will be greeted with stack traces. Scroll up and start from the top.

After all the dependencies have been pulled in you can execute the program:

dnx run

The output should be

Hello World

References : http://docs.asp.net/en/latest/dnx/console.html

ASP.NET 5 RC1 On Linux – Part II – Installation

Using the instructions from docs.asp.net, for Ubuntu we essentially run:

login to ubuntu
fire up terminal (Ctrl-Alt-T)

run the following commands:


sudo apt-get install unzip curl

curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh

sudo apt-get install libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev

dnvm upgrade -r coreclr

sudo apt-get install make automake libtool curl
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
cd /usr/local/src/libuv-1.4.2
sudo sh autogen.sh
sudo ./configure
sudo make
sudo make install
sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/
sudo ldconfig

Happily, this all ran without a hitch.


References: http://docs.asp.net/en/latest/getting-started/installing-on-linux.html#installing-on-debian-ubuntu-and-derivatives