Basic management of devices in Linux

Keywords: vim Linux network Windows

;

Experimental environment:

This experiment deliberately turned off graphics mode
Use init 3 command to turn off graphics mode, ctrl+alt F3 enter no graphics mode
Start network configuration:




Mount:



1. Partition

Partition method:

                 Bit Partition Table Size Payment Number of Partitions Supports Single Partition Size
 Traditional partitioning (MBR32 64BYTE primary 4, 16 2.2TB for all partitions)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UEFI (GPT) 64 128byte theoretically unlimited windows 128 8ZB

[1] MBR partitioning method:

  • Primary partition
    The primary partition table records partition information and can use partitions directly

  • Extended partition
    Partitions recorded in the primary partition table are not directly usable but logical partition containers

  • Logical Partitioning
    Partitions divided above extended partitions are called logical partitions

[2] Partition Method

[root@westos_device ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xfacc4ab8.

Command (m for help): m          #Get help
d                                #delete
l                                #List all partition types
n                                #Newly build
p                                #Show partition table
t                                #Change partition type
w                                #Save Changes
q                                #Sign out
g                                #Set partition mode to GPT
o                                #Set partition mode to mbr

Command (m for help): n          #Newly build
Partition type
   p   primary (0 primary, 0 extended, 4 free)      #Primary partition
   e   extended (container for logical partitions)  #Extended partition
Select (default p): p                               #Create primary partition
Partition number (1-4, default 1):                  #Partition Representation Location
First sector (2048-41943039, default 2048):         #Partition start location (default is recommended)
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +100M  #Partition End Position

Created a new partition 1 of type 'Linux' and of size 100 MiB.

Command (m for help): wq                             #Exit save (if direct q means exit, do not save)
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.



partprobe                     #Synchronize partition tables
partx -d /dev/sdb             #Clean up partition tables
partx -a /dev/sdb             #Reload partition table
mkfs.xfs -K /dev/sdb1         #The format device is the xfs device file system (equivalent to installing device management software on dev/sda1), where -K means no empty data blocks are discarded

mount /dev/sdb1 /mnt/westos   #The mount command is mounted temporarily and/etc/fstab is written if a permanent mount is required




Temporary mount:

Permanent mount:


[3] Device Delete

dd if=/dev/zero of=/dev/sdb bs=1M count=1





[4] Convert mbr partitioning to GPT

[root@westos_device ~]# parted /dev/sdb
(parted) mklabel                                                          
New disk label type? gpt 
Warning: The exiting disk label on /dev/sda will be destroyed and all date on this disk will be lost.
Do you want to continue?
Yes/No yes
(parted) quit

//fdisk can be used directly in RHEL8 /dev/sdb
g            #Adjust partitioning of/dev/sdb devices to GPT


[5] swap partition

  • Effect:
    When the program runs all the data in RAM, when the RAM usage exceeds the limit, to make the system more stable, we divide a portion of the space on the hard disk as the memory buffer swap
    When memory usage exceeds the limit, the kernel stores idle data in memory in swap and returns data from swap partitions to memory processes for processing when programs need data from swap partitions
  • swap partition size recommendation:

    Note: When HIBERNATE is turned on, the power information in the system will be saved after power off.After power on, the stored power information is returned to memory, which consumes a large amount of memory resources.The advantage is that it will make us turn on faster.
  • swap management
swaps -s View swap partition information


  • Create swap partition
    Create partitions and set the type of partition to linucxswap
Mkswap/dev/sda1 formats the device bit swap grid
swapon /dev/sda1 -p 0-32767 -p denotes the priority of the specified swap

All of the above operations are temporary



  • Permanently add swap partitions
vim /etc/fstab

  • Delete swap
    vim /etc/fstab
/dev/sdb1 swap swap defaults 0 0 ##Delete this line

swapoff /dev/sdb1
If you want to delete it completely, you can also delete it in fdisk/dev/sda.udevadm settle synchronizes partition tables after exit
This permanently removes the device


[6] Disk Quota

  • Effect:
    Set the maximum amount a user can write to a specified device

  • Setup method:

mount /dev/sdb1 /pub/ -o usrquota Mount device and activate quota parameters
quotaon -uv /dev/sdb1 Activate Quota
edqupta -u lee Set user lee quota


Disk quotas for user lee (uid 1001):
//Device user has created data Soft Limit Hard Limit User has created number of files Soft Limit Hard Limit
Filesystem       blocks         soft   haid          inodes         soft    hard
/dev/sdb1        20480            0    20480             1           0       0

//Permanently open quota:
vim /etc/fstab
/dev/sdb1 /pub   xfs     defaults,usrquota  0 0

//Test:
su - lee
cd /pub
dd if=/dev/zero of=/pub/leesile bs=1M count=22     #Failure to intercept data can only write 20M data

//Close quotas:
quotaoff -uv /dev/sdb1     
vim /etc/fstab     #Remove quota parameter usequota
 

Posted by lynncrystal on Wed, 24 Jun 2020 18:29:39 -0700