Error message here!

Hide Error message here!

忘记密码?

Error message here!

请输入正确邮箱

Hide Error message here!

密码丢失?请输入您的电子邮件地址。您将收到一个重设密码链接。

Error message here!

返回登录

Close

Linux虚拟机怎么添加磁盘?

菜鹌鹑 2019-07-11 23:31:00 阅读数:57 评论数:0 点赞数:0 收藏数:0

一、VMware workstation菜单栏虚拟机设置添加硬盘下一步

 

二、SCSI下一步:

三、创建新虚拟磁盘下一步

四、选择自己需要的硬盘大小立即分配磁盘取消勾选将虚拟磁盘存储为单个文件下一步

 

五、完成

六、重启虚拟机后,使用lsblk命令查看磁盘情况

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               :       20G   disk 
├─sda1            :        1G   part /boot
└─sda2            :       19G   part 
  ├─centos-root :       17G   lvm  /
  └─centos-swap :        2G   lvm  [SWAP]
sdb 8:16   0    5G  0 disk 
sr0              :     1024M   rom  

发现已经成功添加新硬盘sdb。

七、使用fdisk创建新分区

[root@localhost ~]# 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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x03295b0a.

Command (m for help):

然后输入 p  ,回车:

Command (m for help): p

Disk /dev/sdb:  MB, 5368709120 bytes, 10485760 sectors
Units = sectors of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disk label type: dos
Disk identifier: 0x03295b0a

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): 

输入  n  回车:

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

输入  p  回车, 1  回车,回车,回车:

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

输入  p  ,回车:

Command (m for help): p

Disk /dev/sdb:  MB, 5368709120 bytes, 10485760 sectors
Units = sectors of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disk label type: dos
Disk identifier: 0x03295b0a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1                10485759     5241856     Linux

Command (m for help):

输入  w  ,回车,保存退出。至此,磁盘分区完成。

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

八、使用mkfs.ext4命令进行格式化

先查看分区表

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               :       20G   disk 
├─sda1            :        1G   part /boot
└─sda2            :       19G   part 
  ├─centos-root :       17G   lvm  /
  └─centos-swap :        2G   lvm  [SWAP]
sdb               :       5G   disk 
└─sdb1            :       5G   part 
sr0              :     1024M   rom 

发现新分区是sdb1(我只分了一个主分区,所以是sdb1。)然后我们对sdb1进行格式化

[root@localhost ~]# mkfs.ext4 /dev/sdb1 
mke2fs 1.42. (-Dec-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
327680 inodes, 1310464 blocks
 blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=1342177280
 block groups
 blocks per group,  fragments per group
 inodes per group
Superblock backups stored on blocks: 
    , , 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done

至此格式化完成。

九、挂载分区

我以挂载到根分区的data目录为例:

新建/data目录

[root@localhost /]# mkdir data

挂载分区到/data目录

[root@localhost /]# mount /dev/sdb1 /data

查看磁盘使用情况

[root@localhost /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        17G  .3G   16G   % /
devtmpfs                devtmpfs  .9G       .9G   % /dev
tmpfs                   tmpfs     .9G       .9G   % /dev/shm
tmpfs                   tmpfs     .9G   12M  .9G   % /run
tmpfs                   tmpfs     .9G       .9G   % /sys/fs/cgroup
/dev/sda1               xfs      1014M  148M  867M  % /boot
tmpfs                   tmpfs     378M       378M   % /run/user/
/dev/sdb1               ext4      .8G   20M  .6G   % /data

至此,虚拟机添加磁盘操作结束。

版权声明
本文为[菜鹌鹑]所创,转载请带上原文链接,感谢
https://www.cnblogs.com/quail2333/p/11173511.html