How to use the Ubuntu

How to use the Ubuntu

Introduction

As far as I have noted, I will force myself to write all my blogs in English. So, if you are lucky or unlucky, you have read this blog, and I hope it can be helpful to you. Reading an English document can be a tricky task, as well as writing a blog in English.

In this blog, I will record all the problems that I encountered and the possible feasible solutions to them (you know, no model of solution is universal), including my train of thought.

And I’ll avoid any unnecessary usage of images because the official document always has no images.

I’ll write the references at the end of this article, if you are interested in them, just visit them. And I also will mention some of them in the relevant part of the article.

And, as I’m still a beginner at coding, and my mother tongue is not English, but Chinese, if there are any problems, point them out and try to let me know.

Emm, as this blog is so long I might have no mood to overwrite it in Chinese again.

Using English can prevent the fool from copying others’ blogs without any needed illustrations and make the readers think more about it(as time goes by, you will have to take tea with the projects or documents that are written in English, you could just regard my article as the first step for you to adapt the environment of English, and I’ll try my best to make my blog be friendly to read, using the words that human can realize not like those using words just like the alien), at least in the world of our Chinese, just in my own opinion.

This blog needs to be updated in the future, I just hope that I’ll have the time and mood to do so.

Note:

  • My system is Ubuntu 24.04 LTS​.
  • I chose English as the default language option when I installed the Ubuntu system.
  • All the references I will list at the end of this blog, are named References​.
  • References don’t mean that I use them in this blog, maybe I add them just because of that I regard them as supplementary material to the related part.


Catalog

文章目录



Why my apt doesn’t work

sudo apt update​, fail to connect.

Just like what we have done to Python, we should change the source of the Ubuntu to avoid such a kind of problem.

Visit https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/, and follow the guide, and then it works.

  1. cd /etc/apt/sources.list.d/

  2. sudo cp ubuntu.sources ubuntu.sources.bak

  3. sudo vim ubuntu.sources​(My system is Ubuntu 24.04 LTS​, apply the format of DEB822)

    Types: deb
    URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
    Suites: noble noble-updates noble-backports
    Components: main restricted universe multiverse
    Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    # Types: deb-src
    # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
    # Suites: noble noble-updates noble-backports
    # Components: main restricted universe multiverse
    # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
    Types: deb
    URIs: http://security.ubuntu.com/ubuntu/
    Suites: noble-security
    Components: main restricted universe multiverse
    Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # Types: deb-src
    # URIs: http://security.ubuntu.com/ubuntu/
    # Suites: noble-security
    # Components: main restricted universe multiverse
    # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # Types: deb
    # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports
    # Suites: noble-security
    # Components: main restricted universe multiverse
    # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # Types: deb-src
    # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports
    # Suites: noble-security
    # Components: main restricted universe multiverse
    # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # 预发布软件源,不建议启用
    
    # Types: deb
    # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
    # Suites: noble-proposed
    # Components: main restricted universe multiverse
    # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # # Types: deb-src
    # # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
    # # Suites: noble-proposed
    # # Components: main restricted universe multiverse
    # # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
  4. sudo apt update

You may encounter this question fcitx-team-ubuntu-nightly-noble​ not found 404.

Don’t worry, just need to run this command sudo mv /etc/apt/sources.list.d/fcitx-team-ubuntu-nightly-noble.sources /etc/apt/sources.list.d/fcitx-team-ubuntu-nightly-noble.sources.bak​.

It works.


Emm, how can I run the AppImage​?

Problems I encountered

Sometimes, you can install the application by using the App Center​, and it is practicable for basic usage. But, if the software that you want to install is not accessible by the App Center​, you might turn to the website or other channel to access it.

