System partition management in Linux

  • Preparation before the experiment:

  • How to add a hard disk to the system:

    • 1) linux virt-manager, click the light bulb, addhardware, select virtio as the mode
    • 2) Windows is in the closed state, set, add, hard disk, next step, sata, next step, create, 5G, next step, location storage, complete
      Insert picture description here
      Insert picture description here
      Insert picture description here
      Insert picture description here
      Insert picture description here
      Insert picture description here

1. Device identification

  • After the equipment is connected to the system, it is in the form of files

  • Device file name:

    • SATA/SAS/USB /dev/sda,/dev/sdb ##s=SATA,d=DISK a=first block, b=second block
    • IDE /dev/hd0,/dev/hd1 ##h=hard
    • VIRTIO-BLOCK /dev/vda,/dev/vdb ##v=virtio
    • M2 (SSD) / dev / nvme0, / dev / nvme1 ## nvme = m2
    • SD/MMC(card) /dev/nmcblk0,/dev/nmcblk1 ##nmcblk=nmc card
    • CD-ROM drive /dev/cdrom, /dev/sr0, /dev/sr1
  • Device view

    • fdisk -l ##Check the disk partition situation, the real device situation in the system
      Insert picture description here

    • lsblk ##Device usage
      Insert picture description here

    • blkid ##Device management mode and device id, you can see the id, indicating that the device has been processed
      Insert picture description here

    • df ##View the device mounting situation
      Insert picture description here

    • df -h ##Unit 2^n

    • df -H ##Unit 10^n

    • cat /proc/partitions ##View the devices recognized by the system
      Insert picture description here

2. Mount the device

  • A device with a device id in the system can be used by the system

  • Mount command

  • mount -o mount parameter device mount point
    Insert picture description here

  • umount Equipment|Mounting Point##Uninstalling the device, busy shows that the uninstalled device is being used by the system program, and the uninstallation cannot be completed
    Insert picture description here
    Insert picture description here
    Insert picture description here

  • Uninstall the mount in use:

    • fuser -vm /mnt ##View what programs are running on the device
    • kill -9 ###End the program
    • fuser -kvm /mnt ##End most processes running on the device and solve the problem of program occupation
      Insert picture description here
  • mount ##View mount information
    Insert picture description here

  • mount device mounted point##Mounting device

  • mount -o rw /dev/vda1 /mnt
    Insert picture description here
    Insert picture description here

  • mount -o remount, ro /mnt ## (add mount point, no device) convert the mount parameters from read-write to read-only (only read but not write)
    Insert picture description here
    Insert picture description here

4. Partition

  • Partition method:
    Insert picture description here

MBR partition method
Primary partition: The partition that records the partition information in the primary partition table and can be used directly.
Extended partition: The partition recorded in the primary partition table cannot be used directly, but the logical partition goes to the
logical partition: the partition on the extended partition is also called Logical partition
o ##mbr分開去方法
p ##Check the partition situation.
Create an extended partition, and you can create 4 more partitions. Note: When creating an extended partition, you must give the remaining space to the extended partition
(when deleting the device, make sure that the device is not Use, otherwise the system is likely to crash)

Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

GPT partition
g #Select GPT partition method
p##gpt partition method can always be created

Insert picture description here
Insert picture description here
Insert picture description here

  • fdisk /dev/sdb ##Partition interface

    • m ##hint

    • d ##Delete
      Insert picture description here

    • n ##New

    • p ##View

    • -l ##View information

    • q ##Exit (do not save information)

    • wq ## (Exit and save to hard disk)
      Insert picture description here

  • udevadm settle ##Synchronize the partition table to the system
    Insert picture description here

  • dd if=/dev/zero of=/dev/vdb bs=1M count=1 ##Delete partition table information
    Insert picture description here
    Insert picture description here

  • 1. Set the partition method

    • parted /dev/vdb mklabel msdos ##Set the partition method to mbr
      Insert picture description here

    • parted /dev/vdb mklabel gpt ##Set the partition method gpt
      Insert picture description here

  • 2. Divide the partition

    • parted /dev/vdb mkpart primary 1 100 ##New partition
      Insert picture description here

    • parted /dev/vdb mkpart primary 101 200 ##New partition
      Insert picture description here

  • 3. Delete the partition

    • parted /dev/vdb rm 3 ##Delete 3 partition
      Insert picture description here

