Table Of Content

Installation and settings

建議使用 Ubuntu Linux 20.04 LTS (或版本更高的發行套件),Linux 核心必須在 v5.4 以上,否則課程提供的範例和作業無法正確執行。

  • Try installation on Apple MacBook by multipass project

    • 步驟 from teacher:
      brew install multipass # 安裝套件

      multipass launch -c 2 -d 10G -m 2G -n ubuntu # 建立名為 ubuntu 的虛擬機器環境,其中 -c 表示 CPU 數量、-d 表示儲存裝置的容量、-m 表示主記憶體空間

      multipass shell ubuntu # 一旦上述的虛擬機器環境建立,透過本命令即可存取到 Ubuntu Linux

      uname -a # 取得 Ubuntu Linux 核心版本資訊

      lsb_release -a # 取得 Distro資訊,如:Ubuntu release

  • Update

    • On linux2022q1
      • Install the Ubuntu Linux along with macOS to my wife's MacBook Air 2014 Early
        • I followed the installation guide

          Image Not Showing Possible Reasons
          • The image file may be corrupted
          • The server hosting the image is unavailable
          • The image path is incorrect
          • The image format is not supported
          Learn More →
          use a USB Flash Drive which has full permission to read or write, otherwise, Dual-Boot Manager may not recognize the Ubuntu image correctly.

Set prompt (提示;提詞)

For GIT

Reference the offical doc: A1.6 Appendix A: Git in Other Environments - Git in Bash

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Points:

  1. Copy the prepared scripts, git-completion.sh and git-prompt.sh from contrib/completion/. in Git repo somewhere handy

    I put them in my home directory: ~/Scripts

  2. Note that to enclose the value assigned to PS1 by 'single quote', inorder to evaluate $(__git_ps1 " (%s)") correctly
    • Why?
    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
      The difference between 'single quote' and "double quote":

      reference QUOTING in man bash

      • Enclosing characters in single quotes preserves the literal value of each character within the quotes.
      • Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, \, and, when history expansion is enabled, !.

Other references

Shell

bash-it

installed plugins

Set Display to XQuartz

https://www.reddit.com/r/osx/comments/y6e59/xquartz_and_apparently_incorrectly_set_display/

  • Add the XQuartz to the Login Items
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

Use

Terminal

Backspace becomes Space key in GDB

Editors

Remotely connect the server from MAC OS X

by iTerm2

  • Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    ls output does not have colors on different types
    Original:
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    I google "iterm2 ssh no color", and was inspired from a solution:

    • Go to references window -> profiles -> Default -> Colors
    • Go to the list of Color Presets... and change the upper item from Solarized to Regular or High Contrast; the following picture shows the result of selecting Regular item:
      Image Not Showing Possible Reasons
      • The image was uploaded to a note which you don't have access to
      • The note which the image was originally uploaded to has been deleted
      Learn More →

SSH

Run graphical programs remotely

Ref.: How to install X Window System XQuartz on macOS for ssh X11 forwarding

  • Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    hung on executing the app after connecting server by ssh -Y the_server:

    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
      (guess): the localhost and the offset 11 were missed in my $DISPLAY

      • expected output:
        Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →
      • output on my server:
        ​​​​​​[10:58] asahsieh@asahsieh-MacBookAir:~$ echo $DISPLAY
        ​​​​​​:0
        

      Try to update the environment variable $DISPLAY but the system still hung on the app

      but the issue is not the root cause, please check the next item

    • Try to debug on ssh

      ref.: X11 forwarding requested but DISPLAY not set

      • append vvv option
      • and I found my issue is the same as the question: X11 forwarding requested but DISPLAY not set

      Follow one of the answers, the points are:

      • Make sure the X11 display number
        > Your DISPLAY on the local machine (*NOT* on the server side) is almost always :0.0
      • Make sure you can run X11 applications on your Mac alone first
        > You may need to install XQuartz.
      • Execute ssh -X within xterm window from XQuartz

        updated: no need to do this step

  • For better use

    1. no need to pass the -X option ssh command:
      Edit your ~/.ssh/config file:
      ​​​​​ForwardX11 yes
      
    2. you can run ssh in the background after running a GUI app as follows
      ​​​​​ssh user@server -f -X app-Name
      ​​​​​ssh nixcraft@nas01 -f -X gpass
      
  • Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    On virtual machine: Can-not-open-display-on-gitg

SSH ProxyCommand example: Going through one host to reach another server

Free up Space

Ref.:

  • Use Stacer – GUI based System Optimizer

Check use percentage of mounted devices

df -h

Migrate or Back home directory

