[email protected] ~ / lsblk                     / List the hard disks recognized by the curren...">

当前位置:网站首页>04 disk space management

04 disk space management

2022-06-25 21:00:00 Zhushuaijie 1

 —— Identify the hard disk

Real machine windows  VMware
[[email protected] ~]# lsblk                     # List the current system distinguish Of Hard disk
[[email protected] ~]# ls    /dev/sda      #
[[email protected] ~]# ls    /dev/sdb     #

Real machine Linux-------KM
[[email protected] ~]# lsblk                    # List the hard disks recognized by the current system
[[email protected] ~]# ls    /dev/vda      #
[[email protected] ~]# ls    /dev/vdb     #

—— Zoning planning and use

One 、 Partition management

1. Disk structure and concept

2. A hard disk “ art ” The journey

 3. Zoning

Partition plan ( Partition mode ): MBR And GPT
MBR/msdos Partition mode
Partition type Primary partition 、 Extended partitions ( Take up all the remaining space )、 A logical partition
At best 4 Primary partitions
— The extended partition may not have , At most one
— 1~4 Primary partitions , perhaps   3 Primary partitions +1 Extended partitions (n Logical partitions )
— The maximum support capacity is 2.2TB Of disks
— Extended partition cannot be formatted , Space cannot store data directly

— Partitions that can be used to store data : Primary partition 、 A logical partition

4. Use fdisk Partitioning tool

fdisk   -l   /dev/vda          # View partition table

fdisk    Hardware device                 # Modify the partition table of the hard disk

Comprehensive zoning :

[[email protected] ~]# fdisk    /dev/vdb            ----vda,cdb,vdc,vdd---- This is the hard disk name
n create primary partition 1-----> Partition type enter -----> Partition number enter -----> starting sector enter -----> stay last At the end +2G
p
View partition table
n create primary partition 2-----> Partition type enter -----> Partition number enter -----> starting sector enter -----> stay last At the end +2G
p
View partition table
n create primary partition 3-----> Partition type enter -----> Partition number enter -----> starting sector enter -----> stay last At the end +2G
p View partition table
n create extended 4-----> Partition type enter -----> Partition number enter -----> starting sector enter -----> stay last At the end enter - Allocate all remaining space to the extended partition
p
View partition table
n Create logical partitions 5-----> start enter -----> At the end +2G
n
Create logical partitions 6-----> start enter -----> At the end +2G
p
View partition table
w Save and exit

[[email protected] ~]# lsblk

[[email protected] ~]# partprobe           # Refresh the partition table --- Unrecognized partition table , When the partition cannot be completed , Refresh try

5. Identify new partition

Use partprobe command
— When the partition table of the hard disk is changed , The change of partition table shall be notified in time Linux kernel , best reboot once
— Otherwise, the exact device may not be found when accessing the partition

[[email protected]localhost ~]# partprobe   /dev/vdb
## perhaps
[[email protected] ~]#reboot

Two 、 format partition

format : The process of giving a spatial file system
file system : Rules for storing data in space
windows Common file systems : NTFS     FAT( Strong compatibility )
Linux Common file systems :ext4(RHEL6)    xfs(RHEL7)    FAT

1. Common formatting tools

mkfs Toolset

[[email protected] ~]# mkfs.<Tab><Tab>         # Press twice in a row tab key
mkfs.btrfs      mkfs.ext3     mkfs.minix    mkfs.xfs
mkfs.cramfs  mkfs.ext4     mkfs.msdos   
mkfs.ext2      mkfs.fat        mkfs.vfat
    
[[email protected] ~]# mkfs.ext4    /dev/vdb1          # Format file system ext4
[[email protected] ~]# blkid    /dev/vdb1                  # View file system types
[[email protected] ~]# mkfs.xfs    /dev/vdb2              # Format file system xfs
[[email protected] ~]# blkid    /dev/vdb2                    # View file system types

3、 ... and 、 Accessing the file system

1. Access the formatted partition

—— Use mount Command mount to use , And visit the test

[[email protected] ~]# mkdir     /mypart1   
[[email protected] ~]# mount       /dev/vdb1       /mypart1/           # mount
[[email protected] ~]# mkdir     /mypart2  
[[email protected] ~]# mount       /dev/vdb2       /mypart2/           # mount

