Friday, November 4, 2022

using UMT to create virtual machines using Apple Virtualization on M1 macbook

 

I'm documenting this mostly for myself so that I the steps to redo if I forget.

Background:

Setup up VM using Apple Virtualization (as opposed to QEMU) using UMT https://mac.getutm.app/


We need  ARM64 versions of:

1) linux kernel

2) ramdisk

3) linux image

I use Ubuntu and the cloud images has all the items ready for use.

Linux Kernel file

in https://cloud-images.ubuntu.com/jammy/current/unpacked/

Look for "jammy-server-cloudimg-arm64-vmlinuz-generic" and download

rename the file to gz and gunzip the file.

```mv jammy-server-cloudimg-arm64-vmlinuz-generic jammy-server-cloudimg-arm64-vmlinuz-generic.gz && gunzip jammy-server-cloudimg-arm64-vmlinuz-generic.gz```

Ramdisk

Look for " jammy-server-cloudimg-arm64-initrd-generic" and download

Virtual Disk Image

Download image file from https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.tar.gz   and untar the file






Optional: resize img file  

(This assumes you already have qemu installed via brew)

If you want to add additional 80G to the disk space for example.

```/opt/homebrew/bin/qemu-img resize -f raw jammy-server-cloudimg-arm64.img +80G```


Obtain iso file for cloud init



My personal setup

system login credentials are baked into user-data.yaml

which builds an iso file called 'seed.iso'. which will be used for below instuctions.


alternatively for a basic one see this version

additional reference : https://github.com/frederickding/Cloud-Init-ISO


Finally, set up VM

Launch UTM

1) Add VM
2) Select Virtualize


3) Select Linux




4) select Apple Virtualization
5) Uncompressed Linux kernel select "jammy-server-cloudimg-arm64-vmlinuz-generic"
6) Linux ramdisk select "jammy-server-cloudimg-arm64-initrd-generic"
7) Linux Root FS image select "jammy-server-cloudimg-arm64.img"
8) boot iso select "seed.iso" ( for user and package provisioning)
9) boot argument enter :    console=hvc0 root=/dev/vdb (depends on the order of your storage devices, in this instruction /dev/vda is the iso file, and dev/vdb is the disk)
10) continue and set the rest of the VM resources or leave it default, 












11) save, then start VM

12) you will see a prompt, shortly, the cloud init scripts will update, provision the user and my cloud init will restart system 







13) log in with configured user  and verify diskspace ```df -h```
as with the hyper-v version, I don't seem to require to resize2fs













Sunday, October 31, 2021

Error building gotk3 in Msys2 [Golang]


While building Go program that requires Gotk3 under Msys2, this error may appear during the build.

go build github.com/gotk3/gotk3/gdk: invalid flag in pkg-config --libs: -Wl,-luuid

Run this command to fix the misconfiguration in the packaged gdk PC file and rebuild.

bash -c "sed -i -e 's/-Wl,-luuid/-luuid/g' /mingw64/lib/pkgconfig/gdk-3.0.pc"

Saturday, July 31, 2021

Hyper-v integration with Debian: how to get IP address via powershell

For powershell query to obtain network adapter information of the Debian Buster vm I've installed,

I need to install hyper-v daemon 


```sudo apt-get install hyperv-daemon```


Powershell will be able to query the network information  once it's installed in the guest.

get-vm | ?{$_.State -eq "Running"} | select -ExpandProperty networkadapters | select vmname, macaddress, switchname, ipaddresses


VMName   MacAddress   SwitchName     IPAddresses

------   ----------   ----------     -----------

buildVM 00155D7B6A07 Default Switch {172.25.28.124, fe80::215:5df0:f37b:6a07}

Friday, August 2, 2019

tailing mongo oplog with Perl

I haven't used Perl for over a decade, and I recently got curious to see  how Perl is with respect to the popular languages like Go and Python. Turns out Perl is far from stagnant with nice stuff such as carton package management.

As a practice I decided to try tailing the mongo oplog with Perl. I've written the code with Go and Python to deal with Mongo oplog  not long ago so it's still fresh. Turns out it's fairly easy to do for Perl


Fun!




use MongoDB;
print "hello ";
use feature ':5.10'; # for say
use Data::Dumper;
my $mongo_client = MongoDB::MongoClient->new(host=>'192.168.106.195',port=>7017);
=begin comment
obtaining oplog from "local" db
Every mongod instance has its own local database,
which stores data used in the replication process,
and other instance-specific data. The local database is invisible to replication: collections in the local database are not replicated.
=cut
my $db = $mongo_client->get_database('local');
my $ops_col = $db->get_collection('oplog.rs');
my $cursor = $ops_col->find({});
$cursor->tailable_await(1);
while(true){
say "polling\n";
while ( my $doc = $cursor->next ) {
say Dumper($doc);
}
sleep(2);
}

Saturday, January 14, 2017

Tiny-DNN: Development "as fast as possible" guide

I'm writing this as a simple instruction/refernce to get started using Tiny-DNN to build stuff as fast as possible.

I'm doing this on Ubuntu on Windows 10, Any recent Ubuntu system should have similar if not the same methods of starting.

if you don't have cmake and the gnu c++ compiles:
sudo apt-get install build-essential
sudo apt-get install cmake

(Optional)
if you want to build tiny-dnn with Intel Threading Building Blocks:

sudo apt-get install libtbb-dev

1) clone repo:

git clone https://github.com/tiny-dnn/tiny-dnn

2) Build
cd tiny-dnn

the most simple option is
cmake . 


If you're building with TBB then:
cmake -DUSE_TBB=ON

the build should end with no errors.


3) Building a program:

create a simple program 

for my system, I have to add "#include " to get the program to compile or it will start emitting build errors such as:




I'm going to use one of the sample code in the documentation that constructs a MLP.

// filename: sample.cpp
#include 
#include "tiny_dnn/tiny_dnn.h"
using namespace tiny_dnn;
using namespace tiny_dnn::activation;
using namespace tiny_dnn::layers;

void construct_mlp() {
    network net;

    net << fc(32 * 32, 300)
        << fc(300, 10);

    assert(net.in_data_size() == 32 * 32);
    assert(net.out_data_size() == 10);
}
int main()
{
        construct_mlp();
}

once done compile it (/mnt/e/linuxbuild/tiny-dnn being the directory that was cloned from github and built in #1 and #2)

g++ -pthread -std=c++11 -I /mnt/e/linuxbuild/tiny-dnn sample.cpp

The compiler should build a.out binary successfully.



Monday, September 14, 2015

Using Android Support V7 Appcompat on Eclipse

Had an interesting request - customer wanted to convert the Android Studio project to Eclipse - I did that and found a couple of weird errors including:


error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

when importing the Android Support V7 AppCompat library into Eclipse. The solution is fairly simple!

Just change the Android SDK to 23 (the latest/ Right click on appcompat project and click on Android, choose Build) and the errors will be gone.


Tuesday, June 30, 2015

SocketIO on Windows



I found recently that I was unable to install SocketIO on my Windows development platform.

The installation will throw out some errors.

It turns out that EngineIO on npm is the older version and will not work with SocketIO.


The workaround is to :


npm install Automattic/engine.io-client --save
on your local node project.

SocketIO will work after that.