Bo2SS

Bo2SS

5 Basic System

Course Content#

Directory Structure#

  • Image
  • Image
  • The top-level root is the root directory/, not the root user

  • Additionally, there is a root folder under the root directory/, which is the home directory of the root user

    • Other users cannot enter except for the root user
  • bin, sbin binaries/[system]

  • etc configuration folder【global】

  • opt optional, not very significant, users can choose to place files

  • run currently running files, generally not concerned

  • var dynamic data

    • mail system notification mechanism, not e-mail
    • log logs【important, do not modify】
      • Viewing information generally requires sudo permissions, usually checking the locations of error and warning
      • The login information displayed by last is stored in the wtmp file
  • boot kernel files, boot-related

  • home parent directory of all users' homes

    • Users' homes are under home, with paths ${HOME} or ~
  • lib, lib64 libraries

  • media media [used for early mounting of floppy disks and optical drives, USB drives are not included here, now used less]

  • mnt mount directory

    • Mount other file systems, such as USB drives, CD... disks in WSL
    • Conventional mount points, will not be automatically mounted, can also have other arbitrary mount points
  • proc processes

    • After viewing the corresponding process id with ps, you can find the directory of the corresponding id under the proc directory
    • Most files in the directory are 0KB, as they are not real, just for display
    • There is a fd directory → file descriptor
      • Image
      • You can input abc to stdout【#1】, which will be displayed in the terminal
      • Temporarily ignore what 10 does
  • tmp temporary folder

    • Will be cleared on shutdown, not a buffer
    • [PS] tmpfile command can create temporary files, refer to man tmpfile
  • dev device files

  • usr files installed by users

    • Generally, it is the administrator user, ordinary users cannot install software
    • local shared files [manual...]

Boot Process#

  • 👉 Press the power button
  • 👉 Load BIOS: hardware detection [CPU, disk, memory, etc.], read configuration [system installation location, etc.], until reading MBR
    • BIOS - Basic Input Output System, firmware based on CMOS chip
      • Firmware is based on software and hardware, solidifying some programs [burning] onto a chip
      • Always powered [button battery], will initialize when power is lost
  • 👉 Read the MBR [Master Boot Record] from the first bootable device
    • Stores the boot program Boot Loader
    • Load kernel: detect hardware, load drivers
    • At this point, the kernel takes over the work of BIOS
  • 👉 Execute the boot program [Ubuntu: Grub]
    • Load virtual file system, get the kernel running
  • 👉 Initialize the disk, read the system image file
  • 👉 Start process 1
    • Previously called init, now called cnd
    • At this point, the system has its own functionality
  • 👉 Load the disk, mount data, start various services, connect the terminal
  • 👉 【Finally】 run the X windows system → has a graphical interface

Run Levels#

In Linux, different run levels correspond to different services to start the system

run levelMeaningRemarks
0haltSystem shutdown
1single user modeUsed for maintenance when the system has problems, similar to safe mode
2multi-user, without nfsnfs: network file system
3full multi-user modeComplete multi-user pure text mode【commonly used】
4unusedReserved by the system, not used
5X11Load X windows based on run level 3
6rebootReboot
  • Development of boot methods
    • System V [starts sequentially]
    • Upstart [grouped startup, services without dependencies can start simultaneously]
    • Systemd [all services start together, services with dependencies are slightly delayed, further improving concurrency]
  • The speed of system startup does not represent the quality of system performance, such as large machines that restart once every few years, need to check the hardware carefully
  • Warm boot: skips the hardware detection process of BIOS without necessity, speeding up the startup time

Configuration Files#

File System#

  • /etc/fstab file systems to be mounted at boot
    • Static file system information, indicating the system disks to be mounted
    • For example: if you need to mount another disk for a company machine, you can set it here
  • /etc/mtab currently mounted file systems

User System#

  • /etc/passwd user information
    • Contains not only ordinary users but also many system users
    • User placeholder:uid:gid description directory shell
    • Previously, the password placeholder stored passwords, now stored in👇
  • /etc/shadow user passwords
    • Displayed passwords are encrypted, the cost of decryption may be greater than the value obtained
  • /etc/group group information
  • /etc/gshadow group passwords
    • Basically unused, root manages the entire system, no need to subdivide into groups
  • /etc/sudoers Sudoer list
    • % represents a group
    • Can be added by oneself

Shell#

  • echo ${SHELL} view the user's Shell type
  • /etc/shells list of available Shells

