Thursday, July 18, 2024

QEMU with command line

QEMU with command line


Introduction

QEMU is Quick emulator. This tutorial works on Qemu 9.0.1.

Installation

Debian: $ apt install qemu
Homebrew: $ brew install qemu
Linuxbrew: $ brew install qemu

Using qemu

Create image:

$ qemu-img create -f qcow2 alpine_disk.qcow2 12G
$ ls alpine_disk.qcow2
⇒ only created a 192k image file, even though it was stated to be 12G. The file will grow if it needs more space.

Launch QEMU

$ qemu-system-x86_64 \
-enable-kvm -m 2G -smp 1 \
-hda alpine_disk.qcow2 \
-boot d -cdrom alpine_linux.iso \
-netdev user,id=net0,net=192.168.0.0/24 \
-device virtio-net-pci,netdev=net0 \
-vga virtio \
-device AC97

## if no AC97 audio, just remove it
## -enable-kvm, use kernel kvm virtualization
## -cpu host, if you have this error warning: host doesn't support requested feature: CPUID.80000001H:ECX.svm [bit 2]

Hardware virtualization

Modern CPUs have hardware virtualization. Qemu performs much faster with hardware virtualization. For macOS, no KVM, use -machine type=q35,accel=hvf, for macOS virtualization framework.

## Linux -enable-kvm
## macOS -machine type=q35,accel=hvf

Install Alpine Linux

Choose Alpine Linux as an example, because it is small and simple.

Installation:

1. keymap (us,us)
2. network setting use default or [dhcp]
3. timezone [Singapore]
4. mirror [1]
5. add in new user (other than root) with username and password
6. Which disk to use [none]? sda ## depends on your system
7. How would you like to install it (sys, data, lvm…)? sys
8. Erase disk? y

Alpine Linux on Qemu

After the OS installation:

$ qemu-system-x86_64 \
-m 1G -smp 1 \
-hda alpine_disk.qcow2 \
-netdev user,id=net0,net=192.168.0.0/24 \
-device virtio-net-pci,netdev=net0 \
-nodisplay

Qemu display
## -nographic, not creating another window
## -vga virtio -display default, shows progress and login prompt

Reset terminal

If you need to reset terminal for word wrap.
$ reset
$ tput smam

Ssh from host to guest OS

Using ,hostfwd=tcp::2222-:22

## map host os port 2222 to guest os port 22
$ qemu-system-x86_64 \
…
-netdev user,id=net0,net=192.168.0.0/24,hostfwd=tcp::2222-:22
…

$ ssh user@localhost -p 2222

Thursday, July 11, 2024

Easy Install Docker On Debian 64 bit

Easy Install Docker On Debian 64 bit

This is using command line.

Easy way (Debian)

I found an easy way to install Docker on Debian 64 bit (arm64 and amd64). I just tested on Debian 12 Bookworm, didn't try on Arm platform. If you fail, may be Docker didn't provide the binary of your platform, for example Debian 32 bit.

$ apt update
$ apt upgrade
## need curl and apt-utils
$ curl -fsSL test.docker.com -o get-docker.sh && sh get-docker.sh
$ docker -v
⇒ version 27

Test Docker
$ sudo docker run hello-world ## docker need root
⇒ Hello from Docker!
If you see the Hello message, it is working.

macOS (Homebrew + Docker Desktop)

Homebrew only install the docker (client), you need a Docker daemon). Docker Desktop can start the Docker daemon. Docker Desktop is available for download, available in macOS, Windows and Linux platform.

$ brew install docker docker-compose
$ sudo docker run hello-world ## to test

You can use Colima (lima) + qemu to replace the Docker Desktop, it works.

Thursday, July 04, 2024

Unix Compress Tips (gz xz etc)

Unix Compress Tips (gz xz etc)

Another incomplete jumpstart tutorial or tips for unix compression.

There are a few types of unix compress format eg. gz, bz2, what are the differences? Z is very old unix compress, probable no one is using it now. The gz and bz2 (bzip2) is quite common for compressing text base file, eg. source code. The gz and bz2 format existed and commonly use for a long time (80s, 90s to...).