—— Use   df  Check usage
[[email protected] ~]# df -h             # Display the information of the device being mounted
file system                  Capacity   Already used   You can use Already used % Mount point
/dev/mapper/centos-root   17G  3.7G   14G   22% /
devtmpfs                 480M     0  480M    0% /dev
tmpfs                    496M     0  496M    0% /dev/shm
tmpfs                    496M  7.8M  489M    2% /run
tmpfs                    496M     0  496M    0% /sys/fs/cgroup
/dev/vda1               1014M  157M  858M   16% /boot
tmpfs                    100M  4.0K  100M    1% /run/user/42
tmpfs                    100M   28K  100M    1% /run/user/0
/dev/sr0                 8.8G  8.8G     0  100% /run/media/root/CentOS 7 x86_64
/dev/vdb1                2.0G  6.0M  1.8G    1% /mypart1

2. Realize automatic mount after power on   /etc/fstab

         /dev/vdb1              /mypart1           ext4        defaults                  0                    0( Don't test )
                                                                                                                                   1( Give priority to detection )
                                                                                                                                   2( Secondary test )

[[email protected] ~]# vim     /etc/fstab
/dev/vdb1  /mypart1  ext4  defaults  0  0
/dev/vdb2  /mypart2  xfs    defaults  0  0

mount  -a (auto)    --->    /etc/fstab        // Automatically mount

[[email protected] ~]# umount   /mypart1      # uninstall
[[email protected] ~]# umount   /mypart2      # uninstall
[[email protected] ~]# mount   -a                   # Automatically mount
testing /etc/fstab  Automatically mount the configuration file after power on , Is the format correct
testing /etc/fstab in , The writing is complete , But there are currently no mounted devices , Mount
[[email protected] ~]# df -h   |  grep  mypart

Four 、 Hard disk partition advanced                                

1.GPT Partition mode

GPT,GUID Partition Table
— Globally unique logo
— Break through fixed size 64 Partition table limit of bytes
— Maximum support 128 Primary partitions , The biggest support 18EB disk
parted Common partition instructions
     -help                     # View instruction help
     -mktable     msdos | gpt         # Create the specified schema partition table
     -mkpart       primary       File system type     start      end                                                                                           # Appoint size or percentage % As a starting point 、 End position
     -print            # View partition table
     -rm     Serial number      # Delete the specified partition
     -quit             # Exit the interactive environment

[[email protected] ~]# parted    /dev/vdd    
GNU Parted 3.1
Use /dev/vdd
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted)mktable gpt          # Specify partition mode                                              
(parted) mkpart                  # Divide the New Area                                                     
Partition name ?  []? one             # Write casually                                                 
File system type ?  [ext2]? ext4      # Write at will , No formatting
The starting point ? 0                                                                
The end point ? 5G                                                               
Warning : The resulting partition is not properly aligned for best performance.
Ignore /Ignore/ give up /Cancel?
Ignore       # Choose to ignore , Input i(tab) completion                                        
(parted)print                                      # View the partition table information                                                    
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name  sign
 1      17.4kB  5000MB  5000MB               one

(parted) unit GB                                   # Use GB As a unit                                                
(parted) print                                                          
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name  sign
 1      0.00GB  5.00GB  5.00GB               one

(parted) mkpart
Partition name ?  []? two
File system type ?  [ext2]? ext4
  The starting point ? 5G       # For the end of the previous partition
The end point ? 10G   
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name  sign
 1      0.00GB  5.00GB  5.00GB               one
 2      5.00GB  10.0GB  5.00GB               two

—— Swap space

Mode one : Use hard disk partition to make swap space

[[email protected] ~]# ls /dev/vdd2
/dev/vdd2
[[email protected] ~]# mkswap  /dev/vdd2     # Format swap file system
[[email protected] ~]# blkid     /dev/vdd2        # View file system types
[[email protected] ~]# swapon                        # View the member information of the swap space
[[email protected] ~]# swapon  /dev/vdd2      # Enable swap partition
[[email protected] ~]# swapon    
[[email protected] ~]# free -m                        # Check the swap space size
[[email protected] ~]# swapoff  /dev/vdd2      Disable the swap partition
[[email protected] ~]# swapon                
[[email protected] ~]# free -m               

The switch partition is enabled automatically after startup

原网站

版权声明
本文为[Zhushuaijie 1]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202181335086664.html