1 Operating Environment
CentOS7 purchased by Ali Cloud
2 Check the mounting information
$ df -lh
Copy the code
For example, the new data disk /dev/vdb is not mounted
Filesystem Size Used Avail Use% Mounted on /dev/vda1 99G 27G 67G 29% / devtmpfs 909M 0 909M 0% /dev tmpfs 920M 0 920M 0% /dev/shm tmpfs 920M 484K 919M 1% /run tmpfs 920M 0 920M 0% /sys/fs/cgroup tmpfs 184M 0 184M 0% /run/user/0Copy the code
3 View all hard drives
$ fdisk -l
Copy the code
Displays hard drive information
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 209713151 104855552 83 Linux
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Copy the code
Or just look at a single hard drive
$ fdisk -l /dev/vdb
Copy the code
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Copy the code
/dev/vda1 partition /dev/vda1 partition /dev/vdb partition /dev/vda1 partition /dev/vdb partition
4 Creating a Partition
Create a partition for disk /dev/vdb
$ fdisk /dev/vdb
Copy the code
Enter m to view help. The following options are available
Command action d delete a partition n add a new partition p print the partition table q quit Without saving changes w Write table to disk and exitCopy the code
Now let’s create a 50GB primary partition, using the following command:
N (create partition) -> p (create primary partition) -> 1 (partition needs 1, generate “/dev/vdb1” partition) -> Enter (use default value) -> +50G (partition size, need to make sure there is enough free space)
Partition 2 is generated for all remaining space
N (create partition) -> p (create primary partition) -> 2 (partition requires 2, generate “/dev/vdb2” partition) -> Enter (use default value) -> Enter (use default value) ‘
Finally, press the w command to save and exit
View disks that have been partitioned
$ fdisk -l /dev/vdb
Copy the code
You can see that partitions /dev/vdb1 and /dev/vdb2 already exist, as shown below
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x22c9b721
Device Boot Start End Blocks Id System
/dev/vdb1 2048 104859647 52428800 83 Linux
/dev/vdb2 104859648 209715199 52427776 83 Linux
Copy the code
5 Format the new partition
$ mkfs.ext4 /dev/vdb1
$ mkfs.ext4 /dev/vdb2
Copy the code
An error message will appear if the mount is not formatted
mount: /dev/vdb1 is write-protected, mounting read-only
mount: unknown filesystem type '(null)
Copy the code
6 Mount disks
Add directories and mount partitions
$ mkdir -p /mnt/d/ /mnt/e
$ mount /dev/vdb1 /mnt/d
$ mount /dev/vdb2 /mnt/e
Copy the code
7 Cancel mounting
You can uninstall the partition if you don’t want to use it
$ umount /dev/vdb1
Copy the code
8 Enable automatic mounting upon startup
View the DISK UUID
$ blkid
Copy the code
According to the following
/dev/vda1: UUID="ac95c595-4813-480e-992b-85b1347842e8" TYPE="ext4"
/dev/vdb1: UUID="7f9b97e9-fae1-47ca-bc19-acdfb027368a" TYPE="ext4"
Copy the code
To mount /dev/vdb1 to/MNT /d, modify the /etc/fstab configuration file, and add the following line at the end
UUID=7f9b97e9-fae1-47ca-bc19-acdfb027368a /mnt/d ext4 defaults 0 0
Copy the code
Parameter Description:
- UUID= 7f9b97e9-FAe1-47CA-bc19-ACDFb027368a: indicates the UUID of the disk partition to be mounted
- / MNT /d: indicates the mount directory
- Ext4: The partition format is ext4
- Defaults: Mount parameters (read-only, read/write, quota enabled, etc.). Input defaults include parameters (rw, dev, exec, auto, nouser, async).
- 0: whether to record when dump is used. 0 indicates that no record is required, and 1 indicates that no record is required
- 0: indicates the check sequence during startup. 0 indicates no check. 1 indicates a boot system file, and 2 indicates another file system