5. System file formatting

  • The newly created device cannot be mounted and used

  • Need to install file system

  • Common file system comparison:
    Insert picture description here

  • Device file system format

    • mkfs.xfs /dev/vdb1 -f ##Data needs to be formatted with -f
      Insert picture description here

    • mount /dev/sdb1 /mnt ##Temporary mount
      Insert picture description here

  • vim /etc/fstab

  • /dev/sdb1 /mnt xfs defaults 0 0 ##Permanently hang on the strategy
    Insert picture description here

  • mount -a ##Make the policy take effect immediately
    Insert picture description here

  • No need to delete it directly

  • The file is written incorrectly: (will cause the system to fail to start)
    Insert picture description here

    • Enter the supervisor password
      Insert picture description here

    • vim /etc/fstab modify the wrong location
      Insert picture description here

  • df -sh ##View device size

6. Disk quota

  • Allow users not to monopolize the disk and limit the size of data written to the disk by users
    Insert picture description here

  • umount /mnt

  • mount -o usrquota /dev/sdb1 /mnt ##Activate disk quota

  • mount | tail -n 1 ##
    Insert picture description here

  • edquota -u lee ##Edit disk quota
    Insert picture description here
    Insert picture description here

  • vim /etc/fstab ##Permanent activation of disk quota

  • Permanent activation: /dev/sdb1 /mnt xfs defaults,usrquota 0 0 ##Automatically activate quotas when the disk is activated
    Insert picture description here

  • Delete: directly delete the corresponding content
    Insert picture description here

  • hard ##The maximum size of data that can be written

7. Find instruction to use

  • Experiment preparation: Create file: in /mnt/ file
touch westosfile{1..5}
chmod 000 westosfile*
chown lee westosfile1
chgrp westos westosfile2
chown westos.lee westosfile3
chmod ug+w westosfile1
chmod ugo+w westosfile2
chmod 755 westosfile3
chmod 666 westosfile4
chmod 700 westosfile5
mkdir westosdir
ls -l /mnt

Insert picture description hereInsert picture description here

  • Monitoring command watch -n 1 ls -l /mnt
    Insert picture description here

  • File name search
    find /mnt/ -name westosfile1
    find /mnt -name westosf*
    Insert picture description here

  • 最大深度
    find /etc/ -name passwd
    find /etc/ -maxdepth 2 -name passwd
    find /etc/ -maxdepth 1 -name passwd
    Insert picture description here

  • 深度 浅 深度
    find / mnt -mindepth 2 -type d
    find / mnt -mindepth 1 -type d
    find / mnt -mindepth 0 -type d
    Insert picture description here

  • User search
    find /mnt -user root
    Insert picture description here

  • Group search
    find /mnt -group westos
    Insert picture description here

  • User and group search -a
    find /mnt -user westos -a -group lee
    Insert picture description here

  • User or group -o
    find /mnt -user westos -o -group lee
    find /mnt -user root -o -group lee
    Insert picture description here

  • Reverse search
    find /mnt -not -user root -o -group lee
    Insert picture description here

  • File modification time
    touch /mnt/westosfile1 ##Modification timestamp
    find /mnt -cmin 1 ##File
    date modified within one minute ##View time
    find /mnt -cmin +1 ##Modification time is greater than one minute
    Insert picture description here

  • File size search
    dd if=/dev/zero of=/mnt/westosfile1 bs=1M count=10
    dd if=/dev/zero of=/mnt/westosfile2 bs=1M count=20 dd if=/dev/zero of= /mnt/westosfile3 bs=1M count=30
    find /mnt -size 20M ##File size of 20M
    find /mnt -size -20M ##File size less than 20M find /mnt -size +20M ##File size greater than 20M
    Insert picture description here
    Insert picture description here

  • File permission search
    exact##File permission bit 111 find /mnt -perm 222

    Or ##u bit has 2 or g bit has 2 or o bit has 2 find /mnt -perm /222

    And ##u bit has 2 and g bit has 2 and o bit has 2 find /mnt -perm -222
    Insert picture description here

  • Process the search results
    find /mnt -perm -002 -exec rm -rf {}; ##Delete files with o bit 2
    Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44632711/article/details/113695477