1. Directory structure
Everything starts from the root '/', which is the vertex of all directories
2. Relationship between partition and directory
- One by one correspondence between partition and directory in Windows
- Directories and partitions in Linux are separate.
- Different disks are represented by letters
- Different zones are represented by numbers
- IDE disk:
- Different disk representations
- For example: hda1, hda2
- Different partition representation methods
- For example: hda1, hda2
- Different disk representations
- SAS/SATA/SCSI/SSD disks
- Different disk representations
- sda,sdb.....
- Different partition representation methods
- sda1,sda2....
- Different disk representations
- IDE disk:
- By default, the partition in Linux is inaccessible, prison and black box are inaccessible.
- There is a function that links the directory / etc / to / dev/sda1, which is called mount
2.1, Mount
Find an entrance for the zone and open a door or window for the zone.
2.2 mount point
The directory name of the partition entry, / etc is the mount point of / dev/sda1
2.3 mount command and operation
-
Mount mount
-
Usage: mount device name mount directory
[root@oldboyedu ~]# ls /mnt/ hgfs [root@oldboyedu ~]# cd /dev/cdrom -bash: cd: /dev/cdrom: Not a directory #-bash:cd:/dev/cdrom: not a directory [root@oldboyedu ~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 is write-protected, mounting read-only #mount:/dev/sr0 is write protected and mount is read-only [root@oldboyedu ~]# ll /mnt/ total 694 -rw-rw-r--. 1 root root 14 Sep 10 2019 CentOS_BuildTag drwxr-xr-x. 3 root root 2048 Sep 6 2019 EFI -rw-rw-r--. 1 root root 227 Aug 30 2017 EULA -rw-rw-r--. 1 root root 18009 Dec 10 2015 GPL drwxr-xr-x. 3 root root 2048 Sep 10 2019 images drwxr-xr-x. 2 root root 2048 Sep 10 2019 isolinux drwxr-xr-x. 2 root root 2048 Sep 6 2019 LiveOS drwxrwxr-x. 2 root root 671744 Sep 12 2019 Packages drwxrwxr-x. 2 root root 4096 Sep 12 2019 repodata -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7 -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r--. 1 root root 2883 Sep 12 2019 TRANS.TBL
-
-
Uninstall: umount
-
Usage: you need to go back to the directory above the mount point and enter the umount directory
[root@oldboyedu ~]# ll /mnt/ total 694 -rw-rw-r--. 1 root root 14 Sep 10 2019 CentOS_BuildTag drwxr-xr-x. 3 root root 2048 Sep 6 2019 EFI -rw-rw-r--. 1 root root 227 Aug 30 2017 EULA -rw-rw-r--. 1 root root 18009 Dec 10 2015 GPL drwxr-xr-x. 3 root root 2048 Sep 10 2019 images drwxr-xr-x. 2 root root 2048 Sep 10 2019 isolinux drwxr-xr-x. 2 root root 2048 Sep 6 2019 LiveOS drwxrwxr-x. 2 root root 671744 Sep 12 2019 Packages drwxrwxr-x. 2 root root 4096 Sep 12 2019 repodata -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7 -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r--. 1 root root 2883 Sep 12 2019 TRANS.TBL [root@oldboyedu ~]# cd /mnt/ [root@oldboyedu /mnt]# umount /mut umount: /mut: mountpoint not found [root@oldboyedu /mnt]# umount /mnt umount: /mnt: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) #umount:/mnt:target is busy. (in some cases, the device is found by lsof (8) or fuser (1) [root@oldboyedu /mnt]# cd .. [root@oldboyedu /]# umount /mnt [root@oldboyedu /]# ll /mnt/ total 0 drwxr-xr-x. 2 root root 6 Apr 4 18:22 hgfs
-
-
View mount
[root@oldboyedu ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 12M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda3 19G 2.0G 18G 11% / /dev/sda1 253M 161M 93M 64% /boot tmpfs 378M 0 378M 0% /run/user/0 # Total size of device name use size remaining use% mount point
2.4 standardization of FHS catalogue
-
The root directory "/" is mounted on the first disk. System related content
-
"/ usr" directory is mounted on the second disk with user related content
[root@oldboyedu ~]# ls -ld /bin /lib /sbin /tmp lrwxrwxrwx. 1 root root 7 Apr 4 18:05 /bin -> usr/bin lrwxrwxrwx. 1 root root 7 Apr 4 18:05 /lib -> usr/lib lrwxrwxrwx. 1 root root 8 Apr 4 18:05 /sbin -> usr/sbin drwxrwxrwt. 11 root root 4096 Apr 6 17:30 /tmp [root@oldboyedu ~]# ls -ld /usr/bin /usr/lib /usr/sbin /usr/tmp dr-xr-xr-x. 2 root root 28672 Apr 4 18:23 /usr/bin dr-xr-xr-x. 29 root root 4096 Apr 4 18:06 /usr/lib dr-xr-xr-x. 2 root root 12288 Apr 4 18:23 /usr/sbin lrwxrwxrwx. 1 root root 10 Apr 4 18:05 /usr/tmp -> ../var/tmp
3. Directory structure of linux
3.1 Linux directory definition
- Marked with **** is the key memory
[root@oldboyedu /]# tree -L 1 / / ├── bin -> usr/bin #binaies, store command related***** ├── boot #Boot partition, system kernel and boot program***** ├── dev #Device, the directory where the device partition is located***** ├── etc #Binary package configuration path ├── home #Home directory of ordinary users***** ├── lib -> usr/lib #32-bit library file ├── lib64 -> usr/lib64 #64 bit library file ├── media #media ├── mnt #Temporary mount point***** ├── opt #option optional package (custom) ├── proc #Virtual file system, directory for storing process and kernel information***** ├── root #Administrator's home directory***** ├── run #Running program related information file ├── sbin -> usr/sbin #Directory of system binaies administrator command***** ├── srv #The directory of the data serving the user ├── sys #Virtual file system, directory for storing process and kernel information ├── tmp #Temporary files sitting in directory***** ├── usr #Directory of system software and user related programs, the second level directory***** └── var #Changeable data*****
4. / etc system initialization and setting related files
4.1. Configuration file of network card / etc / sysconfig / network scripts / ifcfg-eth0: used to configure files for Internet access
-
NIC name
- CentOS7: ems33
- Before CentOS 7: eth0 is the first network card eth1 is the second network card
-
Graphical configuration command:
- CentOS7: nmtui
- CentOS6: setup
-
Profile content
[root@oldboyedu ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet #NIC type PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none #Enable address protocol – static: static protocol – bootp: protocol – dhcp: Protocol - none: do not specify protocol [preferably] DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=eth0 UUID=a183d342-6fb0-4adc-8aba-7dced2f24643 DEVICE=eth0 #Network card interface name ONBOOT=yes #Whether yes|no is activated when the system starts IPADDR=10.0.0.200 #IP address of network card PREFIX=24 #Subnet mask 24 = 255.255.255.0 GATEWAY=10.0.0.254 #Network card gateway address DNS1=112.100.100.100 #Network card DNS address IPV6_PRIVACY=no
4.2, / etc/resolv.conf Linux system DNS client configuration file
-
DNS Domain Name System
- Function: the domain name entered in the browser is resolved to the IP address of the server, and then the server can be found to provide content
- A long time ago, I couldn't remember IP0.0.0.200 when I was online....
- At last, DNS was invented. The public resolution server resource requests its IP address if it wants to resolve
- Important functions: the domain name entered in the browser is resolved to the IP address of the server, and there are many other functions.
- The / etc/resolv.conf configuration file of DNS has been basically abandoned, which is replaced by DNS1=112.100.100.100 in the network card configuration file
- As long as it is set in the network card configuration, it will be automatically updated to / etc/resolv.conf
- But if you update the / etc/resolv.conf file first, the network card will be automatically cleared before
[root@oldboyedu ~]# echo "nameserver 1.1.1.1" >> /etc/resolv.conf [root@oldboyedu ~]# cat /etc/resolv.conf # Generated by NetworkManager nameserver 112.100.100.100 nameserver 1.1.1.1 [root@oldboyedu ~]# systemctl restart network [root@oldboyedu ~]# cat /etc/resolv.conf # Generated by NetworkManager nameserver 112.100.100.100
4.3/etc/hosts system local DNS resolution file
10.0.0.200 www.oldboyedu.com 10.0.0.201 www.baidu.com Everyone's computer must have a HOSTS for parsing.
- When the browser re enters www.baidu.com, the priority is to find hosts for parsing.
- The local DNS configuration file hosts takes precedence over the DNS resolution of the public network.
- LAN developer test.
4.4/etc/fstab: configure the files automatically mounted by the boot device
-
The device can only be used after being hung. Have we ever mounted the root / boot?
- The system automatically mounts the partition when we install the system
-
The automount file is / etc/fstab
-
For example, insert a U disk, and hope to access it directly after the next boot. It needs to be configured in / etc/fstab
[root@oldboyedu ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sat Apr 4 18:04:58 2020 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=63ff48bb-a38e-4a8a-afad-f24d25c7e442 / xfs defaults 0 0 UUID=00efac36-5fb3-4fcd-9249-a6210a52b5f0 /boot xfs defaults 0 0 UUID=9aa96766-7dd9-4fd4-979c-30ac56a20d57 swap swap defaults 0 0 //Device name (UUID) mount point file system type mount parameter whether to back up whether to power on check disk
-
View device UUID
-
blkid
[root@oldboyedu ~]# blkid /dev/sda3: UUID="63ff48bb-a38e-4a8a-afad-f24d25c7e442" TYPE="xfs" /dev/sda1: UUID="00efac36-5fb3-4fcd-9249-a6210a52b5f0" TYPE="xfs" /dev/sda2: UUID="9aa96766-7dd9-4fd4-979c-30ac56a20d57" TYPE="swap" /dev/sr0: UUID="2019-09-11-18-50-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
-
-
-
Set up auto mount
[root@oldboyedu ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sat Apr 4 18:04:58 2020 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=63ff48bb-a38e-4a8a-afad-f24d25c7e442 / xfs defaults 0 0 UUID=00efac36-5fb3-4fcd-9249-a6210a52b5f0 /boot xfs defaults 0 0 UUID=9aa96766-7dd9-4fd4-979c-30ac56a20d57 swap swap defaults 0 0 UUID="2019-09-11-18-50-31-00" /media iso9660 defaults 0 0
Restart the server to view the directory (online environment cannot restart the server)
[root@oldboyedu ~]# mount /dev/cdrom /media/ #Manually mount to the auto mounted directory, remember not to restart mount: /dev/sr0 is write-protected, mounting read-only [root@oldboyedu ~]# ll /media/ total 694 -rw-rw-r--. 1 root root 14 Sep 10 2019 CentOS_BuildTag drwxr-xr-x. 3 root root 2048 Sep 6 2019 EFI -rw-rw-r--. 1 root root 227 Aug 30 2017 EULA -rw-rw-r--. 1 root root 18009 Dec 10 2015 GPL drwxr-xr-x. 3 root root 2048 Sep 10 2019 images drwxr-xr-x. 2 root root 2048 Sep 10 2019 isolinux drwxr-xr-x. 2 root root 2048 Sep 6 2019 LiveOS drwxrwxr-x. 2 root root 671744 Sep 12 2019 Packages drwxrwxr-x. 2 root root 4096 Sep 12 2019 repodata -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7 -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r--. 1 root root 2883 Sep 12 2019 TRANS.TBL
Connecting to 10.0.0.200:22... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. WARNING! The remote SSH server rejected X11 forwarding request. Last login: Mon Apr 6 17:58:06 2020 from 10.0.0.1 [root@oldboyedu ~]# ll /media/ total 694 -rw-rw-r--. 1 root root 14 Sep 10 2019 CentOS_BuildTag drwxr-xr-x. 3 root root 2048 Sep 6 2019 EFI -rw-rw-r--. 1 root root 227 Aug 30 2017 EULA -rw-rw-r--. 1 root root 18009 Dec 10 2015 GPL drwxr-xr-x. 3 root root 2048 Sep 10 2019 images drwxr-xr-x. 2 root root 2048 Sep 10 2019 isolinux drwxr-xr-x. 2 root root 2048 Sep 6 2019 LiveOS drwxrwxr-x. 2 root root 671744 Sep 12 2019 Packages drwxrwxr-x. 2 root root 4096 Sep 12 2019 repodata -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7 -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r--. 1 root root 2883 Sep 12 2019 TRANS.TBL
4.5, / etc/issue and / etc/issue.net: display kernel parameter file in local window
Clear the contents of these two documents
[root@oldboyedu ~]# > /etc/issue [root@oldboyedu ~]# > /etc/issue.net
4.6. / etc / RedHat release: view the system version
[root@oldboyedu ~]# uname -r 3.10.0-1062.18.1.el7.x86_64 [root@oldboyedu ~]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core) [root@oldboyedu ~]# cat /etc/os-release #This file is more detailed and complex NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
4.7, / etc/sysctl.conf: Linux kernel parameter setting file
Linux kernel configuration and optimized files
4.8, / etc/init.d: directory of software startup program (before CentOS7)
4.9, / etc/initab: set the startup level and start the corresponding level script file (before CentOS7)
[root@oldboyedu ~]# cat /etc/inittab # inittab is no longer used when using systemd. # # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target # # systemd uses 'targets' instead of runlevels. By default, there are two main targets: # # multi-user.target: analogous to runlevel 3 # graphical.target: analogous to runlevel 5 # # To view current default target, run: # systemctl get-default # # To set a default target, run: # systemctl set-default TARGET.target #
-
Linux system run level description:
Operation level Grade level 0 Shutdown 1 Single user mode (used to retrieve the administrator password) 2 No NFS, multi-user mode 3 Command line mode text mode 4 not used 5 Graphic mode desktop mode 6 restart -
View run level
-
CentOS6:
-
runlevel
[root@oldboyedu ~]# runlevel N 3
-
-
CentOS7:
-
who -r
[root@oldboyedu ~]# who -r run-level 3 2020-04-06 18:02
-
systemctl get-default
[root@oldboyedu ~]# systemctl get-default multi-user.target
-
-
-
CentOS7 run level
[root@oldboyedu ~]# ll /usr/lib/systemd/system | grep level | grep -v wants lrwxrwxrwx. 1 root root 15 Apr 4 18:22 runlevel0.target -> poweroff.target lrwxrwxrwx. 1 root root 13 Apr 4 18:22 runlevel1.target -> rescue.target lrwxrwxrwx. 1 root root 17 Apr 4 18:22 runlevel2.target -> multi-user.target lrwxrwxrwx. 1 root root 17 Apr 4 18:22 runlevel3.target -> multi-user.target lrwxrwxrwx. 1 root root 17 Apr 4 18:22 runlevel4.target -> multi-user.target lrwxrwxrwx. 1 root root 16 Apr 4 18:22 runlevel5.target -> graphical.target lrwxrwxrwx. 1 root root 13 Apr 4 18:22 runlevel6.target -> reboot.target -rw-r--r--. 1 root root 761 Mar 18 07:46 systemd-update-utmp-runlevel.service
-
Switch operation level
[root@oldboyedu ~]# systemctl set-default graphical.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target. [root@oldboyedu ~]# systemctl get-default graphical.target #Graphical [root@oldboyedu ~]# systemctl set-default multi-user.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target. [root@oldboyedu ~]# systemctl get-default multi-user.target #text
-