This is the 30th day of my participation in the August Text Challenge.More challenges in August
preface
This is a continuation of the previous article, so please be patient.
Previous address: juejin.cn/post/700103…
Chapter 7 Linux Disk and file System management
-
Disk composition and partitioning review
- See chapter 1 for disk records
- GPT and MBR partitions
- disk
-
File system features
- The Linux orthodox file system is ext2
- Windows does not support ext2 file systems
- Typically, a mount of data is a file system, not a partition
- File permissions and file attributes are usually placed in separate blocks
- Permissions and properties are placed in inodes
- The actual data goes to the data block
- Each inode is numbered
- The super block
- Total information about the file system, total inode blocks, usage, remaining amount, file system format and related information
- Inode An attribute of a record file. Each file occupies an inode and records the block number of the file’s data
- Data block: the actual record of the file content, the file will occupy more than one block
- The super block
- This approach is an indexed file system
- However the limit
- The size and number of blocks cannot be changed after formatting
- Each block prevents at most one file of data
- If the file is larger than a block, take up more than one block
- Otherwise, the remaining space will be wasted
- File permissions and file attributes are usually placed in separate blocks
- inode table
- Inode records are as follows
- Read and write attribute
- Owner and user group
- The file size
- Ctime to establish or state change
- Last read time
- Last Modified time
- Define the identity of the file
- The actual content of the file points to
- The characteristics of
- Each inode size fixed 128B (ext4 to 256B)
- Files occupy an inode
- The number of files created is related to the number of inodes
- To read files, find the inode and check whether the inode records have the same permissions as the user
- How to calculate the maximum single file limit of 16GB for 1KB blocks?
- Twelve direct, one indirect and one triple indirect
- 12 go straight to 12 times 1 and K is equal to 12 K
- Indirect 256*1K = 256K
- The size of 1 can hold 256 records
- Double indirect
- 256*256* 1K = 256*2K
- Three indirect
- 256 * 256 * 256
- Total amount: 12 +256 +256 * 256 +256 * 256 = 16GB
- Inode records are as follows
- The super block
- The main information
- Total data blocks and inodes
- Number of unused and used inodes
- The inode size of a data block
- Information about the file system: the time when the file system was mounted, the time when data was last written, the time when the disk was last checked, and the information about the file system
- A valid value, 0 if the file is already mounted, and 1 otherwise
- Block mapping table
- The inode table
- dump2fs
- The main information
- The Linux orthodox file system is ext2
-
And the directory tree
- The low-level step of reading a file path
- example
- The procedure for reading /etc/passwd is as follows
- The inode /
- / blocks
- The/etc/inode
- The/etc/block
- The inode passwd
- Passwd blocks
- The procedure for reading /etc/passwd is as follows
-
Ext file access and journaling file system functionality
- Added file system operations
- Determine whether you have W and X permissions
- Find the corresponding inode number according to the inode mapping table, and write the new file
- According to the block mapping table, find the block code that is not used, write the actual data into the block, and update the block data in the inode
- Update the inode mapping table and block mapping table with block data, and update the contents of the super block
- Synchronous operation
- Journaling file system
- Preparation: When writing to a file, a logging block is required to record the information to be written to a file
- Actual write: Starts to write file permissions and data, and updates Metadata data
- End: Data and metadata are updated and recorded in the logging block
- Added file system operations
-
Linux file system execution
- Asynchronous processing
- Set unmodified data to clear
- After being modified, it is set to dirty data
- At this point, the operation is still in progress and has not been written to disk
- File system memory relationship
- The system will often file data into the memory buffer, speed up the read and write
- Linuxd will eventually run out of physical memory, which is normal
- Manual sync Forces dirty memory data to be written back to disks
- If the shutdown is normal, the system actively writes data back to the disk through sync
- Abnormal shutdown, need to restart after disk verification, or even file system damage
- Asynchronous processing
-
Meaning of mount points
- Traditional file systems:
- ext2
- minix
- fat
- iso9660
- Journaling file system
- ext3
- ext4
- reiserFs
- windows ntfs
- ibm jfs
- sgi xfs
- zfs
- Network file system
- nfs
- smbfs
- The query
ls -l /lib/moudules/$(uname -r)/kernel/fs
cat /proc/filesystems
- linux VFS
- Traditional file systems:
-
XFS file system
- The problem of ext
- Supports the widest range of data, and formats the slowest
- Data area
- The inode capacity can be adjusted
- The actual maximum usable block is 4K
- Inode can be another 256b – 2MB
- File system active login area
- Real time operating region
- Check the command
Xfs_info hardpoints | equipment
xfs_info /dev/vda2
df -T /boot
- The problem of ext
-
Simple operation of the file system
- Capacity of disks and directories
- df
- Lists the total disk usage of the file system
- parameter
- -a Lists all file systems
- -k kbyte Displays the file system capacity
- -m mbbyte Displays the capacity of the file system
- -h is displayed in easy-to-read formats such as Gbyte, Mbyte, and kbyte
- -h Replaces the M=1024K carry mode with M=1000K
- -t is also listed along with the disk partition file system name
- -i Indicates the number of inodes without the disk capacity
- format
- Filesystem: specifies the disk partition of the Filesystem
- 1k-blocks: indicates that the following number is 1KB
- Used: Used
- Available: indicates the remaining disk size
- Use% : the usage is greater than 90%
- Mounted on: Specifies the mounting directory of a disk
- case
df -aT
- List all special files in the system with their names listed
df -h
- Easy to read
- du
- Viewing the disk usage of a file system (Often used to view the disk space occupied by a directory)
- parameter
- -a Lists all file and directory capacities. By default, only files under directories are counted
- -h Displays the information in readable mode
- -s Lists the directory usage of each directory
- -s does not contain totals under subdirectories, unlike -s
- KB – k listed
- The -m MB listed
- case
du
du -sm /*
- df
- Capacity of disks and directories
-
Hard links and symbolic links
-
review
- Each file occupies one inode
- Inode numbers are required to read files
-
Hard link knowledge adds a file name to an associated record linked to an Inode for a directory
-
Any hard link deletion of an Inode does not affect another document
-
Disadvantages:
- Unable to link directories
- Why is that?
- Cannot cross file systems
- Why is that?
- Unable to link directories
-
A symbolic link
-
The characteristics of
- It is equivalent to a Windows shortcut, but changing the contents of this shortcut directly affects the contents of the source document
- Equivalent to a full copy of a file reference
- If the source file is deleted, the reference will not find its contents
-
Symbolic link capacity calculation
- According to the reference object file name length to determine
-
Ln uses hard links by default
-
parameter
- ln
- -s symbolic link. This parameter is required if the symbolic link is created
- -f If the file exists, delete it and create it
- ln
-
-
-
Format, partition, verify, and mount disks
-
Adding a disk
- Divide disks and create availability zones
- Format the disk and create a partition available file system
- If you’re careful, for file system validation,
- You need to set up a mount point on Linux. Mount it
-
How do I know the file system of my system
-
lsblk device
-
-d: lists only the disk itself and not the disk partition data. -f: lists the names of file systems on the disk. -I: uses ASCII line output instead of complex encoding (useful in some environments). -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx -rwx Instead of just listing the last name. -t: lists the detailed data of the disk device, including the disk queue mechanism and the amount of preread and write data
-
Display column reading
NAME: The NAME of the device. Will omit /dev and other leading directories! MAJ: In fact, I learned the core cognitive devices through these two codes. Respectively are primary: secondary device code! RM: Is it a removable device? CD-ROM, USB disk, etc. SIZE: Capacity. RO: A read-only device TYPE: Disk, partition or ROM MOUTPOINT: The mount point I talked about in the previous chapter
-
case
lsblk -ip /dev/vda
-
-
Blkid Lists device parameters, such as UUID
-
Parted Lists the partition table types and partitions of the disk
-
parted /dev/vda print
-
Model: Virtio Block Device (virtblk) Disk /dev/vda: 42.9GB Sector Size (Logical/Physical): 512B/512B Partition Table: Msdos Disk Flags: Number Start End Size Type File system flag 1 1049kB 42.9GB 42.9GB primary ext4 StartCopy the code
-
-
Disk partition: gdisk/fdisk
-
Please use fdisk for MBR partition table and GPT partition table.
-
gdisk
-
Gdisk Device name
-
Display parameters
Number: Indicates the partition slot Number. The Number 1 indicates /dev/vda1. Start (Sector) : Start sector number of each partition slot End (sector) : End sector number of each partition slot. You can calculate the total capacity of the partition slot Size: The capacity of the partition slot is Code: Possible file system types in the partition slot. The value is 8300 for Linux and 8200 for swap. However, this item is only a hint and does not really represent the file system in this partition slot. Name: Specifies the file system Name, and so on.
-
-
Be careful not to add numbers
-
Gdisk Added a partition
cat /proc/partitions
-
Partprobe Updates the partition table information of the Linux kernel
- Partprobe -s requires root permission
- View kernel partition records
cat /proc/partitions
-
Delete a partition with gdisk
-
-
fdisk
-
fdisk /dev/vda
A toggle a bootable flag b Edit BSD disklabel c toggle the DOS compatibility flag d delete a partition <== Delete a partition L list known partition types m print this menu n add a new partition <== Create a new empty DOS Partition table p print the partition table <== display the partition table on the screen q quit without saving changes <== create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write Table to disk and exit <== write the action to the partition table x extra Functionality (Experts only)Copy the code
-
-
-
Disk formatting
-
XFS File system mkfs.xfs
Mkfs.xfs [-b bsize] [-d parms] [-i parms] [[-l parms] [-l label] [-f] \ [[[-- -r parms] Device name
- parameter
Unit: Bytes k,m,g, T,p (lower case); s in particular refers to the "number" of the sector. -b: Block capacity is 512 to 64K, but the maximum capacity is limited to 4K for Linux. -d: agcount= value agsize= value agcount= value agcount= value agsize= value agcount= value agcount= value agsize= value agCount = value agCount = value agsize= value AGCount = value agCount = value agSize Agcount/AGsize = 1; agcount/agsize = 1; Size = value: the capacity of the data section, meaning that you do not have to use up all the device capacity su= value: when RAID is available, the value of the stripe means sw= value with the following sw= value: In the case of RAID, the number of disks used to store data (excluding backup and standby disks). Sunit = number of disks used to store data (similar to the number of sectors (512bytes), but in units of su. Swidth = number: Sector (512bytes) -f: if a file system exists in the device, use this -f to force the format. -i: inode Settings are as follows: size= Value: the minimum value is 256bytes and the maximum value is 2k. Generally, 256 is enough to use. Internal = [0 | 1] : the log device is built in? Default is 1 built-in, if you want to use external devices, use the bottom set logdev=device: log device is the meaning of the next device, must set internal=0! Size = number: specifies the size of the logon block, usually up to 512 blocks, or more than 2M! -l: indicates the header name of the file system. -r: specifies the extsize value of the realtime section. The extsize value is the important extent value. It is not necessary to set this value. The minimum value is 4K and the maximum value is 1 GB.Copy the code
-
other
[root@study ~]# grep 'processor' /proc/cpuinfo processor: 0 processor: 1#The XFS file system has two cpus, so let's set the XFS file system formatting parameters.[root@study ~]# mkfs.xfs - - f - - d agcount=2 /dev/vda4 meta-data=/dev/vda4 isize=256 agcount=2, agsize=131072 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 ..... .....#If you look at the previous example, you can see that agcount is 2. #Also, mkfs.xfs may not give you a formatting warning because it has already been formatted once! So we need to use -f Copy the code
-
Ext4 File system mkfs.ext4
-
Ext4 [-- -b size] [-- -l label] Specifies the name of the label
Options and parameters: -b: sets the block size (1K, 2K, 4K capacity), -l: followed by the device header name
-
-
Other file systems MKFS
-
-
File system verification
-
Xfs_repair Processes the XFS file system
Xfs_repair [-fnd] Specifies the installation name
Options and parameters: -f: the device behind is actually a file, not a physical device -n: simple check does not modify any file system data (check only) -d: usually used in single-player maintenance mode, for the root directory (/) check and repair action! Very dangerous! Don't use it casuallyCopy the code
- case
Xfs_repair /dev/vda4 Example: Check the existing file system /dev/centos/home [root@study ~]# xfs_repair /dev/centos/homeCopy the code
-
Fsck. ext4 processes the ext4 file system
Ext4 [-pf] [-b superblock] Options and parameters: -p: When the file system is being repaired, the system automatically replies to y to continue the repair operation. -f: Mandatory check! In general, if FSCK does not find any unclean flag, it will not voluntarily enter the detail inspection. If you want to force FSCK to enter the detail inspection, you will need to add the -F flag. -d: optimizes the configuration of directories in the file system. -b: The position followed by the superblock! In general, this option is not available. However, if your Superblock is damaged for some reason, this parameter can be used to try to rescue the backup superblock in the file system. In general, superblock backups are placed at: 1K block 8193, 2K block 16384, and 4K block 32768Copy the code
-
Use these commands only for extremely serious problems
-
Mounting and unmounting a file system
-
The premise
- A single file system should not be mounted repeatedly at different mount points (directories);
- A single directory should not mount multiple file systems.
- Directories that are intended to be mount points should theoretically be empty.
-
Mount the way
- case
[root@study ~]# mount -- a a [root@study ~]# mount [-- -- L] [root@study ~]# mount [-- -- t filesystem] LABEL=' [root@study ~]# mount [-- -t filesystem] UUID='' [root@study ~]# mount [- -t file system] File name Mount point Options and parameters: -a: Mount all unmounted disks according to the data in the /etc/fstab configuration file -l: Simply typing mount displays information about the current mount. Add -l to add column Label name! -t: You can add the type of file system to specify the type to be mounted. Common Linux file systems support the following types: XFS, ext3, ext4, Reiserfs, VFAT, ISO9660 (CD-ROM format), NFS, CIFS, and SMBFS (the last three are network file system types) -n: By default, the system writes the actual mount information to /etc/mtab in real time to facilitate the operation of other programs. However, in some cases (such as single-player maintenance mode) it is deliberately not written to avoid problems. You have to use the -n option. -o: Can be followed by some additional parameters added during mounting! For example, the account, password, and read/write permission are as follows: async, sync: Whether the file system uses the sync or async memory mechanism, see file system operation mode. The default is async. Atime,noatime: Whether to modify the read time of a file (atime). For efficiency, you can use noatime ro, rw: the filesystem becomes read-only (ro) or erasable (Rw) auto, noauto: Allows the filesystem to be mounted automatically (auto) dev, nodev: Are device files allowed to be created on this filesystem? Dev is suID. Nosuid: Is the file format containing suID /sgid allowed? Exec, noexec: Are executable binary files allowed on this filesystem? User, Nouser: Is the filesystem allowed to mount any user? Generally, only root users can mount the partition. However, if the user parameter is specified, ordinary users can mount the partition. Defaults: rw, suid, dev, exec, auto, nouser, and async remount.Copy the code
- /etc/filesystems: priority specified by the system to test the mounted filesystem type;
- /proc/filesystems: filesystem type that has been loaded to Linux
-
Our Linux-supported file system drivers are written in the following directory
/lib/modules/$(uname -r)/kernel/fs/
-
-
Mount the XFS/corruption/vfat
- sample
[root@study ~]# blkid /dev/vda4 /dev/vda4 /dev/vda4 UUID="e0a6af55-26e7-4cb7-a515-826a8bd29e90" TYPE="xfs" [root@study ~]# mount UUID="e0a6af55- - 26e7- - 4cb7- - a515- - /data/ XFS mount: mount point /data/ XFS does not exist So build it manually! [root@study ~]# mkdir - - p /data/xfs [root@study ~]# mount UUID="e0a6af55- - 26e7- - 4cb7- - a515- - 826a8bd29e90" /data/xfs [root@study ~]# df /data/xfs Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda4 1038336 32864 1005472 4% /data/xfs #Mount it smoothly, and the capacity is about 1G no problem![root@study ~]# blkid /dev/vda5 /dev/vda5: UUID="899b755b-1da4-4d1d-9b1c-f762adb798e1" TYPE="ext4" [root@study ~]# mkdir /data/ext4 [root@study ~]# mount UUID="899b755b- - 1da4- - 4d1d- - 9b1c- - f762adb798e1" /data/ext4 [root@study ~]#Copy the code
-
Mount a CD or DVD
/data/cdrom! [root@study ~]# blkid ..... ..... /dev/sr0: UUID="2015-04-01-00-21-36-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" [root@study ~]# mkdir /data/cdrom [root@study ~]# mount /dev/sr0 /data/cdrom mount: /dev/sr0 is write-protected, mounting read-only [root@study ~]# df /data/cdrom Filesystem 1K-blocks Used Available Use% Mounted on /dev/sr0 7413478 7413478 0 100% /data/cdrom#How can you use 100%? Yeah! Because it's a DVD! So I can't write any more! Copy the code
-
Mount vFAT Chinese drive (USB)
- case
- Note: cannot be an NTFS file system
[root@study ~]# blkid /dev/sda1: UUID="35BC-6D6B" TYPE="vfat" [root@study ~]# mkdir /data/usb [root@study ~]# mount - - o codepage=950,iocharset=utf8 UUID="35BC- - 6D6B" /data/usb [root@study ~]# # mount - - o codepage=950,iocharset=big5 UUID="35BC- - 6D6B" /data/usb [root@study ~]# df /data/usb Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 2092344 4 2092340 1% /data/usbCopy the code
-
Remount the root directory and the unspecified directory
- case
Rw and auto [root@study ~]# mount -- -o remount,rw,auto /Copy the code
/data/var = /data/var [root@study ~]# mkdir /data/var [root@study ~]# mount -- bind /var /data/var [root@study ~]# ls - - lid /var /data/var 16777346 drwxr-xr-x. 22 root root 4096 Jun 15 23:43 /data/var 16777346 drwxr-xr-x. 22 root root 4096 Jun 15 23:43 /var#The content is exactly the same! Because of mount directory! [root@study ~]# mount | grep var Copy the code
-
Umount (unmount device files)
- case
[root@study ~]# umount [-- -fn] Mount file name or mount point options and parameters: -f: forcibly unmount! Can be used in situations such as network file system (NFS) that cannot be read; -l: Immediately dismount the file system, better than -f! -n: this command is removed without updating /etc/mtab. Is to directly mount the file system to his unmount that is! After removing it, use df or mount to see if it still exists in the catalog tree. Remove the way, can be issued device file name or mount point, are acceptable! Take a look at the examples below! Example: Unmount all the file systems that you mounted before in this chapter: [root@study ~]# mount..... ..... /dev/vda4 on /data/xfs type xfs (rw,relatime,seclabel,attr2,inode64,logbsize=256k,sunit=512,..) /dev/vda5 on /data/ext4 type ext4 (rw,relatime,seclabel,data=ordered) /dev/sr0 on /data/cdrom type iso9660 (ro,relatime) /dev/sda1 on /data/usb type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=950,iocharset=...) /dev/mapper/centos-root on /data/var type xfs (rw,relatime,seclabel,attr2,inode64,noquota)#Find the mounted file system first, as shown above, the special font is just mounted device. #Basically, you can remove the rear attachment or the mount point! However, the last centos-root file has other mounts, #Therefore, the item must be dismounted using mount points![root@study ~]# umount /dev/vda4 <== unmount the device filename [root@study ~]# umount /data/ext4 <== unmount the mount point [root@study ~]# umount /data/cdrom <== because mount points are easier to remember! [root@study ~]# umount /data/usb [root@study ~]# umount /data/var <== = Always use mount points! Because the device is mounted in other waysCopy the code
-
-
Disk file system parameters are customized
-
mknod
- Is replaced by the major and minor values of the file
- Manual handling of device file cases
[root@study ~]# mknod install file name [BCP] [Major] [Minor] C: Set device name to a peripheral input device file, such as mouse/keyboard, etc. P: Set the device name into a FIFO file; Major: Code of the main device; Minor: Minor device code; Example: /dev/vda10 /dev/vda10 [root@study ~]# mknod /dev/vda10b 252 10 [root@study ~]# ll /dev/vda10brw -r--r--. 10 Jun 24 23:40 /dev/vda10#252 and 10 are meaningful, so don't set them arbitrarily.Example: Create a FIFO file, File name: / TMP /testpipe [root@study ~]# mknod/TMP /testpipe p [root@study ~]# ll/TMP /testpipe PRW -r--r-- 1 root root 0 Jun 24 23:44 /tmp/testpipe#Pay attention! This file is not just any file, it can't just be left here! #Please delete this file after testing! Take a look at the type of file! Is p! ^_^ [root@study ~]# rm /dev/vda10 /tmp/testpipe rm: remove block special file '/dev/vda10' ? y y rm: remove fifo '/tmp/testpipe' ? y y Copy the code
-
Xfs_admin Modifies the UUID and Label name of an XFS file system
- case
Xfs_admin [-lu] [-l label] [-u uuid] Device file options and parameters: -l: lists the label name of the device. -u: lists the UUID of the device. -l: sets the label name of the device. Set the UUID of this device.Copy the code
-
Tune2fs Modifies the label name and UUID of ext4
[root@study ~]# tune2fs [-- -l] [-- -l Label] [-- -u uuid] Dumpe2fs -h: read superblock data ~ -l: modify LABEL name -u: modify UUID. Example: After listing /dev/vda5 label name, Will it into vbird_ext4 / root @ study ~ # dumpe2fs - h/dev/vda5 | grep name dumpe2fs 1.42.9 (28 - Dec - 2013)Copy the code
-
Set boot mount
-
Some limitations of system mount
-
The root directory/must be mounted, and must be mounted before any other mount point.
-
Other mount points must be established directories, optionally specified, but must comply with the required system directory architecture principles (FHS)
-
All mount points can be mounted only once at a time.
-
All partitions can be mounted only once at a time.
-
To dismount, you must first move the working directory out of mount Point (and its subdirectories)
-
-
To view
cat /etc/fstab
- Description:
[device /UUID etc.] [mount point] [filesystem] [filesystem parameters] [dump] [FSCK]Copy the code
- explain
- Disk device file name /UUID/LABEL name:
- The device name of the file system or disk, for example, /dev/vda2
- UUID name of the file system, for example, UUID= XXX
- LABEL name of a file system, for example, LABEL= XXX
- Column 2: Mount Point:
- Column 3: File system for disk partition slot:
- Column 4: File system parameters:
- Column 5: Whether backup can be dumped
- Column 6: Whether to check sectors with FSCK:
- Disk device file name /UUID/LABEL name:
-
-
-
Special device Loop mount
- Mount the CD /DVD image file
- Formatting of large files
- mount
-
Memory swap space
- Create a swap using the physical partition slot
- Basic steps
- Partition: Use gdisk to create a partition slot on your disk for the system as swap. Since Linux’s gdisk defaults the partition slot ID to the Linux filesystem, you may need to set the system ID as well.
- Format: use the “mkswap device file name” to format the partition slot as swap
- Run the following command to start the swap: swapon device file name.
- Observe: Finally check the memory usage with the free and swapon-s commands.
- Basic steps
- Create a swap using the physical partition slot
-
Build swap using file sets
- Through a case study
- Use dd to add a 128MB file to/TMP:
- Use mkswap to format/TMP /swap as a swap file
- Use swapon to enable/TMP /swap.
- Use swapoff to close swap file and enable it automatically
- Through a case study
-
Special observations and operations on file systems
- Waste of disk space
- Use GNU Parted for partitioning behavior (Optional)
- Parted can be partitioned directly in a single instruction column, which is a very useful instruction! Its common syntax is as follows:
[root@study ~]# parted [install] [command [parameter]] Mkpart [primary | logical | extended] [corruption | vfat | XFS] began to end display partition: print deleted partitions: rm/partition example 1: [root@study ~]# parted /dev/vda print Model: Virtio Block Device (virtblk) <== Disk interface and model Disk /dev/vda: 42.9GB <== Disk name and capacity Sector Size (logical/physical): 512B/512B <== Size of each sector Partition Table: GPT <== Whether GPT or MBR Partition Disk Flags: pmbr_boot Number Start End Size File system Name Flags 1 1049kB 3146kB 2097kB bios_grub 2 3146kB 1077MB 1074MB xfs 3 1077MB 33.3GB 32.2GB LVM 4 33.3GB 34.4GB 1074MB XFS Linux filesystem 5 34.4GB 35.4GB 1074MB ext4 Microsoft basic data 6 35.4GB 36.0GB 537MB Linux -swap(v1) Linux swap [1] [2] [3] [4] [5] [6]Copy the code
- Displays the meaning of parameters
1. Number: This is the Number of the partition slot. For example, number 1 stands for /dev/vda1; 2. Start: How many MB of the disk does the partition Start from? Interesting!!!! He uses capacity as a unit. 3. End: How many MB does this partition End on this disk? 4. Size: How much capacity does the partition slot have? 5. File system: Analyze possible File system types. 6. Name: gdisk's System ID.Copy the code
- case
- Use Parted to change the MBR partition table to GPT
- It’s too dangerous to undo
- Use Parted to change the MBR partition table to GPT
Chapter 8 File and file system compression
-
Use and technology of compressed files
-
Linux common compression command
-
Gzip, zcat, zmore, zless, zgrep
-
grammar
Gzip [-cdtv] File name
Zcat File name.gz
Options and parameters: -c: Outputs compressed data to the screen, which can be processed through data flow redirection. -d: decompresses the parameter. -t: can be used to check the consistency of a compressed file ~ to see whether the file has any errors. -v: displays information such as the compression ratio of original files or compressed files. -# : # represents the number of compression levels, -1 is the fastest, but the worst compression ratio, -9 is the slowest, but the best compression ratio! The default is 6Copy the code
-
Egrep lookup
-
-
bzip2, bzcat/bzmore/bzless/bzgrep
- For the gzip upgrade
- advantages
- Better compression than Gzip
- disadvantages
- It takes longer
-
xz, xzcat/xzmore/xzless/xzgrep
- advantages
- Better compression than Bzip2
- disadvantages
- slow
- advantages
-
-
Package commands (common)
- Options and Parameters
Options and parameters: - c: establishing packaging files, can match the -v to view are packaged in the process of file name (filename) - t: review the packaging file which contains the content of the file name, just focus on view "file name"; -x: The unpacking or unpacking function, which can be combined with -c (uppercase) unpacking in a specific directory. Note that -c, -t, and -x cannot appear in a sequence of instructions at the same time. -z: Compressed/decompressed using gzip: the file name is *.tar.gz. -j: compressed/decompressed using bzip2: the file name is *.tar.bz2. -j: Compressed/decompressed using Xz: Xz, -z, -j, -j can not appear in a sequence of instructions at the same time -v: in the process of compression/decompression, the file name is displayed! -f filename: -f filename: -f -f write a separate option. -c directory: This option is used for decompression, and can be used to decompress in a specific directory. Other options that will be used in subsequent exercises are described as follows: -p(lowercase) : reserves the original permissions and attributes of backup data, which are often used to back up important configuration files. -p(uppercase) : reserves the absolute path, which allows backup data to contain the root directory. --exclude=FILE: Exclude =FILE: Do not wrap FILE during compression!Copy the code
- The following commands are commonly used:
- The compression
Tar -jcv -f Filename.tar. bz2 Specifies the name of a file or directory
- The query
tar -jtv filename.tar.bz2
- unzip
Tar -jxv -f filename.tar.bz2 where to decompress
- The compression
- case
- Zip the file below /etc to see the special advantages
- Why remove the/root directory path?
- If you want to add the root path to tar, what do you do?
- Backup data is decompressed and stored in a specific directory
- How do I specify the directory to unpack
- A way to unlock only a single file
- Start by looking for the document name
tar - - jtv - - f /root/etc.tar.bz2 | grep 'shadow'
- Start by looking for the document name
- Package a directory without some files in that directory
- –exclude specifies the usage of the parameter
- Only back up files that are newer than at any point in time
- First use search to find the corresponding file
tar -jcv -f /root/etc.newer.then.passwd.tar.bz2 --newer-mtime="2015/06/07" /etc/*
- Package the backup over and over again using the pipeline
tar -cvf - /etc | tar -xvf -
- Note – represents input and output
- Example: System backup case
- Combine what we learned above. Back up data in filtering mode
- Unzipped SELinux
- The system configuration may be affected
-
XFS file system backup and restore
-
Run the xfs_dump backup command
- The backup behavior can be cumulative, similar to that of the SVN. In a new backup, only different files are added
- limit
- The file system must be mounted
- Xfsdump must operate with root privileges (involving filesystem relationships)
- Xfsdump can only back up XFS file systems.
- Data (files or storage media) backed up by xfsdump can only be parsed by XFSRestore
- Xfsdump can identify backup files by the UUID of the file system. Therefore, two file systems with the same UUID cannot be backed up.
- By default, xfsdump only supports backup of file systems and does not support backup of specific directories
-
Method of use
Xfsdump [-- -L S_label] [-- -m M_label] [-- -L #] [-- -f Standby file] The standby file
- Options and Parameters
Options and parameters: -l: xfsdump records the session header for each backup. You can fill in the brief description about the file system. -m: xfsdump records the header of the storage media. Is the lower case of L, is the specified level ~ 0~9 a total of 10 levels oh! -f: a bit like tar! Followed by the file, can also pick up such as/dev/st0 device file name or other general file filename, etc - I: from the/var/lib/xfsdump state backup information/inventory list nowCopy the code
-
case
-
Cumulative backup
-
-
XFS file system restore xfsRestore
- Take your place and come back when the system is installed
-
Observe xFsdump with xfsRestore
- Simply restore the file system whose level is 0
- Restore the accumulated backup data
- Restore the XFSRestore interaction mode for only part of the files
-
CD writing tool
- Understanding can
-
Other common compression and backup tools
-
dd
- role
- Dd can read the contents of the disk device and back up the entire device as a file
- Method of use
dd if="input_file" of="output_file" bs="block_size" count="number"
- Options and Parameters
Options and parameters: if: is the input file. Of: output file oh, can also be a device; Bs: Size of a planned block. If this parameter is not specified, the value is 512 bytes(size of a sector). Count: Number of BS.Copy the code
- case
- Example 1: Backup /etc/passwd to/TMP /passwd.back
dd if=/etc/passwd of=/tmp/passwd.back
- Example 2: Just burn the contents of the drive, again back up to the image block
- Example 3: If your USB is /dev/sda, please burn the image from example 2 to a USB disk
- Example 4: Make a DD backup of your /boot file system
- Example 1: Backup /etc/passwd to/TMP /passwd.back
- Examples:
If you want to fully copy your /dev/vda2 partition to another partition, please use the unpartitioned capacity on your system to create a partition slot similar to /dev/vda2 (only larger than /dev/vda2, not smaller!). , and then perform a complete replication (including the blocks to be copied for boot Sector). A: Because our /dev/sda is also a test USB disk, you can make fun of it! We've just tested copying the DISC image into it. /dev/sda1 = /dev/vda2 = /dev/sda1 = /dev/sda1Copy the code
- Pay attention to the point
- Note that the DD is replicated along with the UUID. If you want to replicate two identical disks, you need to redefine the UUID
- role
-
-
cpio
-
role
- Cpio can back up anything, including device device files
- Just remember the grammar for now
-
disadvantages
- Do not actively find files, need find to find files to back up
-
grammar
/ root @ study ~ # cpio - ovcB > [file | device] < = = backup/root @ study ~ # cpio - ivcdu < [file | device] < = = reduction/root @ study ~ # Cpio - ivct < [file | device] < = = see options and parameters of the backup will have access to: -o: the copy output of data to a file or device - B: Increase the number of Blocks by default to 5120 bytes. The default is 512 bytes! The benefit of this is that large files can be stored faster (see i-Nodes). Restore the options and parameters that will be used: -i: copy data from a file or device to the system. -D: automatically create a directory! The data backed up by CPIO may not be in the same directory, so we need to make cPIO create a new directory when restoring. In this case, we need the -d option! -u: automatically overwrites older files with newer ones! -T: needs to be matched with the -i option, which can be used to "view" the contents of a file or device created using CPIO. Some shareable options and parameters: -v: Enables the file name to be displayed on the screen during storage. -c: a new portable format for storageCopy the code
-
exercises
-
Scenario simulation problem 1: Please delete unnecessary files generated during the exercises in this chapter to keep the system capacity from being spooked!
-
Scenario Simulation problem 2: You want to backup data in the /home directory every hour, but you are worried that backups will be too large at a time, so you want to use Xfsdump to backup data to /backups one by one. How to deal with it? O Goals: Understand the role of XFsdUMP and the different levels; O Prerequisite: The data to be backed up is a single partition, that is, in this example, the actual processing method of /home is actually quite simple! We can do it like this:
-
Scenario 3: Suppose after some time, your /home filesystem becomes strange and you want to return the filesystem to its original backup data. What would you do? Here’s what you can do:
Since /home is a partition that users use whenever they log in, you should not be able to remove it! Therefore, you will need to log out all normal users, and then log in to the system directly from TTy2 as root. Do not log in using normal accounts and then su to root! This is the way to remove /home oh!
Chapter 9 Vim Editor
-
Vi and vim
-
Why learn VI and Vim
- Built-in commands are used
- Unix almost always comes with it
- Convenient and simple
- powerful
-
Vi Usage
- Three models
- General command mode +
- Edit mode
- Command line mode
- Three models
-
Pay attention to
- General command mode can be switched with edit mode and command column mode, but the edit mode and command column mode cannot be switched with each other
-
A simple case
- Use vi filename to enter the general command mode
- Use I to enter editing mode
- Use Esc to exit the general command mode
:wq
To save
-
Common operations
-
General pattern
-
HJKL can move up, down, left, and right
-
CTRL + F and CTRL + B move up and down a page
-
/ Search continue Press n to search
-
0 或者 home
-
$or end
-
Gg jumps to the first line
-
N (number) Enter Moves the cursor down n lines
-
:n1,n2s/word1/word2/g
- N1 and n2 are numbers. Look for the string word1 between columns N1 and n2 and replace it with word2! For example, to search for vbird between 100 and 200 columns and replace it with vbird: “:100,200s/vbird/ vbird/ g”. (common)
-
:1,$s/word1/word2/gc
- Find the word1 string from the first column to the last column and replace that string with word2! And display prompt characters to the user before replacing (confirm) whether to replace! (common)
-
:1,$s/word1/word2/g
- Find the word1 string from the first column to the last column and replace that string with word2! (common)
-
X exits without changing the time
-
Dd delete a row
-
Yy Copy one line
-
Nyy copies many rows as 3YY
-
U Restore the previous operation
-
CTRL + R to redo the previous action
-
Repeat the previous action
-
-
Edit mode
-
I I insert mode
- I for “Insert from current cursor location”
- I is “start insertion at the first non-space character in the current column”
-
A and a
- A is “insert from the next character where the cursor is currently located”
- A is “insert from the last character in the cursor column”
-
O and o
-
R and r.
-
-
Command mode
- w
- q
- !
-
A real case, a real case
-
1. Create a directory named vitest in/TMP. 2. Go to the Vitest directory. 3. Copy /etc/man_db.conf to this directory (or download the man_db.conf file from the above link). 4. Open the man_db.conf file in the local directory using vi. 5. Set a down sign in vi. 6. Move to column 43 and move 59 characters to the right. What text do you see in the parentheses? 7. Move to the first column and look down for the string "gzip". What column is it in? 8. Next, I want to change the "lowercase man string" between columns 29 and 41 to "uppercase man string", and select one by one whether to change, how to command? If you press "y" all the way through the selection process, how many men will be changed in the last column? 9. What methods can I use to recover all the modifications if I suddenly go back on my word? 10. I will copy 6 columns 66 to 71 (including MANDB_MAP) and paste it after the last column. 11. I do not want comment data starting with # between columns 113 and 128. How do I delete it? 12. Save this file as a man.test.config file; 13. Go to column 25 and delete 15 characters. What is the first word that appears? 14. Add a new column to the first column and enter "I am a student..." ; 15. Store and leave!Copy the code
-
Vim cache handling
- The problem
- Problem 1: There may be other people or programs editing the file at the same time:
- In the context of the previous VIm, vim may break (crashed) for some unknown reason:
- The problem
-
Additional features of Vim
-
Visual block
- V begins to reverse white
- The white V line
- Y reverse white copy
- D Reverse white delete
-
Multifile editing
- :n Edits the next file
- :N Edits the previous file
- :files Lists all files currently open for this vim
- case
- Multifile editing
-
Multi-window function
- :sp {filename}
- There are file name comparison files,
- Otherwise, create a new window for comparison
- Use CTRL + W + Up or CTRL + W + Down to switch Windows
- :sp {filename}
-
Vim keyword completion
- Shortcut key use
- [CTRL]+x -> [CTRL]+n completes the file content text that is currently being edited as a keyword
- [CTRL]+x -> [CTRL]+f fill out the file name in the current directory
- [CTRL]+x -> [CTRL]+ O use the extension as a syntax complement to vim’s built-in keywords
- Shortcut key use
-
Vim environment Settings and records: ~/. Vimrc, ~/. Viminfo
-
Vim commonly used figure
- Review images
-
Other VIM considerations
- Chinese garbled
- DOS and Linux newline
- dos2nnix
- unix2dos
-
Language coding conversion
iconv -f big5 -t utf8 vi.big5 -o vi.utf8
iconv -f utf8 -t big5 vi utf8 | \
exercises
- In chapter 7, when writing /etc/fstab, use vim to compile the command nano, and change the defatuls of the column added in chapter 7 to default. Be sure to correct the original information before leaving. In addition, if you annotate the column (with a # at the beginning), you will notice that the font color has also changed.
- Try applying some of the vIMRC content in this chapter to the home directory of the account you normally use on your system, including: O Set search for high brightness backlight o Set syntax check to start o Set default start line number to display o Set two status bars (one status line + one command line) :set lastStatus =2
Chapter 10: Learn about the BASH Shell
-
Brief Introduction to shell
- What is a shell?
- Broad sense: refers to a shell program that can mobilize the kernel and hardware to deal with
- Narrow sense: a command program that directs hardware through the kernel
- Why learn the shell?
- Prevention of emergencies
- Personal ascension
- The company requires
- Some special cases can only be solved using a shell
- What happens if you don’t learn the shell
- Use x Windows
- Use third-party applications
- How to Learn the Shell
- Much knock
- More practice
- Multi-simulation scenario
- Periodically clear expiration logs
- Start Start some applications
- Disk warning
- What is a shell?
-
The shell and /etc/shells functions are valid
- Cshell and bshell (bash)
- Check /etc/shell to get the shells available to the system
- /bin/sh
- / bin/bash by default
- /bin/tcsh
- /bin/csh
-
The function of the bash
- History Function
- Record location:.bash_history of the home directory
- Note: according to the login to record, record the last login command, this time is cached
- Record location:.bash_history of the home directory
- Completion function
- Make sure the command is correct
- Command alias
- alias
- Simple to use:
alias lm ='ls -al'
- Simple to use:
- alias
- The wildcard
- History Function
-
Check whether the command is built-in to Bash shell: type
-
man bash
-
Type Basic usage
type -t umask
-
Command shortcut keys: Common
- CTRL + U and CTRL + K
- CTRL + A and CTRL + E
-
-
Learn basic shell content
- Variable definitions
- Echo and the unset
- Case study:
echo $HOME
- Settings: Variables
echo ${myname}
- Special point
- Echo default variable is null
- Case study:
- Set up rules
- The difference between double quotes and single quotes
- case
- How do I access the kernel directory module
cd /lib/moudules/$(name -r)/kernel
- How do I access the kernel directory module
- Echo and the unset
- Variable to cancel
- unset name
- Variable definitions
-
Setting environment variables
-
Env Displays environment variables
-
Declare Another way to define a variable, declare a variable
- declare -i number=
number- Generate a random number
- declare -i number=
-
Set Observes and sets custom variables
-
PS1 Prompt character
-
There are many definitions, specific you can view the corresponding Baidu content
-
Blog.csdn.net/qq_34208467…
-
Parameter meaning
\d: shows the date format of "week, month and day", for example: "Mon Feb 2" \H: full host name. For example, toddie's trainer is "study.centos.vbird" \h: only take the host name before the first decimal point, such as toddie's host name is "study" followed by omits \t: display time in 24-hour format "HH:MM:SS" \t: Display time, in 12-hour format "HH:MM:SS" \A: Display time, in 24-hour format "HH:MM" \@ : Display time, in 12-hour format "AM/PM" \u: current user account name, such as "dmtSAI"; \v: BASH version information, such as the test host version 4.2.46(1)-release, only "4.2" display \w: full working directory name, the directory name written from the root directory. But the home directory will be replaced by ~; \W: Use the basename function to get the name of the working directory, so only the last directory name is listed. \# : the number of instructions issued. \$: prompt character, if root, prompt character is #, otherwise $~Copy the code
-
-
$
- Check the PID:
$$
- Check the PID:
-
?
- Represents the return value of the previous command
- How to understand?
- After a command is executed, a value of 0 and a value of non-0 indicates that the command is successfully executed
- Non-zero indicates failure
-
Export Customizes environment variables
-
What’s the difference between env and set?
- Env is the parent process environment variable
- Set can be a child process variable
- Child processes inherit only environment variables from parent processes, not custom variables
-
Use export to turn custom variables into environment variables
-
-
Declare Environment variables to custom variables
-
-
Language variables
- Locale-a Displays all languages supported by the system
-
Variable effective range
- Variable keyboard reads and array declarations: read, array, declare
- read
- role
- Waiting for keyboard input
- parameter
- -p Indicates the prompt character
- -t Indicates the number of waiting seconds
- role
- Declare, typeset
- role
- Declaring variable types
- -a Defines the array type
- -i Defines the integer type
- The same – e export
- The -r readonly type
- Declaring variable types
- Note:
- Default string type
- The default operation is integer at most
- role
-
Restrictions related to file system programs: ulimit
- role
- Limit the number of open files, available CPU time
- Total memory available
- Parameters and syntax:
Options and parameters: -h: hard limit, strict setting, must not exceed the set value; -s: soft limit, warning setting. The value can be exceeded, but a warning message will be displayed if the value is exceeded. Soft is usually smaller than hard. For example, if soft is 80 and hard is 100, you can use 90 (because it does not exceed 100), but if it is between 80 and 100, a warning message will alert you! -a: All limits can be listed without any options or parameters. -c: When errors occur in certain programs, the system may write the program information in memory as a file (debugging). This file is called a core file. This limits the maximum capacity of each core file. -f: indicates the maximum file capacity that the shell can build (usually set to 2GB). The unit is Kbytes. -d: indicates the maximum segment capacity that the program can use. -l: amount of memory available for locking. -t: maximum available CPU time (in seconds). -u: maximum number of processes that can be used by a single userCopy the code
- How to recover?
- Log out and log in
- role
-
Deletion, substitution, and substitution of variables
-
Variable deletion and substitution
- Case study:
${variable#/*local/bin:}} ${variable#/*local/bin:} this is the name of the original variable that must exist in this deletion mode. ${variable# #/*local/bin:} # ${variable# /*local/bin:} represents the shortest part of the variable to be deleted. Note that we can also replace any number of characters from 0 to infinity with the wildcard *. As shown in example 2 above, the path variable is deleted as follows: /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/dmtsai/.local/bin:/home/dmtsai/binCopy the code
- Simple to understand
${variable# #/*local/bin:} # Represents "delete from the front of the variable content to the right" and delete only the shortest oneCopy the code
- # and ## represent the following
- # Which is the shortest that matches the substitution character
- ## matches the longest substitution character
- How do I delete content from back to front
- % and % %
-
replace
- case
[dmtsai@study ~]$echo ${path/sbin/ sbin}Copy the code
-
Variable testing and content replacement
- case
Example 1: $echo ${username} <== root [dmtsai@study ~]$echo ${username} [dmtsai@study ~]$username=${username-root}Copy the code
- The key is — – Number
- This is followed by a replacement character for a variable that does not exist
- What do I do if I want to replace an empty string
- :- Can be preceded by: colon
-
Variable does not exist?
-
case
[dmtsai@study ~]$unset STR; [dmtsai@study ~]$unset STR; var=${str? No such variable}} -bash: STR: no such variable <== because STR does not exist, an error message is outputCopy the code
-
-
-
Name aliases and history commands
- Alias and unalias
- history
- Man query the usage mode
-
The operating environment of the Bash shell
- Search order of paths and commands (interview end)
- Commands to look up by absolute and relative paths
- Command found due to alias
- Bash’s built-in commands to execute
- Find by the $PATH environment variable
- Search order of paths and commands (interview end)
-
Welcome message for login
cat /etc/issue
- Cat /etc/issue.net Welcome message used for remote login such as SSH
- Cat /etc/motd is used for certain information that all logged-in users want to know
-
Bash’s environment configuration file
- The login and non – login shell
- The login shell obtains the complete login process required for bash
- Non-login shell: The bash method does not require a repeat login
- Why do we need to know these two things first
- Because different login forms obtain different shell configurations
- The login and non – login shell
-
What the login shell reads
- /etc/profile The overall configuration of the system is fragile and difficult to recover in the event of a crash
- /etc/profile Main content
- PATH
- USER
- HOSTNAME
- HISTSIZE
- umask
- Calling external files
- /etc/profile.d/*.sh
- /etc/locale.conf
- /usr/share/bash-completion/completions/*
- /etc/profile Main content
- ~/. Bash_profile or ~/. Bash_login or ~/. Profile Profile of the user
- /etc/profile The overall configuration of the system is fragile and difficult to recover in the event of a crash
-
The command source reads the configuration file
- role
- It is convenient to switch variable environments when the case requires multiple variable environments
- When installing certain software, quickly change the environment variables to test if the Settings are correct
- Note:
- /etc/bashrc (red hat 系统特有)
- role
- Set the umask depending on the UID
- Set prompt characters according to different UUIds
- Call/etc/profile. D / *. Sh
- role
- /etc/bashrc (red hat 系统特有)
- role
-
Terminal environment set stTY and SET
-
linux.die.net/man/1/stty
-
www.computerhope.com/unix/ustty….
-