The xz is newer, it has a better compression ratio, but it also takes more resources (cpu and ram), normally used to compress large binary files. The Zip is very common in Windows systems.

The is how to compress 2 files, dummy and hello.txt:

## compress found in debian ncompress package
## '-c' to create archive, '-O' to output to stdout
## '-cO' same with '-c --to-stdout'
## '-cO' same with '-cf -'
$ tar -cO dummy hello.txt | compress -c > hello.tar.Z
⇒ hello.tar.Z

## gz, -z for gz
$ tar -czf hello.tar.gz dummy hello.txt

## bzip2, -j (capital J)
$ tar -cjf hello.tar.bz2 dummy hello.txt
⇒ hello.tar.bz2 in gzip2 format

## xz, -J
$ tar -cJf hello.tar.xz dummy hello.txt
⇒ hello.tar.xz in xz format

## zip
$ zip -r hello.zip dummy hello.txt
⇒
updating: dummy (stored 0%)
updating: hello.txt (deflated 49%)

Hope you enjoy these quick tips.

Thursday, June 27, 2024

Is Intel N100 Mini PC a Good Buy?

Is Intel N100 mini PC a good buy?

It depends on what you want to do with it. It should be good for general usage, but not for gaming.

The Intel N100 CPU was released 2023 January. It is using Alder Lake-N, base on Alder Lake but with some modification.

The Alder Lake family (aka Intel 7) is one of the latest architecture. The Alder Lake-N is the ultra low power consumption CPU, eg. N100 at 6 watts only. The Alder Lake-N has 4 E-cores (Efficient core) and no P-core (Performance care). (that’s why is cheaper?)

Integrated graphic is Iris Xe. Iris Xe is a high GPU, but it is so new that you might not able to find a proper driver for it.

N5105 using Jasper Lake architecture, which is older compare to N100. the integrate graphic cards perform comparable to the Iris Xe. Intel N5105 has Intel VT-x for virtualization. Both Intel N100 and N5105 has VT-x.

If you are working with virtualization software examples virtual box, Qemu, you might want to use the N5105, but Docker on Linux, doesn’t make use of the VT-x technology. For Docker users might want to consider using Intel N100.

Anyway talk is just theory. I am waiting for my N100 machine to delivery. Then I can do testing for reference.

Friday, June 21, 2024

Docker is good for ...

Docker is good for testing and production

Docker is a lightweight container, is small, fast and secure. Docker is easy to use (should be easy to setup as well).

Docker is good for testing and deploying. For sample, you want to test your application on Red Hat Linux. You don't want to install another machine, so your test it on Docker. For sure I prefer to test it on Alpine than Red Hat.

Sunday, December 31, 2023

Thursday, December 28, 2023

A Small Issue To Compile Usb-notify Program 2023

A Small Issue To Compile Usb-notify Program 2023

undefined reference to notify_notification_new

I like the usb-notify program a lot. This small little program displays a notification on the Linux desktop when a USB device is plugged in.

To compile I need libnotify-dev, libudev-dev package.

$ git clone https://github.com/wcampbell0x2a/usb-notify
$ cd usb-notify
$ make
⇒ bin/usb-notify

Note: Need notification-daemon running to show the notification.

It should just compile and be successful. If it doesn't it is just a small issue, but this small issue took me 1.5 days to try out many other ways, for example trying to recompile the dependency libraries.

This is what I get:

$ gcc -ansi -pedantic -g -std=c99 -W -Wextra -Wall \
`pkg-config --cflags --libs libnotify` \
-o bin/usb-notify src/usb-notify.o -ludev
…
undefined reference to `notify_notification_new'

Keep story short, there is no missing libnotify, as 'pkg-config --libs libnotify' will return '-lnotify' (refer to libnotify.a or libnotify.so), is just has to be put at the back of the compile statement:

$ gcc -o bin/usb-notify src/usb-notify.o -ludev `pkg-config --libs libnotify`

So you might just need to modify the Makefile will do.

Monday, December 04, 2023

How To Apply RM100 Government eWallet Incentive 2023

How To Apply RM100 Government eWallet Incentive 2023

Malaysia government give RM100 incentive for those those who is eligible. The RM100 can be applied through the following eWallet, Touch'n Go eWallet, MAE (Maybank), Shopee Pay, SETEL (Petronas?). Applying period is from 2023 5 December to 2024 20 February.

This RM100 can only be spent on merchants, not transferable or paying bills.

MAE

MAE app > eMadini icon > fill in information and submit.

Touch'n Go eWallet

TNG eWallet > eMadani banner > [x] agree T&C > Claim Now

OR

TNG eWallet > Profile (top right icon) > Inbox/Alert (top right) > click on the notification > confirm MyKad information > [x] agree T&C > Claim Now

Sunday, October 29, 2023

Johor Pay 2023

Johor Pay 2023



I am trying to help my aunt to make payment to property assessment fee in Johor, one of the electronic payment options is Johor Pay.

Sarawak Pay may have a chance of success, even if it is not, the residents are happily using it. Johor Pay has less of a chance, as Malaysia already has nationwide DuitNow QR, quite popular and accepted by many merchants. Is easier to ride on DuitNow QR rather than maintain its own payment network and platform.

Many Singaporeans came over to Johor Bahru. Johor Pay has to cater for Singaporean identification and mobile phone. When Johor Pay users go to Singapore or other states, they can't use Johor Pay, they have to use DuitNow.

The limitation of Johor Pay will limit the market expansion.

It is just my 2 cents.

Thursday, October 19, 2023

The mount point of Google drive in Chrome OS Linux

The mount point of Google drive in Chrome OS Linux

Chrome OS > File app > (right click on Google Drive) > select [ share to linux ]

From Chrome OS Linux, the mount point is:
/mnt/chromeos/GoogleDrive/MyDrive

Tuesday, October 17, 2023

Get Your Own Toucn'n Go eWallet QR Code

Get Your Own Toucn'n Go eWallet QR Code



TNG eWallet > Transfer > Receive (tab)

Your QR code is displayed. Your friend can scan the code and transfer money to you.

Friday, October 06, 2023

Upgrade Raspberry Pi Desktop 2022 to Debian 12

Upgrade Raspberry Pi Desktop 2022 to Debian 12



Much older Rpi Desktop

The reason I want to upgrade the Raspberry Pi Desktop to Debian 12 Bookworm is just to try out the new Linux kernel 6. The older kernel 5, released in 2019, is about 3-4 years old.

The upgrade takes me around 4 hours on my (older) machine. After upgrading, a lot of the Raspberry Pi Desktop settings were changed, and seems slower at the first glance. My advice is not to upgrade until the official release is out for Raspberry Pi Desktop OS.

How to upgrade?

Change the APT source from Bullseye (version 11) to Bookworm (12). Bullseye and bookworm are the code name for the Debian OS version.

  
# edit /etc/apt/sources.list /etc/apt/sources.list.d/raspi.list
eg. deb http://deb.debian.org/debian bookworm main contrib non-free

Monday, October 31, 2022

How To Get Maybank2u DuitNow QR Code

How To Get Maybank2u DuitNow QR Code


Use the "receive" tab to display DuitNow QR

What is a DuitNow QR code?

The easiest way is to ask the payee transfer money to DuitNow (mobile number). You can generate the DuitNow QR for the payee to scan. The DuitNow QR code is normally is red color. In Maybank app, you can specified the amount to be received.

DuitNow is Malaysia nation wide money transfer network, it normally use the mobile phone number as the account ID to receive payment. The DuitNow network can use MyKad IC, passport as account ID as well. Before you can receive payment from DuitNow, you need to active and link the DuitNow to one of you bank account.

Maybank MAE

At the home screen, click the center icon at the bottom.

It shows the camera display. On top, there are 2 tabs, scan and receive. Click on the receive tab to display to the QR code to receive payment.

Maybank2u app (to be obsolete)

At the home screen, click the center icon at the bottom.

It has 3 tabs on top of the display, scan, receive and pay. Click on the receive tab to display to the QR code to receive payment.

Monday, September 26, 2022

Washington Post Mobile App Does It Right

Washington Post mobile app does it right

Amazon reminds me, my Washington Post free subscription is going to end. Finally I opened the mobile app.

A lot of the traditional newspapers or magazines get it wrong. They put the PDF version of the newspaper (or magazine) and put it online as an online version. Washington Post is a hybrid version website and traditional version. You have a choice to display the printout layout, but once you click on the news, it will show the online version.

The PDF version is not good for mobile/desktop use, because the viewing devices may have different sizes, but the PDF format is fixed, the paragraph never wraps around according to the device. Washington Post app allows you to choose what type of news to be displayed like headlines, editor pick.

Wow! I think the Washington Post does it right.

Wednesday, September 14, 2022

iOS 16 Battery Percentage Display

iOS 16 Battery Percentage Display

iOS 16 is available for download and update. One of the changes that people are paying attention is the battery percentage displayed in the battery status bar. Anything special about this?

I just don't understand.

Tuesday, September 13, 2022

Google To Cancel Next Pixelbook

Google abandone the chromebook hardware, but hopefully they don't abandon the Chrome OS.

The chromeOS is a good idea and good implementation. It is a Chrome browser running on Linux, it also has Android framework, so it can run Android apk app. It also has a Debian-like Linux which runs in a VM container.

Only Linux users will appreciate chromeOS.

Thursday, August 04, 2022

Object Oriented Concept For Programmer 2022

Object Oriented Concept For Programmer

This is for beginners.

I try to explain object oriented programming is different ways, especially for beginners.

There are 4 things in OOP: Abstraction, Inheritance, Encapsulation and Polymorphism.

Example: Shape (abstraction)

Shape has area, this is abstract. You don't how's the shape looks like (circle? triangle?), and you are not sure about the size of the shape.

Shape().area # let's say this is how you define the Shape() object.

Example: Circle (Inheritance)

Circle is a shape, so circle has area. Why? Circle inherit the area properties from Shape.

Circle() is Shape()

Example: Circle (Encapsulation)

You don't allow anyone to change the area of a circle. The area of a circle can only be change by the radius. I use the private keyword to protect the Circle().area.

private Circle().area
Circle().area= pi * radius * radius
Circle().get_area()= area

Direct access of area outside of the object invoke an error:
print Circle().area ==> error
print Circle().get_area() ==> 20.5

Example: Square and rectangle (Polymorphism)

Square and rectangle are similar. Square is another form of rectangle, or you can say that rectangle is another form of square.

Square() is Shape()
Square().get_area(height)= height * height # formula for square
Square().get_area(height,width)= height * width # formula for rectangle

You can have 2 functions with the same name for Square() object, this is polymorphism.

print Square().get_area(5)
print Square().get_area(5,4) # this is for rectangle

Note: In C programming language, there are 2 commands for string copy 1. strcpy(t,s) 2. strncpy(t,s,n). In OOP, you can merge these 2 commands into 1 with the same name, but differentiate by number of parameters.

Thursday, May 12, 2022

Using Java For Object Oriented Programming For Beginners

Using Java For Object Oriented Programming For Beginners

I find it easier to use Java programming language to write object oriented program, compare to Python and C++.

C++ is powerful, but I find it complicated. There are advantages using C++. GNU GCC compiler support C++, you don’t have to install another bloated Java C compiler and Java runtime.

Python is easy to learn and use, but the object oriented feature is limited.

I am using the classic example, get the area of a shape, circle and rectangle.


Python
$ edit shape.py
from math import pi
class shape:
    ''' class shape '''
    def __init__(self):
        pass

    def get_area(self):
        return 0

class rectangle(shape):
    def get_area(self,height,width=0):
      return height*width

class circle(shape):
    def get_area(self,radius):
        return pi*radius**2

print(rectangle().get_area(5,4))
print(circle().get_area(5))
Java
abstract class Shape {
	abstract int getArea();
}

class Rectangle extends Shape {
// implement nothing here, will generate error
}
$ javac Rectangle.java
==> error

In Python, if you don't implement rectangle().get_area(), there is no error. The rectangle().get_area() will always return 0 as stated in shape().get_area(). In Java, the compiler error tell you to implement getArea() in subclass.


$ edit Rectangle.java
class Rectangle extends Shape {
	int getArea() { return 0; }

	int getArea(int height, int width) {
		return height*width;
	}
}
  

Polymorphism

Square is a polymorphism of rectangle. They looks the same, the different is square has the same height and width.

Python
$ edit shape.py # add in the code
...
class rectangle(shape):
    def get_area(self,height,width=0):
        if width==0:
            return height*height
        return height*width

sq= rectangle()
print(rectange().get_area(5,4))
print(sq.get_area(4))
...
  

I use a if statement to determine the diffrent code for rectangle and square. The code will look messy if the implementation for rectangle and square are complicated. In java, you can split into 2 methods, like this:


Java
$ edit Rectangle.java

class Rectangle extends Shape {
	int getArea() { return 0; }

	int getArea(int height, int width) {
		return height*width;
	}

	int getArea(int height) {  // this is for square
		return height*height;		
	}
}
  

Polymorphism 2: Waterworld

Let's says the mutant has lungs and gills to breath above water and under water.


$ edit waterworld.py
class air:
	def __init__(self):
		pass

class water:
	def __init__(self):
		pass

class mutant:
	def __init__(self):
		pass
	def breath(self,media):
		if type(media)==air:
			print('use lungs')
		elif type(media)==water:
			print('use gills')
		else:
			print('can not breath')

mariner=mutant();
for m in (air(),water()):
	mariner.breath(m)
  
Java

How do you implement in Java? Tips: create Java object Air and Water. Create 2 methos in Mutant object: 1. breate(Air) 2. breate(Water).

Thursday, April 28, 2022

Print Transaction History Receipt RHB Maybank2u 2022

Print Transaction History Receipt RHB Maybank2u 2022

Re-print the receipt from online banking is an important function. As a prove to the receipiant party a transaction has been done. You can reprint it in RHB and Maybank2u, through the old website and not the new website (yet).

Maybank2u classic

Switch to the classic website.


Maybank2u classic (old) > Account & Banking > Account Details > M2U history > [ Reprint ]

Those transactions done by mobile app, can be reprint as well.

RHB Now

Note : If your transactions are done with the mobile app or the new website, the transaction receipt can not be re-printed again. Only transactions done with RHB Now web version can be re-printed again.

RHB Now > RHB Now Transaction Records (above/besides the email button) > choose date range and type of transaction.

    Account number :[   ]
    From: [    ] dd/mm/yyyy
    To:   [    ] dd/mm/yyyy
    ---- down here has a long list of selection ----
    (I only show some of it)
    JomPay
    [ ] Favourite Biller
    [ ] Open Payment
    
    [Submit]

Conclusion

Maybank2u is easier, and more powerful.

Thursday, April 21, 2022

How To Deregister Fire HD Tablet

How To Deregister Amazon Fire HD Tablet

If you want to give away your Amazon Fire HD tablet to the others (as a gift or selling it), make sure it is deregister with you user account. This apply to other Alexa devices as well.

There are a few ways to deregister:

From the device (Fire HD)

Fire OS > Settings > My Account > [DEREGISTER]

Refer to the picture above.

From the web (need Amazon login)

For me this is easiest and powerful. Not just for deregister, but other configuration and setting as well. Remember this website https://amazon.com/mycd/:

Devices tab > (choose Fire Tablet) > (choose table or device name) > [Deregister]

You can change your device name from here as well.

From Alexa mobile app

Alexa app > Devices tab (lower right) > Echo & ALEXA > setting icon (top right) > Registered To [Deregister]

Note: This doesn't works for my Fire TV stick, and Fire HD tablet. It works for Echo Show, Echo Dot, and some other 3rd party devices.