Run your Linux on Android phone

As Samsung canceled its “Linux on Dex” project, there was only option to run Linux on SBC like raspberry pi, but that leave us ugly design and lack of flexibility. Why shouldn’t we use our phone to run Linux directly? So there upcoming two choices:

  1. Native phone installed Linux, eg. pinephone. Its not expensive, and very cool. You can buy it here. The downside is there are not many apps you can install…
  2. Run Linux on Android phone. So that you can install android app as well as Linux environment. All your need is three apps:
  • bNCV Free: connect to Linux GUI.
  • Termux: terminator to install Linux commands
  • AndroNix: download Linux Distro.

I was using my Samsung S8, which provides big screen projection through Dex. Dex is still an android desktop, but pretty like windows. Then I follow the steps mentioned on this YouTube.

After install Linux (I chose Ubuntu KDE), and connect to it. You can do whatever in it. Blew is my screenshot after I installed visual code.

Visual Code for ARM version

Let’s summary:

Pros:

  1. Flexibility. You don’t have to bring your laptop, but only have to find a monitor or TV.
  2. Apps. Run android and Linux apps at single phone.
  3. Very Geek.

Corns:

  1. It’s better you have a high end phone, like S20. My s8 still slow sometimes as its 3GB memory.
  2. Not native Linux. I feel its working pattern pretty like WSL on windows. Performance may be an issue.

Let Linux make your daily life easier

If you work on Windows during your most time, you must be curious about why should I shift to Linux and why suddenly Linux becomes so popular in the recently decade, even Microsoft migrated Linux kernel into latest windows version named WSL/WSL2 and run its 70% cloud service on Linux including SQL server.

Why should we use Linux?

Although Windows is still the dominate leader especially in the desktop market, more and more professional industries are moving to Linux. The emerging areas like loT device, cloud service, smart phone are all using Linux. In my points, there are several things Linux significantly better than Windows: Reliability, Software management, Hardware compatibility and Customization.

Reliability: How many times you meet blue screen and reboot on windows? Install an application —> reboot; uninstall —> reboot; change a setting —> reboot; even security upgrade will cause a reboot. On Linux, you will never worry about it. It significantly reduces downtime of server.

Software management. On windows, “Click-Installation” maybe an easy way for a normal user, but it would never be a good way for programmer or server admin. Linux adopts a repository methodology, pretty like “Android store”. We only need to run a very short script like “sudo apt install <appname>” or “sudo snap install <appname>”. Even more, we can put all scripts together as a bash, then we can leave it alone and have a cup of coffee.

Hardware compatibility. So many smart devices coming out these years. They have weaker computational ability compared to the desktop or laptop, but we can put them anywhere and let them control home security, TV, freezer or washer. You can not install windows on these device since it is too “fat”. Linux is a good choice and has a nice compatibility with ARM device.

Customization. Not everyone like flexibility. My wife, for example, likes out of box using. So I would never recommend Linux for her. but for the most geek or tech worker, Linux could provide varies distros and desktop environments. In each environment, you can also deeply customize in term of your needs.

How to set Linux for your daily life?

First thing first, you need to choose Linux distro. Linux has hundreds distros, and coming out many branches each year. but most of them are child-parent relationship. Debian, Red-hat and Arch are three most popular families. Here we look at Debian and Arch family. For the daily life, we need to use stable and easy to use one. Debian, Ubuntu, Mint Linux are all good in Debian family. Manjaro, Arch are the most popular in Arch family. Beside these, you can also find Android and ChromeOS in the left distribution map. But they are only designed for mobile or special device.

If you are beginner for Linux and want to get wiki answer quickly. Ubuntu LTS would be a good choice. In end of April, 2020, Ubuntu 20.04 LTS is going to launch.

In the following steps, I will use Ubuntu for example by default.

Second, How to install application. As I mentioned before, Linux use Repository to download and install application. Basically, Repository is like a store where you can find a list of goods(application) in it. For different Linux distros family, you would use different repositories. In Ubuntu, you can run following simple script to install application.

# update repository as root
sudo apt update
# install application
sudo apt-get install <app name>
# find the install path of application
whereis <app name>