【For zsh】

  • /etc/zsh/zprofile user preferences【global】
  • ⭐ Search in man zsh for —FILES to see all configurable zsh file paths
    • For example: in 4 global configurations, 4 user configurations echo "In ..."
    • When the user logs into zsh, the display order is as follows:
    • Image
    • Order: zshenv→zprofile→zshrc→zlogin, first global (G), then user (L)
    • [PS] User configuration files
      • $ZDOTDIR/.zshenv
      • $ZDOTDIR/.zprofile
      • $ZDOTDIR/.zshrc
      • $ZDOTDIR/.zlogin
      • $ZDOTDIR/.zlogout
      • $ZDOTDIR — defaults to the user's home directory

System Environment#

  • /etc/environment environment variables
    • PATH environment variable: ${PATH}
    • which command will look for the command corresponding file in this【PATH environment variable】 [file must be executable]
    • ⭐ Add path "." to PATH: PATH=${PATH}:.
      • You can directly add:. to the PATH variable to connect
      • You can also use export PATH=${PATH}:.
      • ❗ But both methods modify in memory, and will disappear after reconnecting the shell
    • See the next 2 sections — environment variables
  • /etc/updatedb.conf file retrieval database configuration information
    • updatedb updates the database [after updating, newly created files can be found by locate, the database is not updated in real-time]
  • /etc/issue, /etc/issue.net release information, [displayed during remote login]
  • /etc/os-release more detailed system information

Image

Network#

  • ⭐/etc/hosts host list
    • Also known as static DNS, can write corresponding relationships
    • ❗ Domain name [hostname] → IP address
    • [My understanding] Similar to Windows hosts, for resolving a name, first look for hosts, then use DNS
  • /etc/hostname hostname
    • ① Requires sudo permission to modify → new hostname
    • Restart the host; or use [hostname new hostname] to temporarily modify the hostname in memory, otherwise the hostname in the environment will not change after modification
    • ③ Reconnect to take effect
    • [My understanding] Step ① modifies the actual hostname, step ② hostname is used to temporarily modify the hostname in memory, directly restarting can also refresh memory
  • ⭐/etc/resolv.conf domain name resolution server address
    • DNS dynamic domain name server
    • ❗ Domain name → IP address
  • /etc/network/interfaces network card configuration file, check it yourself

Environment Variables#

  • env all environment variables, usually named in uppercase letters
    • Call by adding $ before the environment variable name
    • PATH path of executable folders
    • OLDPWD last working directory
    • HISTSIZE size of saved history records [input commands]
      • bash defaults to saving 1000 lines
      • zsh currently does not have this variable
      • You can view the command history through history, private browsing can search by itself
  • export
    • export PATH=${PATH}:.
    • Equivalent to PATH=${PATH}:.
    • Compared to directly assigning values to environment variables, export is more standardized
    • This modifies in memory, if you want to solidify this variable and make it effective every time you connect, you can add the above statement in any【configuration file】, see the zsh configuration files in the previous 3 sections — Shell
  • [PS] You can use set to view all locally defined environment variables

Software Management#

  • Source code installation
git clone XXXX  # Download source code
cd XXX
make            # Compile
make install    # Install
  • Software package management system
    • ⭐ Recommended apt: It can be understood as a high-level integrated version of apt-get and apt-cache
    • man apt can see its description: advanced, better interactivity than apt-get, apt-cache
    • Image
    • For example:

In-Class Exercises#

Code Demonstration#

Additional Knowledge Points#

  • Variables declared in the shell are stored in memory, in the process space, closing and reopening the shell will lose the variables
    • Do not over-interpret the concept that everything is a file; files are static and need processes to maintain files to make them dynamic
    • Variables are stored in the process space
  • ps can see the process ID
  • ⭐ Use ssh nicknames to log in to the cloud host, such as ssh Ten, the effect on WSL is as follows👇
    • Image
    • For WSL or MacOS
    • ① Add the cloud host's IP to your local /etc/hosts, corresponding to a nickname Ten, for example: 45.123.111.1 Ten
    • ② Create a user on your local machine with the same name as the user you want to log into on the cloud host, for example: hz [local user], hz [cloud host user]
    • ③ At this point, ssh Ten on your local machine, enter the password to log in
    • ❗ Invalid after reboot [for WSL 2, search for methods for other systems, WSL 1 cannot chattr]
      • Use sudo chattr +i /etc/hosts to make /etc/hosts read-only, it will not be reset after reboot
      • To modify again: sudo chattr -i /etc/hosts
    • [PS] You can also use ssh-copy-id for passwordless login, tldr ssh-copy-id can view help instructions
  • Domain names and IPs can be many-to-many, can do load balancing

Points to Consider#

Tips#

  • [Under bash] /etc/profile user preferences【global】 [the file that runs first when the default shell is bash]

Course Notes#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.