Storage Structure and Disk Partitioning
1. Everything starts with "/"
In a Linux system, everything is a file. The file should then be structured in some way. Files form a tree structure through the system hierarchy standard. And files and directories are strictly case-sensitive. One wrong letter means two different files. All file systems start from the root directory.
A brief list of Linux common directories and related content:
/boot: files required for booting - kernel, boot menu and required configuration files, etc.
/dev: Store devices and interfaces in the form of files.
/etc: configuration files
/home, /root: common user home directory and root user home directory
/media: The directory used to mount device files.
/opt: third-party software
/srv: Data file directory for network services
/tmp: temporary files
/proc: virtual file system
/var: Changing files, logs, etc.
Absolute path : Starting from the root directory, always find the current file
Relative path : from the current directory to the file you are looking for
2. File system:
We treat the disk as an empty house, and the files to be installed as boxes. The file system is how these boxes fit into this empty house. Therefore, before we use the disk, we must format it first, that is to say: first determine which strategy the box uses to load the empty house. Some strategies are relatively simple, but they run slowly and find them slowly. Some strategies do not waste space, and lookup speed is also very fast.
Common file systems:
ext3,ext4,xfs,ntfs,dosfs,
3. Disk
The hard disk sd is commonly used. Generally, the sda, sdb, etc. we see are the order that the computer first recognizes. The number behind sdb1 and sdb2 is the partition of the disk. For a whole disk, we generally divide it into three primary partitions and one extended partition. The extended partition stores pointers to another partition. Therefore, we can create multiple logical partitions in the extended partition.
The fdisk command to manage hard disk devices. Manage disk partitions.
The method of use is fdisk disk
fdisk sdb: perform disk management on the second hard disk recognized by the computer
then m print directory
p can print the current disk status
n Create a new partition
p is the main partition (the default is also the main partition)
starting point
Set the size, for example +2G
w to save and exit (q is to exit without saving.)
Sometimes the result responds slowly, we can refresh the partprobe
4. Formatting
mkfs. Follow the options you want to format here. We use xfs
mkfs.xfs /dev/sdb1 : stands for 1 partition of sdb formatted with xfs format.
5. Mount
mount
The mount command is used to mount the file system, the format is: mount file system mount directory.
The file system is your disk, and the mount directory is a directory you create through which you can view the disk.
For example, your disk sdb1 can be mounted on /FS.
mount /dev/sdb1 /FS: Mount the 1 partition of sdb to /FS. At this time, you can operate and store the 1 partition of sdb by accessing FS.
umount
Unmount, umount /dev/sdb1 or umount /FS
Both methods are fine.
Tip: After restarting, the mounted directory will be invalid.
We can write the mount information to /etc/fstab, so that it will be automatically loaded even after restarting.
mount -a will automatically detect the mount information in /etc/fstab and implement it.
du command
Use the du command to view the space occupied by the file
-s total size
-h human view
you -sh /FS
6. Swap partition
Swap partition, if the current physical memory of the computer system is insufficient, you can use the swap partition method to put the temporarily unused memory in the swap partition. We can mount the size of the swap partition by ourselves.
Create a disk partition (same as above)
When formatting, remember to use the swap format
mkswap /dev/sdb2
Mount the swap partition
swapon /dev/sdb2
free -h View current memory