There is another popular repository called snapcraft which is my favor. Install snapcraft is super easy: https://snapcraft.io/docs/installing-snapd. In Ubuntu, you only need to run:

sudo apt update
sudo apt install snapd 

Then in the page of application page in snapcraft, you can copy the installation code from there. I took Visual Studio Code for example blew.

“sudo snap install code -classic” is the installation script.

If you feel even script is complex, you can install snap store, which provides you “Android store” like GUI and click-install experience.

sudo snap install snap-store
Categories in Snap store

In some case, you can only find the application on the official website, like anaconda, Microsoft Team. What should we do?

For deb file, just click and install, this is the package for Debian family. If failed, use script below.

sudo dpkg -i <file name.deb>

For shell file end with “.sh” like anaconda.

# download package
wget <download URL>
# add execution mode
chmode +x <file name.sh>
# execute file
sudo ./<file name.sh>

Most applications you can find Linux version, they are some alternatives in Linux.

Windows Application NameAlternative
Google Driveinsync
EvernoteNixNote2
MS Office 365LibreOffice or office online
check point VPNSNX
my workplace

Third, Command Line. Terminal is the most important tool in Linux. Once you familiar with it, you would never use your mice. Since terminal saves you lot of time. Here I list some common commands. For more information you can check: https://files.fosswire.com/2007/08/fwunixref.pdf.

# check command meaning
man <command name>

# file operation
ls # listing files and dir
cd <path> # change to the path
pwd # show current dir
mkdir <dir> # create dir
rm <file> # delete file
rm -r <dir> # delete dir recursively
cp -r <dir1> <dir2> # copy dir1 to dir2
touch <file> # create or update file
cat > <file> # places standard input into file
more <file> output contents of file

# file permission
chmod # change file mode
chown # change owner of file

# ssh
ssh user@host

# system info
top/htop # task monitor
whereis app # app location
df # disk usage
w # who is online

# compression
tar cf file.tar files # create tar file
tar xzf file.tar.gz  # extract a tar using Gzip
tar xf file.tar # extract a tar file

# download
wget

# search 
grep <pattern>

# split terminal
tmux

# schedule
crontab

# back up 
sudo dd if=/dev/sda1 of=/media/c/back.img

What else benefit can Linux bring for you?

For big data engineer, the most popular foundation is Apache software, which provides many excellent projects, like spark, hadoop, Kafka, Maven,Tomcat. All of these are natively support Linux. And they recommend using Linux as well.

For application developer, python, java, C# have already cross platform. You can choose whatever OS you like. As I said before, you won’t meet the problems of windows in Linux, which saves you lots of time.

For administrator, Linux provides sable and flexible solutions. You would send out mails less that explains downtime for some upgrading maintenance.

Who is not recommended moving to Linux .

If you are very sticking to some software like Adobe suit, you need to leave Linux away.

CRLF vs LF

These days I am coding a Linux shell running for AZcopy, since my laptop is running windows, so I switch between two operations systems. The strange problem came soon:

  1. ./azCopyToAzure.sh: line 7: $’\r’: command not found
  2. source ./config.cfg can not found
  3. when I was using echo ${log_dir}!!!, the result is !!!XXX, basically, the !!! will come to the beginning and overwrite ${log_dir}

After wasting almost two days, I found the problem. It caused by difference between end of sequence in windows and Linux. Here is from wiki:

The term CRLF refers to Carriage Return (ASCII 13, \r) Line Feed (ASCII 10, \n). They’re used to note the termination of a line, however, dealt with differently in today’s popular Operating Systems. For example: in Windows both a CR and LF are required to note the end of a line, whereas in Linux/UNIX a LF is only required. In the HTTP protocol, the CR-LF sequence is always used to terminate a line.

https://www.owasp.org/index.php/CRLF_Injection

In vs code , we have to change this setting at the bottom of right side.

I thought there should not be many person developing bash on windows, but if you are, hope this can solve some of your problems.

Raspberry PI Security

