对VM挂载新加入的磁盘

在虚拟机配置中增加磁盘后,启动Linux,使用root登录。

首先查看未分区的磁盘,使用下面命令:

## 查看未使用的磁盘
fdisk -l

对VM挂载新加入的磁盘

磁盘/dev/sdb后面没有任何分区,是新挂载的磁盘

输入下面命令来开始对磁盘/dev/sdb进行分区

## 开始格式化磁盘 ##
fdisk /dev/sdb

有如下提示:

[root@localhost dev]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.). Changes will remain in memory only, until you decide to write them.
Be careful before using the write command. 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)

首选使用n来创建一个扩展分区,输入选项n:

Command (m for help): n
Partition type:
p primary ( primary, extended, free)
e extended
Select (default p):

选择创建扩展分区,输入选项e,然后选择扩展分区编号、起始位置和大小,我们选择整个磁盘只创建一个扩展分区:

Select (default p): e
Partition number (-, default ):
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value
Partition of type Extended and of size GiB is set

扩展分区创建好后,可以在此基础上进行创建逻辑分区,我们创建2个逻辑分区并分别设置为10G:

Command (m for help): n
Partition type:
p primary ( primary, extended, free)
l logical (numbered from )
Select (default p): l
Adding logical partition
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ): +10G
Partition of type Linux and of size GiB is set Command (m for help): n
Partition type:
p primary ( primary, extended, free)
l logical (numbered from )
Select (default p): l
Adding logical partition
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value
Partition of type Linux and of size GiB is set

最后使用选项p来查看分好的分区:

Command (m for help): p

Disk /dev/sdb: 21.5 GB,  bytes,  sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x40e44e64 Device Boot Start End Blocks Id System
/dev/sdb1 Extended
/dev/sdb5 Linux
/dev/sdb6 Linux

为磁盘分配好分区后,需要使用选项w来进行保存:

Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

在执行partprobe命令来重新读取分区信息,如果有警告可以忽略。

## 重新读取分区信息 ##
partprobe

然后需要对磁盘进行格式化,使用mkfs将磁盘格式化为ext4格式(注意扩展分区不能进行格式化)

mkfs -t ext4 /dev/sdb5

mke2fs 1.42. (-Dec-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Allocating group tables: done
Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done

然后我们创建两个目录来挂载这两个逻辑分区:

## 然后创建目录 ##
mkdir /disk5 /disk6 ## 使用mount命令来挂载目录 ##
mount /dev/sdb5 /disk5
mount /dev/sdb6 /disk6

最后使用mount命令来查看挂载情况

[root@localhost dev]# ## 使用mount命令来查看挂载情况 ##
[root@localhost dev]# mount | grep "sdb"
/dev/sdb5 on /disk5 type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb6 on /disk6 type ext4 (rw,relatime,seclabel,data=ordered)
上一篇:Objective-c:NSFileHandle类,创建流对象,对文件进行写入、读取的操作


下一篇:Jenkin+TestNG进行自动化测试执行