Then, you may be confused about the things that I list below(e.g. https://b3log.org/siyuan/en/download.html):

  • AppImagex86_64arm64
  • debx86_64arm64
  • tar.gzx86_64arm64
  • Source

As the recommended option is AppImage​, I will focus on it(If I need to introduce other options in the future, like deb​ or tar.gz​, maybe I will make the supplement for it).

So, I installed it and didn’t know how to run it. I clicked it like I have done in the Windows system, but it didn’t work.

I realized it was time for me to STFW​, and I did it(if you are interested in it or just want to explore it in hand, you can click here).

AppImages require FUSE version 2 to run. Filesystem in Userspace (FUSE) is a system that lets non-root users mount filesystems.

So, if you want to run the AppImage, you need to install the FUSE. (For more details, just visit the https://github.com/AppImage/AppImageKit/wiki/FUSE)

  • Ubuntu>=24.04

    sudo add-apt-repository universe
    sudo apt install libfuse2t64
    
  • Ubuntu>=22.04

    sudo add-apt-repository universe
    sudo apt install libfuse2
    


Why do we use the AppImage

AppImage provides a way for upstream developers to provide “native” binaries for Linux users just the same way they could do for other operating systems.

It allow packaging applications for any common Linux based operating system, e.g., Ubuntu, Debian, openSUSE, RHEL, CentOS, Fedora etc.

AppImages come with all dependencies that cannot be assumed to be part of each target system in a recent enough version and will run on most Linux distributions without further modifications.

In conclusion, you can regard the AppImage as a universal format of applications that can be run in any common Linux.

In general, It is not installed on your system, so if you want to uninstall it, just remove it.

If it is automatically integrated with your desktop, you may need to remove the desktop files manually.

AppImage features:

  • Distribution agnostic: Can run on various different Linux distributions
  • No need of installing and compiling software: Just click and play
  • No need for root permission: System files are not touched
  • Portability: Can be run anywhere including live disks
  • Apps are in read-only mode
  • Software is removed just by deleting the AppImage file
  • Applications packaged in AppImage are not sandboxed by default.


How to run the AppImage

You exactly have three methods to run an AppImage, by GUI, terminal, or desktop.

GUI

  1. Open your file manager and browse to the location of the AppImage
  2. Right-click on the AppImage and click the ‘Properties’ entry
  3. Switch to the Permissions tab and
  4. Click the ‘Allow executing file as program’ checkbox if you are using a Nautilus-based file manager (Files, Nemo, Caja), or click the ‘Is executable’ checkbox if you are using Dolphin, or change the ‘Execute’ drop down list to ‘Anyone’ if you are using PCManFM
  5. Close the dialog
  6. Double-click on the AppImage file to run

I think the guide from the official document is enough, and it did work when I had a try.


Terminal

Use the command chmod a+x <AppImage File>​, then you can double-click it to run it.

But if you want to run it by using ./<AppImage File>​, it can be a tricky task(maybe not, not every AppImage will cause such a kind of problem).

You can see that the error message may be shown like this:

[51026:0926/080644.846932:FATAL:setuid_sandbox_host.cc(158)] The SUID sandbox helper binary was found, but is not configured correctly. Rather than run without sandboxing I’m aborting now. You need to make sure that /tmp/.mount_SiYuanBgR0wT/chrome-sandbox is owned by root and has mode 4755.
Trace/breakpoint trap (core dumped)

You might want to solve it in this way:

  1. sudo chown root /tmp/.mount_SiYuanBgR0wT/chrome-sandbox
  2. sudo chmod 4755 /tmp/.mount_SiYuanBgR0wT/chrome-sandbox

But it didn’t work(It might work in some AppImage).

chown: cannot access ‘/tmp/.mount_SiYuanBgR0wT/chrome-sandbox’: No such file or directory

You may not encounter this kind of problem in other AppImage files, but I’m not lucky enough.

But at least, I can double-click it to run it.

OK, may this command work. sudo ./SiYuan.AppImage

[0926/082147.923059:FATAL:electron_main_delegate.cc(295)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Trace/breakpoint trap

sudo ./SiYuan.AppImage --no-sandbox

Many errors, and it didn’t work. STFW​ again, this time, I turn to askubuntu.com​ for help.

https://askubuntu.com/questions/1512287/obsidian-appimage-the-suid-sandbox-helper-binary-was-found-but-is-not-configu

Try this command ./SiYuan.AppImage --no-sandbox​.

It works, but it’s not safe.

Someone provides a safe solution. But it didn’t work for me.

SiYuan.AppImage --appimage-extract

SiYuan.AppImage: command not found

Now, go to the official document for possible help.

OK, it still didn’t work for me, just put it aside.


Desktop

You might want to use the AppImage as how you use the Firefox, but how can it be searched in Show Apps​, and be added to the Dock​?

The answer is: .desktop​.

  1. [sudo] vim <AppImage file>.desktop​ file(if you directly edit it on the location that I listed below, you may need sudo​)

  2. Edit it like this

    [Desktop Entry]
    Encoding=UTF-8
    Type=Application
    #Name of the Application
    Name=LANDrop
    #The path of the Application icon
    Icon=/home/user/图片/APP.svg
    #Whether open the terminal when starting it
    Terminal=false
    #The path of the AppImage
    Exec=/home/user/APP/APP.AppImage
    #The categories of the AppImage
    Categories=Utility;
    
  3. After editing the .desktop​ file, you can mv​ it to the location listed below(based on your request):

    • /usr/share/applications/

      • System Area, Showed to All users, Managed by System Package Manager.
    • /usr/local/share/applications/

      • System Area, Showed to All users, Manually managed or installed.
    • ~/.local/share/applications/

      • Only Shown to the current user, Manually managed or installed.
  4. Then you can use this command to make it able to execute

    • sudo chmod a+x <AppImage file>.desktop​(if the owner is root)

      • Also, you can use the chown​ to change the owner of this file.
    • sudo chmod u+x <AppImage file>.desktop

  5. After that, you can find it in your Show Apps​, use it, or add it to the Dock​.

Note: If you want to run SiYuan​, you may have to add the option --no-sandbox​ to the Exec​.


How about creating the .desktop file automatic

If every time we have to write all of this manually, it is repetitive. So, how about writing a function in bash?

[Desktop Entry]
Encoding=UTF-8
Type=Application
#Name of the Application
Name=LANDrop
#The path of the Application icon
Icon=/home/user/图片/APP.svg
#Whether open the terminal when starting it
Terminal=false
#The path of the AppImage
Exec=/home/user/APP/APP.AppImage
#The categories of the AppImage
Categories=Utility;

Assume that I always put the AppImage file in the path like ~/Applications/<AppImage file dir>/<AppImage file>​.

We may only want to type the name of the application, and set the default value for the Encoding​, Type​, Terminal​, Exec​, and Categories​.

Remember this?

  • /usr/local/share/applications/

    • System Area, Showed to All users, Mannually managed or installed
  • ~/.local/share/applications/

    • Only Showed to the current user, Mannually managed or installed

We can write the .sh​ to achieve it.

  • For ~/.local/share/applications/ ​ (In general, recommending to use this path)

    • UInAppImage.sh​ Used for init the AppImage to your desktop

      #!/bin/bash
      
      # Function to initialize an AppImage for the current user
      UInAppImage() {
          local app_dir
          local app_name_base
          local app_icon
          local use_default_icon_extension
          local use_default_icon_path
          local exec_options=""
      
          # Get the base directory where all AppImages are stored
          local appimage_base_dir=~/Applications
      
          # Check if the base directory for AppImages exists
          if [[ ! -d "$appimage_base_dir" ]]; then
              read -p "The directory $appimage_base_dir does not exist. Do you want to create it? (y/n): " create_dir
              if [[ "$create_dir" == "y" || "$create_dir" == "Y" ]]; then
                  mkdir -p "$appimage_base_dir"
                  if [[ $? -ne 0 ]]; then
                      echo "Failed to create directory $appimage_base_dir."
                      return 1
                  fi
              else
                  read -p "Enter the full path for the AppImage directory: " appimage_base_dir
                  if [[ ! -d "$appimage_base_dir" ]]; then
                      echo "The specified directory does not exist."
                      return 0
                  fi
              fi
          fi
      
          # Prompt the user for the AppImage file directory
          read -p "Enter the AppImage file directory (relative to $appimage_base_dir): " app_dir
      
          # Create the directory if it does not exist
          mkdir -p "$appimage_base_dir/$app_dir"
      
          # Validate if the AppImage directory was created successfully
          if [[ ! -d "$appimage_base_dir/$app_dir" ]]; then
              echo "Error: Failed to create AppImage directory."
              return 1
          fi
      
          # Prompt the user for the base application's name (without .AppImage)
          read -p "Enter the base name of the application (do not include '.AppImage'): " app_name_base
      
          # Validate application base name
          if [[ -z "$app_name_base" ]]; then
              echo "Error: Application base name cannot be empty."
              return 1
          fi
      
          # Construct the full application name with .AppImage
          local app_name="${app_name_base}.AppImage"
          local app_exec="$appimage_base_dir/$app_dir/$app_name"
      
          # Check if the AppImage file exists and add execute permissions if necessary
          if [[ -f "$app_exec" ]]; then
              echo "AppImage file found. Adding execute permissions..."
              chmod +x "$app_exec"
          else
              echo "Error: AppImage file does not exist."
              return 1
          fi
      
          # Determine if the user wants to use the default .png extension for the icon
          read -p "Would you like to use the default .png extension for the icon? (y/n): " use_default_icon_extension
          if [[ "$use_default_icon_extension" == "y" || "$use_default_icon_extension" == "Y" ]]; then
              # Offer to use the default icon path
              read -p "Would you like to use the default icon path ($appimage_base_dir/$app_dir/)? (y/n): " use_default_icon_path
              if [[ "$use_default_icon_path" == "y" || "$use_default_icon_path" == "Y" ]]; then
                  # Use default icon path
                  app_icon="$appimage_base_dir/$app_dir/${app_name_base}.png"
              else
                  # User wants to specify the icon path
                  read -p "Enter the full path of the application icon: " app_icon
              fi
          else
              # Offer to use the default icon path without default extension
              read -p "Would you like to use the default icon path ($appimage_base_dir/$app_dir/) without default extension? (y/n): " use_default_icon_path
              if [[ "$use_default_icon_path" == "y" || "$use_default_icon_path" == "Y" ]]; then
                  # Use default icon path without default extension
                  app_icon="$appimage_base_dir/$app_dir/${app_name_base}"
              else
                  # User wants to specify the icon path and extension
                  read -p "Enter the full path of the application icon: " app_icon
              fi
          fi
      
          # Validate icon path
          if [[ ! -f "$app_icon" ]]; then
              echo "Error: Icon file does not exist."
              return 1
          fi
      
          # Check if ~/.local/share/applications directory exists, create if not
          local desktop_dir="$HOME/.local/share/applications"
          if [[ ! -d "$desktop_dir" ]]; then
              echo "Creating $desktop_dir directory..."
              mkdir -p "$desktop_dir"
          fi
      
          # Create the .desktop file path
          local desktop_file_path="$desktop_dir/${app_name_base}.desktop"
      
          # Check if .desktop file already exists
          if [[ -e "$desktop_file_path" ]]; then
              read -p "A .desktop file already exists. Do you want to replace it? (y/n): " replace_desktop
              if [[ "$replace_desktop" != "y" && "$replace_desktop" != "Y" ]]; then
                  echo "Operation canceled. The .desktop file was not replaced."
                  return 0
              fi
              # Remove the existing .desktop file
              rm "$desktop_file_path"
          fi
      
          # Prompt for adding --no-sandbox option to Exec
          read -p "Do you want to add --no-sandbox option to Exec? (y/n): " use_sandbox
          if [[ "$use_sandbox" == "y" ]]; then
              exec_options="--no-sandbox"
          fi
      
          # Create the .desktop file
          cat > "${app_name_base}.desktop" << EOF
      [Desktop Entry]
      Encoding=UTF-8
      Type=Application
      Name=$app_name_base
      Icon=$app_icon
      Terminal=false
      Exec="$app_exec" $exec_options
      Categories=Utility;
      EOF
      
          # Make the .desktop file executable
          chmod +x "${app_name_base}.desktop"
      
          # Move the .desktop file to the applications directory
          mv "${app_name_base}.desktop" "$desktop_file_path"
      
          # Inform the user of the created .desktop file
          echo "The .desktop file has been created at: $desktop_file_path"
      }
      
      # Call the function to initialize the AppImage for the current user
      UInAppImage
      
      
    • UUnAppImage.sh​ Used for uninstall the AppImage(but may have some requirements to your construction of directories)

      #!/bin/bash
      
      # Function to uninstall an AppImage for the current user
      UUnAppImage() {
          local app_dir
          local app_name_base
          local app_exec
          local desktop_file_path
          local icon_file_path
          local appimage_base_dir=~/Applications  # Base directory where all AppImages are stored
      
          # Prompt the user for the AppImage file directory
          read -p "Enter the AppImage file directory (relative to $appimage_base_dir): " app_dir
      
          # Prompt the user for the base application's name (without .AppImage)
          read -p "Enter the base name of the application (do not include '.AppImage'): " app_name_base
      
          # Construct the full application name with .AppImage
          app_exec="$appimage_base_dir/$app_dir/$app_name_base.AppImage"
      
          # Ask if the user wants to remove the AppImage file
          read -p "Do you want to remove the AppImage file? [y/N]: " remove_appimage
          if [[ "$remove_appimage" =~ ^[Yy]$ ]]; then
              if [[ -f "$app_exec" ]]; then
                  echo "Removing AppImage: $app_exec"
                  rm "$app_exec"
      
                  # Check if the removal was successful
                  if [[ $? -eq 0 ]]; then
                      echo "AppImage removed successfully."
                  else
                      echo "Failed to remove AppImage."
                      return 1
                  fi
              else
                  echo "AppImage does not exist."
                  return 1
              fi
          else
              echo "Skipping removal of AppImage."
          fi
      
          # Ask if the user wants to remove the .desktop file
          read -p "Do you want to remove the .desktop file? [y/N]: " remove_desktop
          if [[ "$remove_desktop" =~ ^[Yy]$ ]]; then
              desktop_file_path="$HOME/.local/share/applications/$app_name_base.desktop"
              if [[ -f "$desktop_file_path" ]]; then
                  echo "Removing .desktop file: $desktop_file_path"
                  rm "$desktop_file_path"
                  if [[ $? -eq 0 ]]; then
                      echo ".desktop file removed successfully."
                  else
                      echo "Failed to remove .desktop file."
                  fi
              else
                  echo ".desktop file does not exist."
              fi
          else
              echo "Skipping removal of .desktop file."
          fi
      
          # Ask if the user wants to remove the application icon
          read -p "Do you want to remove the application icon? [y/N]: " remove_icon
          if [[ "$remove_icon" =~ ^[Yy]$ ]]; then
              icon_file_path="$appimage_base_dir/$app_dir/${app_name_base}.png"
              if [[ -f "$icon_file_path" ]]; then
                  echo "Removing icon file: $icon_file_path"
                  rm "$icon_file_path"
                  if [[ $? -eq 0 ]]; then
                      echo "Icon file removed successfully."
                  else
                      echo "Failed to remove icon file."
                  fi
              else
                  echo "Icon file does not exist."
              fi
          else
              echo "Skipping removal of icon file."
          fi
      
          # Ask if the user wants to remove the AppImage directory
          read -p "Do you want to remove the AppImage directory ($app_dir)? [y/N]: " remove_app_dir
          if [[ "$remove_app_dir" =~ ^[Yy]$ ]]; then
              app_dir_path="$appimage_base_dir/$app_dir"
              if [[ -d "$app_dir_path" ]]; then
                  echo "Removing AppImage directory: $app_dir_path"
                  rm -r "$app_dir_path"
                  if [[ $? -eq 0 ]]; then
                      echo "AppImage directory removed successfully."
                  else
                      echo "Failed to remove AppImage directory."
                  fi
              else
                  echo "AppImage directory does not exist."
              fi
          else
              echo "Skipping removal of AppImage directory."
          fi
      
          echo "Uninstallation process completed."
      }
      
      # Call the function to uninstall the AppImage for the current user
      UUnAppImage
      
      
  • For /usr/local/share/applications/

    • AUInAppImage.sh​ Used for init the AppImage

      #!/bin/bash
      
      # Function to initialize an AppImage for all users
      AUInAppImage() {
          local app_dir
          local app_name_base
          local app_icon
          local use_default_icon_extension
          local use_default_icon_path
          local exec_options=""
          local desktop_file_path
      
          # Get the base directory where all AppImages are stored
          local appimage_base_dir=~/Applications
      
          # Check if the base directory for AppImages exists
          if [[ ! -d "$appimage_base_dir" ]]; then
              read -p "The directory $appimage_base_dir does not exist. Do you want to create it? (y/n): " create_dir
              if [[ "$create_dir" == "y" || "$create_dir" == "Y" ]]; then
                  mkdir -p "$appimage_base_dir"
                  if [[ $? -ne 0 ]]; then
                      echo "Failed to create directory $appimage_base_dir."
                      return 1
                  fi
              else
                  read -p "Enter the full path for the AppImage directory: " appimage_base_dir
                  if [[ ! -d "$appimage_base_dir" ]]; then
                      echo "The specified directory does not exist."
                      return 0
                  fi
              fi
          fi
      
          # Prompt the user for the AppImage file directory
          read -p "Enter the AppImage file directory (relative to $appimage_base_dir): " app_dir
      
          # Create the directory if it does not exist
          mkdir -p "$appimage_base_dir/$app_dir"
      
          # Validate if the AppImage directory was created successfully
          if [[ ! -d "$appimage_base_dir/$app_dir" ]]; then
              echo "Error: Failed to create AppImage directory."
              return 1
          fi
      
          # Prompt the user for the base application's name (without .AppImage)
          read -p "Enter the base name of the application (do not include '.AppImage'): " app_name_base
      
          # Validate application base name
          if [[ -z "$app_name_base" ]]; then
              echo "Error: Application base name cannot be empty."
              return 1
          fi
      
          # Construct the full application name with .AppImage
          local app_name="${app_name_base}.AppImage"
          local app_exec="$appimage_base_dir/$app_dir/$app_name"
      
          # Check if the AppImage file exists and add execute permissions if necessary
          if [[ -f "$app_exec" ]]; then
              echo "AppImage file found. Adding execute permissions..."
              chmod +x "$app_exec"
          else
              echo "Error: AppImage file does not exist."
              return 1
          fi
      
          # Determine if the user wants to use the default .png extension for the icon
          read -p "Would you like to use the default .png extension for the icon? (y/n): " use_default_icon_extension
          if [[ "$use_default_icon_extension" == "y" || "$use_default_icon_extension" == "Y" ]]; then
              # Offer to use the default icon path
              read -p "Would you like to use the default icon path ($appimage_base_dir/$app_dir/)? (y/n): " use_default_icon_path
              if [[ "$use_default_icon_path" == "y" || "$use_default_icon_path" == "Y" ]]; then
                  # Use default icon path
                  app_icon="$appimage_base_dir/$app_dir/${app_name_base}.png"
              else
                  # User wants to specify the icon path
                  read -p "Enter the full path of the application icon: " app_icon
              fi
          else
              # Offer to use the default icon path without default extension
              read -p "Would you like to use the default icon path ($appimage_base_dir/$app_dir/) without specifying the extension? (y/n): " use_default_icon_path
              if [[ "$use_default_icon_path" == "y" || "$use_default_icon_path" == "Y" ]]; then
                  # Use default icon path without specifying the extension
                  app_icon="$appimage_base_dir/$app_dir/${app_name_base}"
              else
                  # User wants to specify the icon path and extension
                  read -p "Enter the full path of the application icon: " app_icon
              fi
          fi
      
          # Validate icon path
          if [[ ! -f "$app_icon" ]]; then
              echo "Error: Icon file does not exist."
              return 1
          fi
      
          # Check if /usr/local/share/applications directory exists, create if not
          local desktop_dir="/usr/local/share/applications"
          if [[ ! -d "$desktop_dir" ]]; then
              echo "Creating $desktop_dir directory..."
              mkdir -p "$desktop_dir"
          fi
      
          # Create the .desktop file path
          desktop_file_path="$desktop_dir/${app_name_base}.desktop"
      
          # Check if .desktop file already exists
          if [[ -e "$desktop_file_path" ]]; then
              read -p "A .desktop file already exists. Do you want to replace it? (y/n): " replace_desktop
              if [[ "$replace_desktop" != "y" && "$replace_desktop" != "Y" ]]; then
                  echo "Operation canceled. The .desktop file was not replaced."
                  return 0
              fi
              # Remove the existing .desktop file
              rm "$desktop_file_path"
          fi
      
          # Prompt for adding --no-sandbox option to Exec
          read -p "Do you want to add --no-sandbox option to Exec? (y/n): " use_sandbox
          if [[ "$use_sandbox" == "y" ]]; then
              exec_options="--no-sandbox"
          fi
      
          # Create the .desktop file
          cat > "${app_name_base}.desktop" << EOF
      [Desktop Entry]
      Encoding=UTF-8
      Type=Application
      Name=$app_name_base
      Icon=$app_icon
      Terminal=false
      Exec="$app_exec" $exec_options
      Categories=Utility;
      EOF
      
          # Make the .desktop file executable
          chmod +x "${app_name_base}.desktop"
      
          # Check if the user is root to determine if sudo is needed
          if [[ $EUID -ne 0 ]]; then
              echo "This action requires sudo privileges."
              sudo mv "${app_name_base}.desktop" "$desktop_file_path"
              if [[ $? -ne 0 ]]; then
                  echo "Failed to move .desktop file. Please check your permissions."
                  return 1
              fi
          else
              mv "${app_name_base}.desktop" "$desktop_file_path"
          fi
      
          # Inform the user of the created .desktop file
          echo "The .desktop file has been created at: $desktop_file_path"
      }
      
      # Call the function to initialize the AppImage for all users
      AUInAppImage
      
      
    • AUUnAppImage.sh​ Used for uninit the AppImage

      #!/bin/bash
      
      # Function to uninstall an AppImage for all users
      AUUnAppImage() {
          local app_dir
          local app_name_base
          local app_exec
          local desktop_file_path
          local icon_file_path
          local appimage_base_dir=~/Applications  # Base directory where all AppImages are stored
          local use_default_icon_path
      
          # Check if the base directory for AppImages exists
          if [[ ! -d "$appimage_base_dir" ]]; then
              echo "The directory $appimage_base_dir does not exist."
              return 0
          fi
      
          # Prompt the user for the AppImage file directory
          read -p "Enter the AppImage file directory (relative to $appimage_base_dir or absolute path): " app_dir
      
          # Construct the full application name with .AppImage
          read -p "Enter the base name of the application (including any non-default extension, do not include '.AppImage'): " app_name_base
          local app_name="${app_name_base}.AppImage"
          app_exec="$appimage_base_dir/$app_dir/$app_name"
      
          # Ask if the user wants to remove the AppImage file
          read -p "Do you want to remove the AppImage file? [y/N]: " remove_appimage
          if [[ "$remove_appimage" =~ ^[Yy]$ ]]; then
              if [[ -f "$app_exec" ]]; then
                  echo "Removing AppImage: $app_exec"
                  rm "$app_exec"
                  if [[ $? -eq 0 ]]; then
                      echo "AppImage removed successfully."
                  else
                      echo "Failed to remove AppImage."
                      return 1
                  fi
              else
                  echo "AppImage does not exist."
                  return 1
              fi
          fi
      
          # Determine if the user wants to use the default icon path
          read -p "Would you like to use the default icon path ($appimage_base_dir/$app_dir/)? (y/n): " use_default_icon_path
          if [[ "$use_default_icon_path" == "y" || "$use_default_icon_path" == "Y" ]]; then
              app_icon="$appimage_base_dir/$app_dir/${app_name_base}.png"
          else
              read -p "Enter the full path of the application icon: " app_icon
          fi
      
          # Ask if the user wants to remove the application icon
          if [[ -f "$app_icon" ]]; then
              read -p "Do you want to remove the application icon? [y/N]: " remove_icon
              if [[ "$remove_icon" =~ ^[Yy]$ ]]; then
                  echo "Removing icon file: $app_icon"
                  rm "$app_icon"
                  if [[ $? -eq 0 ]]; then
                      echo "Icon file removed successfully."
                  else
                      echo "Failed to remove icon file."
                  fi
              fi
          else
              echo "Icon file does not exist."
          fi
      
          # Construct the .desktop file path
          desktop_file_path="/usr/local/share/applications/${app_name_base}.desktop"
          if [[ -f "$desktop_file_path" ]]; then
              read -p "Do you want to remove the .desktop file? [y/N]: " remove_desktop
              if [[ "$remove_desktop" =~ ^[Yy]$ ]]; then
                  echo "Removing .desktop file: $desktop_file_path"
                  if [[ $EUID -ne 0 ]]; then
                      echo "This action requires sudo privileges."
                      sudo rm "$desktop_file_path"
                  else
                      rm "$desktop_file_path"
                  fi
                  if [[ $? -eq 0 ]]; then
                      echo ".desktop file removed successfully."
                  else
                      echo "Failed to remove .desktop file."
                  fi
              fi
          fi
      
          # Ask if the user wants to remove the AppImage directory
          read -p "Do you want to remove the AppImage directory ($app_dir)? [y/N]: " remove_app_dir
          if [[ "$remove_app_dir" =~ ^[Yy]$ ]]; then
              app_dir_path="$appimage_base_dir/$app_dir"
              if [[ -d "$app_dir_path" ]]; then
                  echo "Removing AppImage directory: $app_dir_path"
                  rm -r "$app_dir_path"
                  if [[ $? -eq 0 ]]; then
                      echo "AppImage directory removed successfully."
                  else
                      echo "Failed to remove AppImage directory."
                  fi
              else
                  echo "AppImage directory does not exist."
              fi
          fi
      
          echo "Uninstallation process completed."
      }
      
      # Call the function to uninstall the AppImage for all users
      AUUnAppImage
      
      

OK, it works, though it’s just a simple example and may not be friendly enough for everyone to use, as I can only make sure it works for myself with some simple test.

Maybe, one day I’ll try to write the AppImage manager based on them. I hope that I’ll be in the mood for it.


How about install the rime(or Chinese Input Method by step 3 and step 4)

Why I use the rime

Now, I can’t type any Chinese on my System. As I had used the rime in my Windows System, I chose to use the rime as my Input Method Engine.

It’s free, open, with no advertisements, and does not collect your data in secret.

Just my own opinion, habit, and preference.

Note: Through the step 3 and the similar operation of step 4 that I mentioned below, it seems like that you can choose the suitable Chinese Input Method Engine for the Ubuntu 24.04 LTS​. So, if you don’t want to install the rime, just do step 3 and step 4(the operations of it are almost similar), then it will work.


Install the rime

Visit https://github.com/rime/home/wiki/RimeWithIBus and https://github.com/rime/home/wiki/RimeWithSchemata.

Rime 是跨平臺的輸入法軟件,Rime 輸入方案可通用於以下發行版:

  • 【中州韻】 ibus-rime → Linux
  • 【小狼毫】 Weasel → Windows
  • 【鼠鬚管】 Squirrel → Mac OS X

So, for my System, I need to install the ibus-rime.

  1. sudo apt-get install ibus-rime

  2. Install the different input schema (optional)

    • sudo apt-get install librime-data-double-pinyin
    • sudo apt-get install librime-data-terra-pinyin librime-data-bopomofo
  3. Settings->System->Region & Language->System->Manage Installed languages->Install/Remove Languages->Chinese(simplified)

  4. Settings->Keyboard->Input Sources->Add Input Source->type Chinese, and choose other​ option->add the Chinese(Rime)

  5. Restart your system, you can use this command sudo shutdown -r now

Then, you can use the rime.

Note: For step 3 and step 4, I have simplified some details like where are they, so, you might need to make it by STFW​, if you meet some problems during the process. But I promise that it will not be a tricky task.


Edit the rime for your personal preference

Rime is just a frame of Input Method, so, it allows you to set many personal configurations.

It’s a little bit complicated, just to do it step by step.

Though the official document has given information for our configuration, it’s still not very friendly for a primary user of it(especially for the user on Linux).

I write this part to record how I edit the configuration for myself, and hope it will be helpful to others who want to use the Rime as their Input Method on Linux.

Just some basic settings.


To start it

Visit https://github.com/rime/home/wiki/RimeWithSchemata.

  • SharedData: /usr/share/rime-data/​ (do not edit it manually)
  • UserData: ~/.config/ibus/rime​ (always edit this)

Note:

  • Do not edit the *.yamldirectly(When the Rime update, all the *.yaml​ will be overwritten, though you can choose not to update it).

    The recommended way to edit the schema is to create and edit *.custom.yamlinstead.

    Use the patch​ to write the new settings or use the new value of the setting to replace the original one.

  • Everytime you do any changes to the *.yaml​, you need to run ibus restart to deploy the Rime.


Change the Candidate words:

  1. vim ~/.config/ibus/rime/default.custom.yaml

  2. Write the content below.

    patch:
      "menu/page_size": 9
    
  3. Then ibus restart​, works.

Note: The valid arrangement of it is [1,9]​, some release versions of the Rime can support 10​ candidate words.


Vertical or horizontal:

  1. vim ~/.config/ibus/rime/ibus_rime.custom.yaml

  2. Write the content below.

    patch:
      "style/horizontal": true
    
  3. Then ibus restart​, works.


Chinese(tradition) and Chinese(simplified):

  1. Type “ctrl+`”
  2. Select “朙月拼音.简化字”, it works.


How to use the grub

To start it

Well, I installed the Ubuntu first and installed the Windows secondly, now, I can’t see the interface of the grub and don’t know how to start the Windows.

In the past, I installed Windows first. After that, if you install the Ubuntu, it will offer you the option to install the Ubuntu for your Windows, as this process is automatically processed by the installer, I don’t need to do anything manually. Except editing the grub file to allow me to select which system to start.

Now, as it may be a tricky task, just prepare yourself for it.


Start it with the grub file itself

Before any edit to the grub, we are supposed to know where are they and what the function of them at least.

  • Configuration file: /etc/default/grub

    If you change this file, run ‘update-grub’ afterwards to update
    /boot/grub/grub.cfg.

    For full documentation of the options in this file, see:
    info -f grub -n ‘Simple configuration’

  • Executable files’ directory: /etc/grub.d

    All executable files in this directory are processed in shell expansion order.

    00_*: Reserved for 00_header.

    10_*: Native boot entries.

    20_*: Third party apps (e.g. memtest86+).

    The number namespace in-between is configurable by system installer and/or
    administrator. For example, you can add an entry to boot another OS as
    01_otheros, 11_otheros, etc
    , depending on the position you want it to occupy in
    the menu
    ; and then adjust the default setting via /etc/default/grub.

  • Automatically generated file: /boot/grub/grub.cfg​(Do not edit it directly)

    It is automatically generated by grub-mkconfig using templates
    from /etc/grub.d and settings from /etc/default/grub

Based on the illustration above, we should turn to know more about the configuration file first.


Know more about the Configuration file of the grub

  1. info -f grub -n 'Simple configuration'

  2. vim /etc/default/grub

  3. Read it but only focus on the information that you may need

    • Quote the value containing spaces or other special characters

    • GRUB_DEFAULT

      • The default menu entry.
      • value: number | the title of a menu entry | the special string ‘saved’
    • GRUB_TIMEOUT

      • Boot the default entry this many seconds after the menu is displayed unless a key is pressed.
      • 0​ : boot immediately without displaying the menu
      • -1​: wait indefinitely
      • number not in {0,-1}​ : seconds the menu is displayed
      • Note: If the GRUB_TIMEOUT_STYLE is set to ‘countdown’ or ‘hidden’, the timeout is instead counted before the menu is displayed
    • GRUB_TIMEOUT_STYLE

      • Influence the behavior of the menu

      • {countdown, hidden}​ : Before displaying the menu, GRUB will wait for the timeout set by ‘GRUB_TIMEOUT’ to expire

        • If <ESC> or <F4> are pressed, or <SHIFT> is held down during that time, it will display the menu and wait for input.
        • If a hotkey associated with a menu entry is pressed, it will boot the associated menu entry immediately.
        • If the timeout expires before either of these happens, it will boot the default entry.
        • In the ‘countdown’ case, it will show a one-line indication of the remaining time.
  4. Analyse-it

    • So, if you find that your GRUB_TIMEOUT=0​, you can’t see the menu of grub, because it will boot the default entry immediately without displaying the menu.
    • If you can find that your GRUB_TIMEOUT_STYLE=hidden​, without typing the {<ESC>, <F4>, <SHIFT>}​, you can’t see the menu.
    • Besides, when the GRUB_TIMEOUT_STYLE={countdown, hidden}​, if your value of timeout is low, as GRUB will wait for the timeout before displaying the menu, you still can’t see the menu while typing the key {<ESC>, <F4>, <SHIFT>}​.

Make the changes based on your requirements.

Don’t forget to run sudo update-grub​, after any changes to the /etc/default/grub​.


Add the menu entry of my Windows to it

After the operations that we have done, we can see the grub menu now, but, we still can’t find the menu entry of my Windows system.

Remeber the /etc/grub.d​ ?

For example, you can add an entry to boot another OS as
01_otheros, 11_otheros, etc
, depending on the position you want it to occupy in
the menu
; and then adjust the default setting via /etc/default/grub.

We need to add an entry to boot another OS, but how?

By STFW​, I have tried the methods listed below.


os-prober (X) Not work for me

Visit https://cn.linux-console.net/?p=10556.

  1. sudo os-prober

    /dev/nvme0n1p5:Windows 10:Windows:chain

  2. sudo update-grub

    Sourcing file `/etc/default/grub’
    Generating grub configuration file …
    Found linux image: /boot/vmlinuz-6.8.0-45-generic
    Found initrd image: /boot/initrd.img-6.8.0-45-generic
    Found linux image: /boot/vmlinuz-6.8.0-31-generic
    Found initrd image: /boot/initrd.img-6.8.0-31-generic
    Found memtest86+x64 image: /boot/memtest86+x64.bin
    Warning: os-prober will not be executed to detect other bootable partitions.
    Systems on them will not be added to the GRUB boot configuration.
    Check GRUB_DISABLE_OS_PROBER documentation entry.
    Adding boot menu entry for UEFI Firmware Settings …
    done

  3. OK, check the /etc/default/grub

    If your computer has multiple operating systems installed, then you
    probably want to run os-prober. However, if your computer is a host
    for guest OSes installed via LVM or raw disk devices, running
    os-prober can cause damage to those guest OSes as it mounts
    filesystems to look for things.
    #GRUB\_DISABLE\_OS\_PROBER\=false

  4. Justice do I have the guest OSes? No. GRUB_DISABLE_OS_PROBER=true​ then sudo update-grub

    1. Host Machine: This is the physical computer that runs the hypervisor. It provides the underlying hardware resources for the virtual machines.
    2. Hypervisor: Also known as a virtual machine monitor (VMM), it is software that runs on the host machine’s hardware and allows multiple operating systems to run on the host at the same time. The hypervisor presents hardware resources to the guest operating systems.
    3. Guest OS: This is the operating system installed within a virtual machine. It believes it is running directly on the hardware, but in reality, it is being managed by the hypervisor.
    4. Virtual Machine (VM) : A software implementation of a physical machine that runs an operating system. Each VM acts like a separate computer and can run its own operating system and applications.
  5. Not work, info -f grub -n 'Simple configuration'

    ‘GRUB_DISABLE_OS_PROBER’
    The ‘grub-mkconfig’ has a feature to use the external ‘os-prober’
    program to discover other operating systems installed on the same
    machine and generate appropriate menu entries for them. It is
    disabled by default since automatic and silent execution of
    ‘os-prober’
    , and creating boot entries based on that data, is a
    potential attack vector. Set this option to ‘false’ to enable this
    feature in the ‘grub-mkconfig’ command.

  6. OK, set GRUB_DISABLE_OS_PROBER=false​, still doesn’t work at all, with the same error message above. Turn to the next method.


Boot-Repair tool (?) May work for me

Hmm, I don’t wanna try this, for that I don’t want to install too many unusual used software for my system, and I don’t want to do the repetitive install and uninstall jobs, either.

But if you are interested in it, visit the https://help.ubuntu.com/community/Boot-Repair for detailed information.


info grub​ for help (X) Not work for me

Now, it’s time for us to read the document of the grub to find the possible solution to the tricky task.

  1. info grub​ and scan it for the information that we need

  2. Turn to “Booting”

    • How to boot different operating systems

      • Loading an operating system directly

      • Using kexec from userspace

      • Chainloading another bootloader

        • GRUB cannot boot DOS or Windows directly, so you must chain-load them.

        • For a Windows system on the first partition of the first hard disk:

          menuentry “Windows” {
          insmod chain
          insmod ntfs
          set root=(hd0,1)
          chainloader +1
          }

  3. Turn to “Filesystem syntax and semantics”

    • device syntax: (DEVICE[,PARTMAP-NAME1PART-NUM1[,PARTMAP-NAME2PART-NUM2[,...]]])

        • ‘[]’ means the parameter is optional.
        • BIOS and EFI disks use either ‘fd’ or ‘hd’ followed by a digit, like ‘fd0’, or ‘cd’.
        • AHCI, PATA (ata), crypto, USB use the name of driver followed by a number.
        • Memdisk and host are limited to one disk so it’s referred just by driver name.
        • RAID (md), ofdisk (ieee1275 and nand), LVM (lvm), LDM, virtio (vdsk), and arcdisk (arc) use intrinsic name of disk prefixed by driver name.
        • Hostdisk: [fhc]d[0-9]* or hostdisk/
        • crypto and RAID (md): uuid/
        • LVM: lvmid//
      • The syntax ‘(hd0)’ represents using the entire disk (or the MBR when installing GRUB), while the syntax ‘(hd0,1)’ represents using the first partition of the disk (or the boot sector of the partition when installing GRUB).

  4. To start the grub command line to define the position of my Windows System

    1. Restart your system
    2. On the grub menu, type c​ to get into the grub command line
    3. ls​ to see all the disks and their partitions
    4. ls​ one by one to define which one is my Windows System
    5. I find it on my (hd0,msdos5)
  5. Another way is to use sudo fdisk -l​ and observe the information to define it (It needs you to know clearly about step 3)

  6. Know the UUID of the Windows System

    sudo blkid /dev/nvme0n1p5

    /dev/nvme0n1p5: BLOCK_SIZE=“512” UUID=“7EF6B725F6B6DD19” TYPE=“ntfs” PARTUUID=“10d919dd-05”

    UUID: 7EF6B725F6B6DD19

    Type: ntfs

  7. sudo vim /etc/grub.d/11_otheros

    Write the content below.

    #!/bin/sh
    menuentry "Windows 10" {
            insmod ntfs
    		insmod chain
            search --fs-uuid --no-floppy --set=root 7EF6B725F6B6DD19
            chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi
    }
    
  8. sudo chmod +x 11_otheros

  9. sudo update-grub

    Didn’t work! Errors occur.

OK, I don’t know how to handle it anymore.


Install the Windows first, then install the Ubuntu (y) work for me

Yes, I just chose the old workable way to solve it.

But maybe I can learn how to boot my Windows by learning the /etc/grub.d​.

  1. more 30_os-prober​ OK, I don’t know what it’s talking about.

  2. sudo more /boot/grub/grub.cfg​ As I have installed the system again, it’s no wonder why there are some differences from the past information.

    ### BEGIN /etc/grub.d/30_os-prober ###
    menuentry 'Windows 8 (on /dev/nvme0n1p1)' --class windows --class os $menuentry_id
    _option 'osprober-chain-12B062A8B06291D1' {
    	insmod part_msdos
    	insmod ntfs
    	search --no-floppy --fs-uuid --set=root 12B062A8B06291D1
    	parttool ${root} hidden-
    	drivemap -s (hd0) ${root}
    	chainloader +1
    }
    ### END /etc/grub.d/30_os-prober ###
    
  3. Then explanation from the AI

    1. menuentry 'Windows 8 (on /dev/nvme0n1p1)' --class windows --class os $menuentry_id

      • menuentry​: Defines a boot menu entry.
      • 'Windows 8 (on /dev/nvme0n1p1)'​: This is the name displayed in the boot menu, indicating that this option is for booting Windows 8 from the partition located at /dev/nvme0n1p1​.
      • --class windows​: A classification option that tags the menu item as a Windows system.
      • --class os​: Another classification option, indicating that this is an operating system.
      • $menuentry_id​: This is a variable typically used to provide a unique identifier for the menu entry.
    2. _option 'osprober-chain-12B062A8B06291D1' {

      • _option​: Defines a configuration option block, often used to store configurations related to the boot entry.
      • 'osprober-chain-12B062A8B06291D1'​: This is the name of the options block, usually related to osprober​ (a tool for automatically detecting other operating systems).
    3. insmod part_msdos

      • insmod​: Stands for “insert module,” used to load modules for GRUB2.
      • part_msdos​: A module that is used to recognize MS-DOS partition tables.
    4. insmod ntfs

      • ntfs​: Another module that provides support for the NTFS file system, which is commonly used by Windows operating systems.
    5. search --no-floppy --fs-uuid --set=root 12B062A8B06291D1

      • search​: Used to search for bootable devices.
      • --no-floppy​: Tells GRUB not to search on floppy drives.
      • --fs-uuid​: Specifies to search for a device based on the file system UUID.
      • --set=root​: Sets the found device as the root device, which is used for subsequent booting processes.
      • 12B062A8B06291D1​: The file system UUID.
    6. parttool ${root} hidden-

      • parttool​: A tool used to manipulate partitions.
      • ${root}​: The root device variable set by the previous search​ command.
      • hidden-​: The exact purpose of this parameter is unclear; it might be used to hide a partition.
    7. drivemap -s (hd0) ${root}

      • drivemap​: Used to map drives.
      • -s (hd0)​: Specifies the source drive to map, (hd0)​ typically represents the first SCSI/IDE hard drive.
      • ${root}​: Maps to the previously found root device.
    8. chainloader +1

      • chainloader​: Used to load another boot loader.
      • +1​: Indicates that GRUB2 should load the boot loader from the next sector after the current location, which is usually the Windows boot sector.
  4. Analyse-it

    • I need to boot a Windows System, so I need to use --class windows​ to tag this menu entry as a Windows System.

    • This menu entry will boot an OS, so --class os​ is needed to tag it as an OS.

    • I need to provide a unique identifier for the menu entry, so I use the $menuentry_id​.

    • My hard disk use the format of MBR, so it’s needed to use insmod part_msdos​.

    • My Windows System use the NTFS file system, so I use the insmod ntfs​.

    • I need to search the bootable devices, so I use the search

      1. --no-floppy​: not to search on floppy drives
      2. --fs-uuid​: use file system UUID to search the bootable devices, we can use sudo blkid /where/os/is​ to get it.
      3. --set=root​: Sets the found device as the root device
    • After searching the bootable devices…

      • parttool ${root} hidden-

        This line is intended to interact with the partition table of the device identified by ${root}​. Here’s a breakdown:

        • parttool​: This is a command in GRUB2 used for partition manipulation. It’s typically used to perform operations on partitions that are not directly accessible due to BIOS or EFI constraints, or to handle certain types of partitions that GRUB2’s standard commands can’t interact with.
        • ${root} ​: This is a variable that represents the root device as determined by a previous search​ command. It’s used to refer to the device or partition where the boot process should proceed.
        • hidden- ​: This is indeed a bit ambiguous without more context. In GRUB2, the parttool​ command is used to mark a partition as hidden or to change its bootable flag. However, the hidden-​ option does not correspond to any standard GRUB2 parttool​ operation. It’s possible that this is a typo or a custom modification. The correct operation might be hidden​ followed by a partition number to hide a specific partition, or bootable​ followed by a partition number to set its bootable flag.
      • drivemap -s (hd0) ${root}

        This line is used to map a drive for the purpose of the boot process:

        • drivemap​: This command in GRUB2 is used to map a BIOS drive to a GRUB device. This mapping is necessary because GRUB uses its own naming scheme for drives that may not correspond to the BIOS’s drive numbering.
        • -s (hd0) ​: The -s​ option specifies the source drive for the mapping. (hd0)​ is a GRUB device reference that typically denotes the first hard disk drive detected by GRUB. The notation in parentheses is a legacy way of referring to drives and might be used for compatibility reasons.
        • ${root} ​: As mentioned before, this variable holds the device specification set by a previous search​ command. In the context of drivemap​, ${root}​ is used to define the target of the mapping, meaning that (hd0)​ in the BIOS is mapped to whatever device ${root}​ refers to within GRUB.
      • OK, info grub​ for more help.

        • parttool: Make various modifications to partition table entries.

          • If GRUB “hides” a DOS (or Windows) partition (*note parttool:😃, DOS
            (or Windows) will ignore the partition. If GRUB “unhides” a DOS (or
            Windows) partition, DOS (or Windows) will detect the partition.

            Each COMMAND is either a boolean option, in which case it must be
            followed with ‘+’ or ‘-’ (with no intervening space) to enable or
            disable that option, or else it takes a value in the form
            ‘COMMAND=VALUE’.

            ‘hidden’ (boolean)
            When enabled, this hides the selected partition by setting the
            “hidden” bit in its partition type code; when disabled,
            unhides the selected partition by clearing this bit. This is
            useful only when booting DOS or Windows and multiple primary
            FAT partitions exist in one disk.

          • So, parttool ${root} hidden-​ means disable the hidden option, making DOS (or Windows) will detect the partition ${root}​, the root device as determined by a previous search​ command.
        • drivemap:

          • Command: drivemap -l|-r|[-s] from_drive to_drive
            Without options, map the drive FROM_DRIVE to the drive TO_DRIVE.
            This is necessary when you chain-load some operating systems, such
            as DOS, if such an OS resides at a non-first drive.
            For
            convenience, any partition suffix on the drive is ignored, so you
            can safely use ${root} as a drive specification.

             With the ‘-s’ option, perform the reverse mapping as well, swapping  
             the two drives.
            
             With the ‘-l’ option, list the current mappings.
            
             With the ‘-r’ option, reset all mappings to the default values.
            
        • drivemap -s (hd0) ${root}​, means swap the (hd0)​ and ${root}​, now we can make sure that (hd0)​ in the BIOS is mapped to whatever device ${root}​ refers to within GRUB.

    • chainloader +1​: load the boot loader from the next sector after the current location, which is usually the Windows boot sector.

  5. Let’s make a conclusion

    1. Write the name for the menu entry and classify it

      menuentry ‘Windows 8 (on /dev/nvme0n1p1)’ --class windows --class os $menuentry_id
      _option ‘osprober-chain-12B062A8B06291D1’

    2. insmod​ the needed modules for GRUB

      insmod part_msdos # My hard disk uses the MBR(Master Boot Record) partition
      insmod ntfs # The filesystem of my Windows System

    3. search​ the correct partition based on the UUID, and set the searched device as the root device, ignoring the floppy devices.

      search --no-floppy --fs-uuid --set=root 12B062A8B06291D1 # The UUID of my Windows System

    4. parttool​ to make the DOS (or Windows) detect the partition ${root}

      parttool ${root} hidden-

    5. drivemap​ to make sure that (hd0)​ in the BIOS is mapped to whatever device ${root}​ refers to within GRUB.

      drivemap -s (hd0) ${root}

    6. chainloader +1​, loading the boot loader from the next sector after the current location, which is usually the Windows boot sector.

      chainloader +1

However, I still can’t write the 21_Windows​ file in the /etc/grub.d​, and for that, the grammar is not equal to the things that I analyzed above.

Maybe I will try it in the future, but not now.


Why the time of my Windows and Linux are different from each other, and the interval is always 8 hours?

You can visit https://wiki.archlinux.org/title/System_time or https://wiki.archlinuxcn.org/wiki/%E7%B3%BB%E7%BB%9F%E6%97%B6%E9%97%B4#Windows_%E7%B3%BB%E7%BB%9F%E4%BD%BF%E7%94%A8_UTC for the answer.

In an operating system, the time (clock) is determined by three parts:

  • time value, whether it is local time or UTC or something else,
  • time zone
  • Daylight Saving Time (DST) if applicable.

Two clocks are present on systems: a hardware clock and a system clock.

Time standard

  • localtime

    It is dependent on the current time zone

    Windows use it.

  • Coordinated Universal Time(UTC)

    It is the global time standard and is independent of time zone values

    macOs use it.

  • Other UNIX and UNIX-like systems vary.

  • An OS that uses the UTC standard will generally consider the hardware clock as UTC and make an adjustment to it to set the OS time at boot according to the time zone.


What causes the difference?

  1. Run timedatectl​ on your terminal

    Local time: Thu 2024-10-03 11:15:19 CST
    Universal time: Thu 2024-10-03 03:15:19 UTC
    RTC time: Thu 2024-10-03 03:15:19
    Time zone: Asia/Shanghai (CST, +0800)
    System clock synchronized: yes
    NTP service: active
    RTC in local TZ: no

  2. Then you may discover that the interval between Local time and Univarsal time is 8 hours, but Windows uses the localtime, why Linux can show time correctly while the windows will show the time 8 hours late?

  3. If multiple operating systems are installed on a machine, they will all derive the current time from the same hardware clock.

    Remember? An OS that uses the UTC standard will generally consider the hardware clock as UTC and make an adjustment to it to set the OS time at boot according to the time zone.

    So, your Linux will consider the hardware clock as UTC and then make an adjustment to it to set the OS time at boot according to the time zone(like plus 8 hours). While your windows derive the current time from the same hardware clock, without the adjustment of the OS time according to the time zone, which causes the difference.

How to handle it?

  1. Of course, we have to make a choice, let the Linux use the localtime or the Windows use the UTC.

    1. Linux uses the localtime

      1. timedatectl set-local-rtc 1

      2. Then, run timedatectl​, warning will occur

        Warning: The system is configured to read the RTC time in the local time zone.
        This mode cannot be fully supported. It will create various problems
        with time zone changes and daylight saving time adjustments. The RTC
        time is never updated, it relies on external facilities to maintain it.
        If at all possible, use RTC in UTC by calling
        ‘timedatectl set-local-rtc 0’.

      3. If you don’t want to do so, run timedatectl set-local-rtc 0

    2. Windows uses the UTC

      1. Method1: Open regedit​ and add a DWORD​ value with hexadecimal value 1​ to the registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal

      2. Method2: From an Administrator Command Prompt running

        C:\>reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal /d 1 /t REG_DWORD /f

      3. Method3: create a *.reg​ file (on the desktop) with the following content and double-click it to import it into the registry

        Windows Registry Editor Version 5.00
        
        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
        "RealTimeIsUniversal"=dword:00000001
        
      4. Should Windows ask to update the clock due to DST changes, let it. It will leave the clock in UTC as expected, only correcting the displayed time.

        The #Hardware clock and #System clock time may need to be updated after setting this value.

      5. If you are having issues with the offset of the time, try reinstalling tzdata and then setting your time zone again:

        timedatectl set-timezone America/Los_Angeles

At last, I choose to let Windows use the UTC and use the Method2 that I mentioned above, and it works.


How to use the dictionary on Ubuntu

You know, using English to write is not easy, so I have to query the dictionary online again and again.

But, if I can’t connect to the Internet, or I just want to do this whole on my own PC, what should I do?

I choose to use the GoldenDict, for some known reasons, we can’t use some resources without the usage of scientific Internet. So, let’s go straight to the topic.


A simple method to open your software without the use of a mouse

  1. Press <Super(win)>
  2. Type the name of the software(But it should be integrated to your desktop, in short, it should have the relative .desktop​ file)
  3. Use the left <left>​ and <right>​ to choose the target software
  4. Type <Enter>​, it will works.


Just to do it

At first, I managed to write a blog to introduce how to use the GoldenDict, but I’m glad to see that someone has done it very well.

So, I recommend you to visit the https://www.cnblogs.com/keatonlao/p/12702571.html.

Here, I will record how I follow it, step by step.

  1. sudo apt install goldendict -y​, install the goldendict.

  2. Download the dictionary from the link https://pan.baidu.com/s/1qlV-JB8VU1NkWz76na8nBQ?pwd=5mgk (I’m not happy that I can’t connect with the http://download.huzheng.org/)

  3. mv​ them to the location that you want them to be.

  4. Import the dictionaries by the step Edit->Dictionaries->Sources->Files->Add...(the path to the directory of the dictionaries)->Recursive->Rescan now->Apply->OK

  5. Group the dictionaries by the step Edit->Dictionaries->Groups->Add group->set the shortcut->drag the dictionary to the relative group(or select the dictionary and press the > in the middle to add it to the group)->Apply->OK

  6. Select the words that you want to query, and press the hotkey <ctrl>+<c>+<c>​ to make it. (You can edit the hotkeys by the step Edit->Preferences->Hotkeys->edit the "Use the following hotkey to translate a word from clipboard"​)

  7. We can use the wildcard to make the Fuzzy matching

  8. As there is a lack of the query on our local dictionary, we can add the online dictionary for it

    Follow this step Edit->Dictionaries->Sources->Websites->Add the link that you want to->Enable the specific link->Group->Add the online dictionary to the group

    # 欧路-英汉(En-中)
    https://dict.eudic.net/dicts/en/%GDWORD%
    
    # 有道词典 / 词典-英汉汉英(En-中中-En)
    https://dict.youdao.com/result?word=%GDWORD%&lang=en
    
    # Collins Online Dictionary-英英(En-En)
    https://www.collinsdictionary.com/dictionary/english/%GDWORD%
    
    # Longman Dictionary-英英(En-En)
    https://www.ldoceonline.com/dictionary/%GDWORD%
    
    # Cambridge Dictionary-英英(En-En)
    https://dictionary.cambridge.org/dictionary/english/%GDWORD%
    
    # Cambridge Dictionary-英汉(En-中)
    https://dictionary.cambridge.org/dictionary/english-chinese-simplified/%GDWORD%
    
    # Vocabulary-英英(En-En)
    https://www.vocabulary.com/dictionary/%GDWORD%
    
    # merriam-webster-英英(En-En)
    https://www.merriam-webster.com/dictionary/%GDWORD%
    
    # merriam-webster-thesaurus-英英(En-En)
    https://www.merriam-webster.com/thesaurus/%GDWORD%
    
    # 汉典-汉语(Chinese)
    https://www.zdic.net/hans/%GDWORD%
    
  9. We can also add the search engine to it with the same step

    # Bing 中国:
    http://cn.bing.com/search?q=%GDWORD%
    
    # Bing 美国:
    http://www.bing.com/search?q=%GDWORD%
    
    # 搜狗
    http://www.sogou.com/web?query=%GDWORD%
    
    # 百度搜索
    http://www.baidu.com/s?wd=%GDWORD%
    
    # Google
    https://google.com/search?q=%GDWORD%
    

It’s just the basic configuration of the goldendic, which is enough for me to use.


How to play the music on Ubuntu

As I haven’t learned the usage of the docker, maybe the best choice for me is the cmus.

If possible, maybe when I can use the docker, I’ll update this part and introduce more music players for everyone.

But now, let’s focus on the cmus.

You can also visit the relative blogs at the References part of this article.

Recommand to visit https://man.archlinux.org/man/cmus-tutorial.7 and https://www.cnblogs.com/brt2/p/13258775.html.


Install it and know about it

  1. sudo apt install cmus​, then you can install it.

  2. cmus --help​ but does not help me very much.

  3. man cmus​, read the documents, so you will know how to use it

    • Considering the Cognitive processes of people, I’ll not introduce it directly.

Note: I’ll only introduce the part that I am interested in, if you want more detalis, explore it by yourself.


Start to use it and know how to use it

  1. Type and run cmus​, then you can see it.

  2. You can see that we have no music on the library view, so we press <5>​ to switch to the Browser view where we can add the music from the filesystem to the library.

  3. You can use <j>​ and <k>​ or <up>​ and <down>​ to highlight a file or folder.

    • You can press <Enter>​ to navigate into the highlighted folder and press <Backspace>​ to back to the parent directory.
    • You can press <g>​ to go the top of the
  4. You can press <a>​ to copy tracks to the library.

    When you press a cmus will move you to the next line down (so that it is easy to add a bunch of files/folders in a row) and start adding the file/folder you pressed a on to your library. This can take a while if you added a folder with a lot in it.

    Note: cmus does not move, duplicate, or change your files. It just remembers where they are and caches the metadata (duration, artist, etc.)

  5. Then you want to play it, so you press <1>​(Library view) or <2>​(sorted Library view).

    • Library view (1)
      Displays all tracks in the library. Tracks are sorted and displayed in a tree grouped by artist/album. Artist sorting is done alphabetically. Albums are sorted by year.

    • Sorted library view (2)

      Displays the same content as view 1, but as a simple list automatically sorted by user criteria.

  6. Also, You can use <j>​ and <k>​ or <up>​ and <down>​ to highlight the single music file, just press <Enter>​, and then the highlighted music will be played.

  7. About play

    • You can press <c>​ to pause/unpause.
    • Press <left>​ | <j>​ or <right>​ | <k>​ to seek by 10 seconds.
    • Press <​ or >​ to seek by 1 minute
    • Press <z>​ to play the previous track, and <b>​ to play the next track
    • Press <v>​ to stop playback
  8. Then you may want to play the music {Continue(default), Repeat, Shuffle, Follow}

    1. Press <r>​ -> Repeat
    2. Press <s>​ -> Shuffle
    3. Press <f>​ -> Follow
    4. Press <shift>+<c>​ -> Continue
  9. When you are on View 2, you may want to play music {all from library, artist from library, album from library}, you can press <m>​ to cycle through the different options for this setting.

  10. Now you are listening to a song, you want to see the queue of the songs to know what will be played next, so you press <4>​ to switch to the Play Queue view. But before that, you should go to the song that you want to hear next, and press <e>​ to add it to the queue, or you can see nothing in the Play Queue view. (Note: The queue will not be affected by the Shuffle)

  11. You may want to add songs to the playlists, so you can play the playlists instead of playing all the songs in the library. So you press <3>​ to switch to the Playlist view.

  12. But how to add the songs to the playlist? Press <2>​ and press <y>​ to add the highlighted song to the marked playlist(highlighted). Press <3>​, and you can see the added songs in the highlighted playlist.

    If you want to play the music in the playlist without interrupting the currently playing song, you can press <shift>+<m>​.

  13. If you want to remove the songs from the library or the songs from the playlist or the playlist (because you can’t play this music or you just don’t like it), you can press the <D>​ or <delete>​ to make it.

    Specially, if you want to delete the songs in the playlist, you should press <Tab>​ to switch to the right column, after the operations, you can press <Tab>​ again to go back to the left column.

  14. If you want to change the order of the tracks

    • Pressing p​ moves marked tracks to the position immediately after the selected track.
    • P​ moves them to the position immediately before the selected track.
  15. Sometimes, we just want to search for the specific song to play, so, you press <2>​, then press /​, and type a word or two from the track you’re looking for.

    Press <Enter>​ to get the keyboard out of the search command, or <n>​ to find the next match.

  16. Now we know about Views 1-5 and their basic usage, but how about 6 and 7?

       Filters view (6)  
              Lists user-defined filters.
    
       Settings view (7)  
              Lists keybindings, unbound commands and options. Remove bindings  
              with D or del, change bindings and variables with enter, and  
              toggle variables with space.
    
  17. Now, you feel tired and want to sleep, so you press :q​ to quit the cmus.

  18. You can do all the work above by the command line, man cmus​ for more details.


Write a .desktop​ for cmus

Though you can just simply type the cmus​ on your terminal to start it, I just to prefer regarding it as the application that I used to use, which makes me write a .desktop​ for it.

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=cmus
Icon=/home/lbc/Applications/cmus/cmus.png
Terminal=true
Exec="cmus"
Categories=Music;


How to code on Ubuntu

When you generally apply the Ubuntu as a part of your daily life, you may turn to code on it.

As I have made the essential environment on Windows System, now, it’s time for me to do it on Linux!

Note:

  1. I’ll use the Visual Studio Code, if it does not need me to use another editor.


C/C++

You can visit the https://code.visualstudio.com/docs/cpp/config-linux.

  1. Run sudo apt-get update​, and update the Ubuntu package lists.

  2. Run sudo apt-get install build-essential gdb​, install the GNU compiler tools and the GDB debugger

  3. Type gcc -v​, you can see it has been installed.

  4. Run code​ (if you have downloaded it, you can download the .dep​ from the official website or just simply through the App Center)

  5. Install the C/C++ Extension Pack.

  6. Input the content below:

    #include<iostream>
    
    int main()
    {
        std::cout<<"hello world!"<<std::endl;
        return 0;
    }
    
  7. Choose the “C/C++: g++ build and debug active file” or “C/C++: g+±13 build and debug active file”.

  8. Run it, and it will work.


Python

It’s not the first time for me to create the environment for Python, but only on Windows.

Before I do that on Linux, I turn to solve the questions that have confused me for a period.

Why do we need the virtual environment for Python?

What are the differences between miniconda, anaconda, and virtualenv?


Why do we need the virtual environment for Python?

Borrow the explanation from virtualenv.

The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1​ of LibFoo​, but another application requires version2​. How can you use both these libraries? If you install everything into your host python (e.g. python3.8​) it’s easy to end up in a situation where two packages have conflicting requirements.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application. Also, what if you can’t install packages into the global site-packages​ directory, due to not having permissions to change the host python environment?

So, there are four reasons for us to use the virtual environment:

  1. Dependency Isolation: Prevents conflicts by allowing each project to have its own set of libraries. It allows for package installation without altering the global Python environment.
  2. Version Management: Ensures that applications work consistently by locking down library versions.
  3. Permissions: Enables package management without needing system-wide installation rights.
  4. Reproducibility and Portability: Makes it easy to share and replicate the development environment across different systems.


A simple explanation of the differences between miniconda, anaconda, and virtualenv

  • virtualenv

    • virtualenv​ is a tool to create isolated Python environments.

      It creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally installed libraries either).

    • It is more lightweight compared to Anaconda and is suitable for general Python development.
  • Anaconda

    • Register to get everything you need to get started on your workstation including Cloud Notebooks, Navigator, AI Assistant, Learning and more.

      • Easily search and install thousands of data science, machine learning, and AI packages
      • Manage packages and environments from a desktop application or work from the command line
      • Deploy across hardware and software platforms
      • Distribution installation on Windows, MacOS, or Linux
  • Miniconda

    • Miniconda is a free minimal installer for conda. It is a small bootstrap version of Anaconda that includes only conda, Python, the packages they both depend on, and a small number of other useful packages (like pip, zlib, and a few others).

  • So, you can simply conduct it like this

    • virtualenv provides the basic functions of the virtual environment, and it is very light but without Python.
    • Anaconda not only provides the functions of the virtual environment, but also the easy management of packages and environment, default abundant packages for data science, machine learning, AI, and other programs.
    • Miniconda is a small bootstrap version of Anaconda, lighter than Anaconda, allowing you to install all the needed packages based on your own needs.

Based on my own needs, I’ll choose the Miniconda.


How to install the Miniconda on Linux

Visit the https://docs.anaconda.com/miniconda/.

  1. I choose the Miniconda3 Linux 64-bit​ to install it. (I am not familiar with the other option)

  2. Open the terminal, chmod +x Miniconda3-latest-Linux-x86_64.sh​ (You know where the downloaded files are)

  3. ./Miniconda3-latest-Linux-x86_64.sh

  4. Follow the guide of the .sh

    1. You can change the install location of the miniconda

      • Press ENTER to confirm the location
      • Press CTRL-C to abort the installation
      • Or specify a different location below
    2. You can choose not to automatically initialize conda or yes

      Do you wish to update your shell profile to automatically initialize conda?
      This will activate conda on startup and change the command prompt when activated.
      If you’d prefer that conda’s base environment not be activated on startup,
      run the following command when conda is activated:

      conda config --set auto_activate_base false

      You can undo this by running conda init --reverse $SHELL​? [yes|no]
      [no] >>>

  5. Finish the installation of the Miniconda.

I choose all the default options.

Also, you can install it only by the usage of the command line.

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh


To start using it in the vscode

Visit the https://code.visualstudio.com/docs/python/python-quick-start.

  1. Open the vscode, you can do it just by running code​ on your terminal

  2. Install the python extension

  3. Use Ctrl+shift+p​, type the Python: Create Environment​, and select the conda environment (you can also just click the button at the lower right corner, like 3.12.3 64-bit​ to switch your environment)

  4. Choose a folder as your workspace

  5. Create a file named hello.py​, and input the content below

    input("hello world!")
    
  6. Run it, and it works.


How to install packages for the virtual environment and how to manage them

  1. Type conda init​ in the terminal of your vscode(if it does not works, relaunch your terminal)

  2. Close and re-open your current shell (I just added a new terminal on my vscode)

  3. Now, I wanna create four virtual environments, the first one is named “MathMode” that used for the race of Mathematical Modeling,the second one is named “DigitalImage” that used for the digital image process, the third one is named “DataDig” that used for data dig, and the last one is named “AIMode” that used for constructing the mode of AI.

    How? Visit the https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html for more details.

  4. Create the conda environment

    conda create --no-default-packages -n MathMode python=3.10 numpy pandas scipy matplotlib scikit-learn
    conda create --no-default-packages -n DigitalImage python=3.10 numpy scipy Pillow scikit-image matplotlib
    conda create --no-default-packages -n DataDig python=3.10 numpy pandas scipy matplotlib scikit-learn scrapy matplotlib
    conda create --no-default-packages -n AIMode python=3.10 numpy pandas scipy matplotlib scikit-learn sympy
    

    If you want to install the PyTorch or opencv for your conda environment, you need to make it a little differently.

    • PyTorch

      • Visit the https://pytorch.org/get-started/locally/

      • What’s the Compute Platform?

        • You may see CUDA 11.8, CUDA 12.1, CUDA12.4, ROCm6.1, and CPU, so, what’s the meaning of them?

          • The number means the version, so there is no need to explain it.
          • CUDA: CUDA is a general parallel computing architecture and programming model developed by NVIDIA for its graphics cards (GPUs).
          • ROCm: ROCm is an open-source software platform optimized to extract HPC and AI workload performance from AMD Instinct accelerators and AMD Radeon GPUs while maintaining compatibility with industry software frameworks.
          • CPU: No need to explain it.
        • My computer uses NVIDIA, so, now I need to check the version of my CUDA

          1. sudo apt install nvidia-cuda-toolkit
          2. nvidia-smi
          3. Oh, the version is 12.2, so, I choose to install the CUDA 12.1.
        • conda install --name MathMode pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

        • conda install --name AIMode pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

        • Create the helloPyTorch.py​ and input the content below

          import torch
          
          # Check if CUDA is available
          cuda_available = torch.cuda.is_available()
          
          # Get the version of CUDA used by PyTorch
          cuda_version = torch.version.cuda
          
          # Print the PyTorch version
          print("PyTorch version:", torch.__version__)
          
          # Print the CUDA version used by PyTorch
          if cuda_available:
              print("CUDA version used by PyTorch:", cuda_version)
          else:
              print("CUDA is not available. PyTorch is running on CPU.")
          
          # Get the CUDA version installed on the system
          if cuda_available:
              try:
                  # Running the command to get the CUDA version from the system
                  import subprocess
                  subprocess.run(["nvcc", "--version"], check=True, stdout=subprocess.PIPE)
                  print("CUDA is available and PyTorch is using it.")
              except subprocess.CalledProcessError:
                  print("CUDA is not properly installed or configured on your system.")
          
          # Simple usage of torch
          # Create a tensor
          x_data = [[1, 2], [3, 4]]
          x_tensor = torch.tensor(x_data, dtype=torch.float)
          
          # Print the tensor
          print("Tensor x:", x_tensor)
          
          # Perform a simple operation, e.g., matrix multiplication
          y_tensor = torch.tensor([[2, 0], [0, 2]], dtype=torch.float)
          z_tensor = torch.mm(x_tensor, y_tensor)
          
          # Print the result of the operation
          print("Result of matrix multiplication:")
          print(z_tensor)
          
          # Verify CUDA usage
          if cuda_available:
              # Move tensors to GPU
              x_tensor = x_tensor.cuda()
              y_tensor = y_tensor.cuda()
            
              # Perform the operation on GPU
              z_tensor_gpu = torch.mm(x_tensor, y_tensor)
            
              # Print the result of the GPU operation
              print("Result of matrix multiplication on GPU:")
              print(z_tensor_gpu)
          
        • If you can see the result of the output has been shown below, it works

          PyTorch version: 2.4.1
          CUDA version used by PyTorch: 12.1
          CUDA is available and PyTorch is using it.
          Tensor x: tensor([[1., 2.],
          [3., 4.]])
          Result of matrix multiplication:
          tensor([[2., 4.],
          [6., 8.]])
          Result of matrix multiplication on GPU:
          tensor([[2., 4.],
          [6., 8.]], device=‘cuda:0’)

    • opencv

      • Visit the https://opencv.org/

      • conda install -n DigitalImage -c conda-forge opencv

      • Create the helloOpenCV​ and input the content below

        from skimage import data
        import cv2
        
        # Load the coffee image from skimage's dataset
        coffee_image = data.coffee()
        
        # Convert the image to the format required by OpenCV
        # skimage images are typically loaded as float64 with values in [0, 1],
        # while OpenCV works with uint8 in the range [0, 255].
        coffee_image_opencv = (coffee_image * 255).astype('uint8')
        
        # Display the image using OpenCV
        cv2.imshow('Coffee Image', coffee_image_opencv)
        
        # Wait for a key press and then close all windows
        cv2.waitKey(0)
        cv2.destroyAllWindows()
        
      • If you can see the processed image of the coffee, it works.

  5. Type conda env list​, you can see all of them.

  6. Visit https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html#installing-packages for more details.


References

apt


AppImage


rime


Grub


Time difference between Linux and Windows


Dictionary


Music


Code

C/C++


Python

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值