When purchasing cloud services, you usually bring a 40G system disk and then purchase a data disk yourself. If it is a Windows system, the purchased data disk will exist as a partition, such as D drive, E drive, etc., which can be directly Use, but it must be mounted in Linux for normal use.
Table of contents
3. Check the current disk partition status
Usage environment: centos 7.9
1. Mounting concept
Mounting refers to a process by which the operating system makes computer files and directories on a storage device (such as a hard disk, CD-ROM, or shared resource) accessible to users through the computer's file system.
In the Windows operating system, mounting usually refers to assigning a drive letter to a disk partition (including a virtualized disk partition).
In the Linux operating system, it refers to attaching a device (usually a storage device) to an existing directory. (This directory does not need to be empty, but the previous contents in this directory will not be available after mounting.)
The following demonstrates how to mount a disk under Linux
2. Check the disk status
You can view the currently mounted disk information through the df command.
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 0 3.8G 0% /dev/shm
tmpfs 3.8G 500K 3.8G 1% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/vda1 40G 2.4G 36G 7% /
tmpfs 768M 0 768M 0% /run/user/0
It can be seen from the above information that currently only the system disk is mounted.
3. Check the current disk partition status
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000bf3aa
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 83 Linux
Disk /dev/vdb: 268.4 GB, 268435456000 bytes, 524288000 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 /dev/vdc: 268.4 GB, 268435456000 bytes, 524288000 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
From the above information, we can see that there are three disks in the system: /dev/vda, /dev/vdb, and /dev/vdc, which are 42G, 268G, and 268G respectively. There is a gap between the size of the disks originally purchased.
4. Add new disk mount
From the previous step, we know the name of each disk. Now partition the hard disk ( if you are mounting an entire disk, you can omit this step ). The partitioning steps are as follows:
- fdisk /dev/vdb (/dev/vdb is the disk name queried in the previous step)
- Enter parameter m (you don’t need to enter it to display help)
- Input parameter n (new partition)
- Input parameter e (extended extended partition, p primary primary partition)
- Input parameter 1 (1-4 1 means only one area)
- Enter key to skip
- Enter key to skip (means all, you can also enter the cylinder number to complete the partition, the number cannot be greater than the end number of the disk)
- Enter parameter w (save)
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
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
Building a new DOS disklabel with disk identifier 0xbacfd979.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1): 1
First sector (2048-524287999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-524287999, default 524287999):
Using default value 524287999
Partition 1 of type Extended and of size 250 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Use the command lsblk to check the partition status:
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
vdb 253:16 0 250G 0 disk
└─vdb1 253:17 0 1K 0 part
vdc 253:32 0 250G 0 disk
It can be seen that vdb has been successfully partitioned, but vdc has not been partitioned yet.
5. Format the disk
Format the disk using mkfs.ext4 /dev/vdb:
[root@iZ2ze5x5mt3210wm46kjgwZ mnt]# mkfs.ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
16384000 inodes, 65536000 blocks
3276800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2214592512
2000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Use the command lsblk to check the partition situation: there are changes from the previous one (the reason has not been investigated yet)
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
vdb 253:16 0 250G 0 disk
vdc 253:32 0 250G 0 disk
6. Mount the disk
Before mounting, you need to create a mount point, which is a folder, and then use the mount command to mount the disk into this folder.
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# cd /mnt
[root@iZ2ze5x5mt3210wm46kjgwZ mnt]# ll
total 0
[root@iZ2ze5x5mt3210wm46kjgwZ mnt]# mkdir software
[root@iZ2ze5x5mt3210wm46kjgwZ mnt]# mount /dev/vdb /mnt/software
Check for success
[root@iZ2ze5x5mt3210wm46kjgwZ mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 0 3.8G 0% /dev/shm
tmpfs 3.8G 476K 3.8G 1% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/vda1 40G 2.0G 36G 6% /
tmpfs 768M 0 768M 0% /run/user/0
/dev/vdb 246G 61M 234G 1% /mnt/software
It can be seen from the results that the mount has been successful and the disk is /dev/vdb. After this step, it is only temporarily mounted. After restarting, the mount point will disappear. Now set the mount information to automatically mount at boot.
7. Automatic mount
There are two ways to automatically mount. One is to use a disk to mount, and the other is to use a UUID to mount.
1. Use the disk to hang on
Execute the command:
echo "/dev/vdb /mnt/software ext4 defaults 0 0" >> /etc/fstab
Then use shutdown -r now to restart, and check the mounting status after restarting
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 0 3.8G 0% /dev/shm
tmpfs 3.8G 496K 3.8G 1% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/vda1 40G 2.4G 36G 7% /
/dev/vdb 246G 61M 234G 1% /mnt/sfotware
tmpfs 768M 0 768M 0% /run/user/0
2. Use UUID to mount
Use vim to delete the mount information in /etc/fstab. There are three ways to view UUID:
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# blkid
/dev/vda1: UUID="10c0e7e5-557a-40c1-893c-1e2dcbac1526" TYPE="ext4"
/dev/vdb: UUID="6e26ed03-df7d-47e7-9324-8408341aeacb" TYPE="ext4"
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
vda
└─vda1 ext4 10c0e7e5-557a-40c1-893c-1e2dcbac1526 /
vdb ext4 6e26ed03-df7d-47e7-9324-8408341aeacb /mnt/software
vdc
[root@iZ2ze5x5mt3210wm46kjgwZ ~]# ll /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Aug 13 17:06 10c0e7e5-557a-40c1-893c-1e2dcbac1526 -> ../../vda1
lrwxrwxrwx 1 root root 9 Aug 13 17:10 6e26ed03-df7d-47e7-9324-8408341aeacb -> ../../vdb
Set up automount:
echo "UUID=6e26ed03-df7d-47e7-9324-8408341aeacb /mnt/software ext4 defaults 0 0" >> /etc/fstab
View the mount file:
Automatically mount the contents of /etc/fstab
mount –a
Restart the server and use the name df to confirm the successful mounting again.
8. Unmount the disk
# 临时卸载,重启机器之后又恢复到挂载状态
umount /dev/vdb
#永久卸载
vim /etc/fstab
#把添加的磁盘信息删除即可。重启机器查看是否卸载