Lots of ready-to-use opensource project can be found on internet for raspberry PI object detection. Most of them can do very well to motion detection or object classification. I am thinking how to merge them together to make a practical security system that can help all of us to make our home safety. Since It is open source, I will share my design, source code and project milestone. ( mostly to push myself to finish it eventually 🙂

Design:

  1. start camera to capture each frame
  2. save the first frame as reference. and this reference frame will be replaced every 5 mins when there is no movement detected.
  3. continuously compare the current frame with the reference frame.
  4. if any movement detected, draw some interesting areas.
  5. loop these interesting areas, if its size out of threshold, move it to next DNN network.
  6. use DNN network to classify the object.
  7. if object is human, trigger dedicated process “Event process”. includes, recording video, send notification and make speaker noise.
  8. loop to the next frame.

Milestone:

Oct 10th-15th: finish basic function to detect movement, recording video and send mail.

Oct 16th-22th: add DNN network

Oct 22th-30th: add speaker and integration test.

Potential update:

  • GPU accelerate on Cuda device
  • GUI
  • restful API

Source:

https://github.com/neoaksa/raspiberry-security

Demo(till Oct 15th):

Reference:

Deep learning: How OpenCV’s blobFromImage works. https://www.pyimagesearch.com/2017/11/06/deep-learning-opencvs-blobfromimage-works/

Raspberry Pi: Deep learning object detection with OpenCV. https://www.pyimagesearch.com/2017/10/16/raspberry-pi-deep-learning-object-detection-with-opencv/

how to install opencv on the raspberry pi 3 Model b+ (with camera) https://pysource.com/2018/10/31/raspberry-pi-3-and-opencv-3-installation-tutorial/

Home surveillance and motion detection with the Raspberry Pi, Python, OpenCV, and Dropbox. https://www.pyimagesearch.com/2015/06/01/home-surveillance-and-motion-detection-with-the-raspberry-pi-python-and-opencv/

Windows + Linux = WSL

I still remembered the song “pineapple”, the singer is a wired middle age man, looks like this: Today, what I wanna talk about is similar to “pineapple”. It’s called “WSL”.

what is WSL?

WSL is an abbr for windows subsystem for linux, where you can run linux on windows like an app.

How does it work?

very simple!

  1. run windows store , find ubuntu and install it.
  2. check the wsl option in turn windows feature on or off
    • you need to restart you computer after check it.
  3. run ubuntu as your application, all commands are same.

Where is GUI?

Sorry, by default, it is only a kernal system. So, basicly you have to run with commands. But there is a workaround: Xming. You can find detail here . I only tried two steps: install ‘Xming’ and setting display export DISPLAY=:0 . Then I did successfully run Geany with GUI! Don’t tell me you don’t know how to run app on consoler.

Existing Problem

I tried install program by sanpd, but it awalys showed me error message.

Who can try it

If you like both Linux and windows, WSL gives you a opportunity to waive the dual booting problem. You can aslo access windows drivers under /mnt/.

Have fun!

Hello world!

Well. I have to agree “Hello world” is one of my favor titles. Since I bought a raspberry pi which supposed to do some deep learning works, like object detection, I have to do something before my camera coming from amazon.

So, I guess creating a pro personal website would be a good choice. I refer “Build a LAMP Web Server with WordPress”  and “offcial website“. In an nutshell, not hard stuffs, but some points need to be care.

Installation:

    1.  if you change password through mySQL directly, you have to transfer pwd through MD5 tool, here is one.
    2. if you happen to unable to upload file, please install “sudo apt-get install php7.0-gd” and restart apache “sudo service apache2 restart“.
    3. I initially started with offical website guide, but I suddenly realized I need to install LAMP(Linux, ApacheMySQLPHP)
    4. There might be requests for setting FTP when installing plugins, this can be solved by edit wp-config.php with adding “define(‘FS_METHOD’, ‘direct’);
    5. Give www-data authority to access wordpress folder: “sudo chown -R www-data:www-data /var/www/html“, /var/www/html is my wordpress folder

Backup:

  1. UpdraftPlus would be a good choice which provides several romote storage methods inculding google dirve.

After almost 2 hours mess around, I finally  create this website on raspberry!