ref.: [Partitioning/Home/Moving](https://help.ubuntu.com/community/Partitioning/Home/Moving)

  1. (Option) Mount an SD card

    How to Mount an SD Card in Linux
    How do I mount an SD card?

  2. Find the mount point for the SD card

    • by lsblk
      ​​​​​[13:10] asahsieh@asahsieh-MacBookAir:~$ lsblk
      ​​​​​NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
      ​​​​​loop0    7:0    0 131.8M  1 loop /snap/cmake/1035
      ​​​​​loop1    7:1    0 209.1M  1 loop /snap/code/91
      ​​​​​loop2    7:2    0  65.2M  1 loop /snap/gtk-common-themes/1519
      ​​​​​loop3    7:3    0 248.8M  1 loop /snap/gnome-3-38-2004/99
      ​​​​​loop4    7:4    0 110.8M  1 loop /snap/core/12725
      ​​​​​loop5    7:5    0  55.5M  1 loop /snap/core18/2344
      ​​​​​loop6    7:6    0  22.4M  1 loop /snap/universal-ctags/892
      ​​​​​loop7    7:7    0  61.9M  1 loop /snap/core20/1361
      ​​​​​loop8    7:8    0  55.5M  1 loop /snap/core18/2284
      ​​​​​loop9    7:9    0 323.5M  1 loop /snap/kde-frameworks-5-qt-5-15-core20
      ​​​​​loop10   7:10   0     4K  1 loop /snap/bare/5
      ​​​​​loop11   7:11   0 155.4M  1 loop /snap/firefox/1073
      ​​​​​loop12   7:12   0 242.3M  1 loop /snap/gnome-3-38-2004/76
      ​​​​​loop13   7:13   0   9.5M  1 loop /snap/htop/3359
      ​​​​​loop14   7:14   0   617M  1 loop /snap/libreoffice/242
      ​​​​​loop15   7:15   0  61.9M  1 loop /snap/core20/1376
      ​​​​​loop16   7:16   0  15.7M  1 loop /snap/universal-ctags/882
      ​​​​​loop17   7:17   0 110.7M  1 loop /snap/core/12821
      ​​​​​loop18   7:18   0  54.2M  1 loop /snap/snap-store/557
      ​​​​​loop19   7:19   0 625.3M  1 loop /snap/libreoffice/247
      ​​​​​loop20   7:20   0 295.7M  1 loop /snap/vlc/2344
      ​​​​​loop21   7:21   0 150.2M  1 loop /snap/okular/109
      ​​​​​loop22   7:22   0 155.3M  1 loop /snap/firefox/1115
      ​​​​​loop23   7:23   0  54.2M  1 loop /snap/snap-store/558
      ​​​​​sda      8:0    0   113G  0 disk 
      ​​​​​├─sda1   8:1    0   200M  0 part /boot/efi
      ​​​​​├─sda2   8:2    0  84.9G  0 part 
      ​​​​​└─sda3   8:3    0  27.9G  0 part /
      ​​​​​sdb      8:16   1 241.9G  0 disk 
      ​​​​​├─sdb1   8:17   1   200M  0 part 
      ​​​​​├─sdb2   8:18   1 120.8G  0 part /media/asahsieh/Transcend
      ​​​​​└─sdb3   8:19   1 120.7G  0 part /media/asahsieh/Ubuntu_data
      
    • or by fdisk -l
  3. Move data by rsync command

Ref.: How to backup your home directory in Linux

File manipulation

Replace string in file

ref.: How to use sed to find and replace text in files in Linux / Unix shell

sed -i 's/search_string/replace_string/' filename

Create and Extract .tar.bz2 or .tar.gz files

Ref.: https://www.cyberciti.biz/faq/how-to-create-tar-gz-file-in-linux-using-command-line/#Creating_tar.gz_file

  • Extract files
    • bz2
      tar -xvjf guitar_songs.tar.bz2
    • gz
      tar -xvzf ukulele_songs.tar.gz
  • Create files
    • The syntax for the tar command is as follows:
      tar -czvf filename.tar.gz /path/to/dir1
      tar -czvf filename.tar.gz /path/to/dir1 dir2 file1 file2
    • Create a tar.gz file from all pdf (".pdf") files
      tar -czvf archive.tgz *.pdf
    • To create projects.tar.gz in the current working directory, run:
      tar -czvf projects.tar.gz $HOME/projects/

Network checking

Get routing path

sudo mtr access.sifive.com -c 100 -r

Information

Directory structure

  • Typical Ubuntu filesystem hierarchy
    image alt

圖片出處: Filesystem Hierarchy Standard

Coding

reference https://www.kernel.org/doc/html/latest/

Linux kernel coding style

8) commenting

Comments are good, but there is also a danger of over-commenting. NEVER try to explain HOW your code works in a comment:

  • it’s much better to write the code so that the working is obvious, and it’s a waste of time to explain badly written code.

Generally, you want your comments to tell WHAT your code does, not HOW. Also, try to avoid putting comments inside a function body:

  • if the function is so complex that you need to separately comment parts of it, you should probably go back to chapter 6 for a while.

When commenting the kernel API functions, please use the kernel-doc format. See the files at Documentation/doc-guide/ and scripts/kernel-doc for details.

The preferred style for long (multi-line) comments is:

/*
 * This is the preferred style for multi-line
 * comments in the Linux kernel source code.
 * Please use it consistently.
 *
 * Description:  A column of asterisks on the left side,
 * with beginning and ending almost-blank lines.
 */

For files in net/ and drivers/net/ the preferred style for long (multi-line) comments is a little different.

/* The preferred comment style for files in net/ and drivers/net
 * looks like this.
 *
 * It is nearly the same as the generally preferred comment style,
 * but there is no initial almost-blank line.
 */

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
There is no initial almost-blank line.

It’s also important to comment data, whether they are basic types or derived types.

  • To this end, use just one data declaration per line (no commas for multiple data declarations).

    This leaves you room for a small comment on each item, explaining its use.

Plugins

fzf

Source: https://github.com/junegunn/fzf

Shell extensions

  • Key bindings (CTRL-T, CTRL-R, and ALT-C) (bash, zsh, fish)
  • Fuzzy auto-completion (bash, zsh)

FAQ

How to read man pages

Understanding man Pages in Linux [Beginner's Guide]

  • check the format on terminal, e.g., SYNOPSIS:
    ​​$man man  
    ​​
    ​​The following conventions apply to the SYNOPSIS section and can be used as a guide in other sections.
    
    ​​bold text          type exactly as shown.
    ​​italic text        replace with appropriate argument.
    ​​[-abc]             any or all arguments within [ ] are optional.
    ​​-a|-b              options delimited by | cannot be used together.
    ​​argument ...       argument is repeatable.
    ​​[expression] ...   entire expression within [ ] is repeatable.
    

HOW TO READ MAN PAGES

  • SYNOPSIS
    • words in [ ]: means flags for this command

References