分类
Debian 10 服务器配置手册
Debian 10 服务器配置手册>0103 挂载数据盘
0103 挂载数据盘
创建于 299天前 更新于 299天前

一、查看所有磁盘

使用命令行进行查看:

# fdisk -l

得到以下结果:

Disk /dev/vda: 50 GiB, 53687091200 bytes, 104857600 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

Disklabel type: dos

Disk identifier: 0x18d59027

 

Device Boot Start End Sectors Size Id Type

/dev/vda1 * 2048 104857566 104855519 50G 83 Linux

 

 

Disk /dev/vdb: 100 GiB, 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

二、初始化数据盘

从前段结果中可以看到/dev/vdb这块盘尚未初始化。

2.1 选择数据盘

使用命令选择需要操作的数据盘:

# fdisk /dev/vdb

2.2 创建分区

安装以下顺序操作,将数据盘创建为一个独立分区:

Command (m for help): n

Partition type

p primary (0 primary, 0 extended, 4 free)

e extended (container for logical partitions)

Select (default p):

 

Using default response p.

Partition number (1-4, default 1):

First sector (2048-209715199, default 2048):

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199):

 

Created a new partition 1 of type 'Linux' and of size 100 GiB.

2.3 保存分区信息

使用w命令,将之前的分区操作进行保存:

Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

2.4 查看新建分区信息

使用命令行进行查看:

# fdisk -l

得到以下结果:

Disk /dev/vda: 50 GiB, 53687091200 bytes, 104857600 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

Disklabel type: dos

Disk identifier: 0x18d59027

 

Device Boot Start End Sectors Size Id Type

/dev/vda1 * 2048 104857566 104855519 50G 83 Linux

 

 

Disk /dev/vdb: 100 GiB, 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

Disklabel type: dos

Disk identifier: 0x6588907d

 

Device Boot Start End Sectors Size Id Type

/dev/vdb1 2048 209715199 209713152 100G 83 Linux

2.5 格式化新建分区

使用命令将分区格式化为ext4格式:

# mkfs.ext4 /dev/vdb1

得到以下结果:

mke2fs 1.44.5 (15-Dec-2018)

Creating filesystem with 26214144 4k blocks and 6553600 inodes

Filesystem UUID: a1a90f19-3485-4a02-91ef-0e0a07c44609

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 (131072 blocks): done

Writing superblocks and filesystem accounting information: done

三、挂载数据盘

3.1 创建数据目录

使用命令创建目录:

# mkdir /data

3.2 临时挂载分区

使用命令挂载分区:

# mount /dev/vdb1 /data

3.3 开机自动挂载分区

打开编辑配置文件:

# nano /etc/fstab

在文件末尾加入下列内容:

/dev/vdb1 /data ext4 defaults 0 1

使用Ctrl+O进行保存,使用Ctrl+X退出编辑。