1. 使用lsblk命令查看新加入的磁盘信息
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 203.6M 0 rom
vda 253:0 0 50G 0 disk
└─vda1 253:1 0 50G 0 part /
vdb 253:16 0 500G 0 disk
└─vdb1 253:17 0 500G 0 part /mnt/dataA
vdc 253:32 0 500G 0 disk
vdd 253:48 0 500G 0 disk
2. 使用fdisk或者cfdisk分区新磁盘,并将分区标记为Linux文件系统类型(83)
sudo 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 0xb8ccdd97.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1048575999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999):
Using default value 1048575999
Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L
Hex code (type L to list all codes): 83
Changed type of partition 'Linux' to 'Linux'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3. 格式化新分区,使用mkfs命令
$ sudo mkfs -t ext4 /dev/vdb1
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
32768000 inodes, 131071744 blocks
6553587 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2279604224
4000 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, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
4. 创建挂载目录,使用mkdir命令
$ sudo mkdir /mnt/dataA
5. 挂载分区,使用mount命令
$ sudo mount /dev/vdb1 /mnt/dataA
6. 验证挂载是否成功,使用df -h命令查看所有文件系统的储存器使用情况:
$ sudo df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 32K 3.8G 1% /dev/shm
tmpfs 3.8G 592K 3.8G 1% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/vda1 50G 6.0G 41G 13% /
tmpfs 773M 0 773M 0% /run/user/0
/dev/vdb1 493G 73M 467G 1% /mnt/dataA
/dev/vdc1 493G 73M 467G 1% /mnt/dataB
从上述结果可以看出,新分区已经被成功挂载到/mnt/data目录下。
7. 添加自动挂载,编辑/etc/fstab文件,添加以下内容:
$ sudo su
$ echo '/dev/vdb1 /mnt/dataA ext4 defaults 0 2' >> /etc/fstab
挂载磁盘是Linux系统中一个基本的操作,它可以帮助我们扩展存储空间,管理数据文件,备份和存储重要文件等。在挂载磁盘之前,我们需要先对磁盘进行分区,并且在分区上创建文件系统。然后,我们需要使用mount命令将设备挂载到指定的目录下,并在必要时使用/etc/fstab文件配置开机自动挂载。最后,在卸载磁盘之前,需要先检查是否有进程在使用磁盘,并终止相应的进程。