Basic Concepts Before operation, you must first understand some basic concepts disk In the Linux system, all devices are stored in the form of files. Devices are generally stored in the /dev directory, in the form of sda, sda1, sda2…, sdb, sdb1…, hda, hdb. Nowadays, most devices are named "sd", while very old hard drives were named "ha". sda: The first hard disk. If the disk is partitioned, there will be sda1 (the first partition), sda2, and so on. sdb: The second hard disk, after partitioning, there are sdb1, sdb2, etc. Partition The purpose of partitioning is to facilitate management. For example, in Windows systems we usually divide them into C drive, D drive, E drive, etc. Linux can only create 4 primary partitions. If you need to create more partitions, you must create logical partitions, and the logical partitions need to occupy one primary partition. File System The file system in Linux is the partition type. In Windows, there are NTEF, FAT32, etc. In Linux, there are Ext2, Ext3, Ext4, Linux swap, proc, sysfs, tmpfs, etc. You can view the currently mounted file system through the mount name. format After creating the partition, one step is to format the partition. In fact, it is the same in Windows system. After creating a partition, you also need to format the partition. It can only be used after it is formatted into a specific file type. Mount In Windows, the partition can be used after it is formatted, but in Linux system, the partition must be mounted to a specific path. Common commands
Mount the new hard drive The basic idea of mounting a new hard disk is: create partitions, create file systems, and mount. 1. Check the new hard drive First, check the hard disk status: fdisk -l in: If there is a message like: Disk /dev/sdc doesn't contain a valid partition table under the disk; or there is no message like: sdb1 sdb2 under the disk, it means that the disk is not mounted. Here we assume that the hard disk name is /dev/sdb 2. Create partitions dfisk /dev/sdb According to the prompts, enter "n", "p", "1" in sequence, press Enter twice, and "wq" This means creating a new primary partition (1) the size of the entire sdb disk, and then writing to it. Note: For simplicity, the above operation only creates one primary partition. In fact, a disk can have up to four primary partitions (including one extended partition). 1-4 are all primary partitions. We can also use a partition as an extended partition (the system displayed by df -lh is Extended). At this point the disk has been partitioned, but there is no file system yet, and the disk is still unusable. 3. Write to the system mkfs.ext4 /dev/sdb This command will format the disk and write the file system 4. Mount For example, mount it under /data mkdir /data # If this step exists, skip mount /dev/sdb /data 5. Set up automatic mounting at startup The above is just a temporary mount, and you need to set it to automatically mount when you boot. vim /etc/fstab # Then add a line at the end of the content (note that the file type must correspond): /dev/sdb /data ext4 defaults 0 0 Scaling About mounting to an existing directory If the directory you want to mount is not empty, then after the file system is mounted, the contents of the original directory will temporarily disappear. It is not overwritten, but temporarily hidden. After the new partition is unmounted, the original contents of the original directory will appear again. If you want to permanently mount an existing directory, you can mount it to a temporary directory after creating a file system on the new hard disk, then copy the directory to be expanded to this temporary directory, then delete the directory to be expanded, unmount the temporary mount point, and remount it to the directory to be expanded. Example: # For example, to expand /var # After creating the file system, create a temporary mount point storage mkdir /storage # Mount /dev/sdb1 to /storage mount /dev/sdb1 /storage # Copy all contents under /var to the new hard disk cp -pdr /var /storage # Or execute in the /var directory: find . -depth -print | cpio - pldvm /temp # Delete the contents of the current /var directory rm -rf /var/* # Remount the hard disk to the /var directory umount /dev/sdb1 mount /dev/sdb1 /var # If the disk is busy, use fuser to find out the program that is using the disk and terminate it; fuser -m -v /var fuser -m -v -i -k /var The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: VMWare Linux MySQL 5.7.13 installation and configuration tutorial
>>: How to use less in WeChat applet (optimal method)
Publish Over SSH Plugin Usage Before using Publis...
There is no need to say much about the difference...
MySQL database storage location: 1. If MySQL uses...
This article mainly introduces the detailed proce...
Docker Compose Docker Compose divides the managed...
Recently, an online security scan found a vulnera...
Xiaobai records the installation of vmtools: 1. S...
In the previous article, we learned about the pas...
In higher versions of Tomcat, the default mode is...
1. Create a shell script vim backupdb.sh Create t...
Find the problem I wrote a simple demo before, bu...
Table of contents 1. Database Engine 1.1 View dat...
use Flexible boxes play a vital role in front-end...
1. What is Docker? Everyone knows about virtual m...
The installation of Harbor is pretty simple, but ...