virtualbox虚拟机添加虚拟磁盘disk的步骤

virtualbox虚拟机添加虚拟磁盘disk的步骤

1. 创建虚拟硬盘

为virtualbox虚拟机添加虚拟硬盘

  • 打开virtualbox-> 管理 -> 虚拟介质管理 -> 创建 ->
  • 确认虚拟文件位置和文件大小上限如500G,类型选VDI,动态分配 -> 创建;
  • 也可以选择向导模式

为VMware虚拟机添加虚拟磁盘

  • 打开虚拟机-> 虚拟机设置 -> 磁盘 -> add -> hard disk -> next -> next ->
  • create new disk -> 输入大小和选择保存到单一文件 -> 输入文件名 -> finish;

2. 挂载到linux系统

首先重启虚拟机系统

2.1 确认新增的虚拟磁盘设备文件

$ sudo fdisk -l
Disk /dev/sdf: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 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
Disk identifier: 0x00000000

Disk /dev/sdf doesn't contain a valid partition table

注意提示信息:Disk /dev/sdf doesn’t contain a valid partition table,

/dev/sdf就是我们刚新建而未设置分区的虚拟磁盘;

2.2 为新增磁盘配置分区

$ sudo fdisk /dev/sdf 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xc388f37d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m #输入m打印帮助信息
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   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 #选择n新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): #使用默认值p直接回车
Using default response p
Partition number (1-4, default 1): #使用默认值1直接回车
Using default value 1
First sector (2048-209715199, default 2048): #使用默认值2048直接回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): 
Using default value 209715199

Command (m for help): w #写入分区信息(保存)
The partition table has been altered!

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

2.3 格式化磁盘分区为ext4格式

首先查看新增磁盘的分区信息

$ sudo fdisk -l
Disk /dev/sdf: 107.4 GB, 107374182400 bytes
43 heads, 44 sectors/track, 110843 cylinders, total 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
Disk identifier: 0xc388f37d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdf1            2048   209715199   104856576   83  Linux

然后进行格式化

$ sudo mkfs.ext4 /dev/sdf1
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214144 blocks
1310707 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 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

2.4 挂载分区到文件系统

首先确认分区的UUID

$ sudo blkid /dev/sdf1
/dev/sdf1: LABEL="toolkits" UUID="3c0633c0-fc64-4252-adae-c124ebeb2962" TYPE="ext4"

然后将UUID写入到 /etc/fstab 文件

$ sudo vi /etc/fstab

添加以下内容

UUID=3c0633c0-fc64-4252-adae-c124ebeb2962 /mnt/dev-toolkits                auto    rw,suid,dev,exec,auto,nouser,async      0       0

如果已经为分区设置过LABEL,也可以使用LABEL挂载,如

LABEL=toolkits  /mnt/dev-toolkits                auto    rw,suid,dev,exec,auto,nouser,async      0       0

最后执行重新挂载所有文件系统命令

$ sudo mount -a
mount: mount point /mnt/dev-toolkits does not exist

报错了,提示挂载点目录不存在,所以创建挂载点目录后重试

$ sudo mkdir -p /mnt/dev-toolkits
$ sudo mount -a

执行df命令查看文件系统挂载情况

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       489G   14G  450G   3% /
/dev/sdf1        99G   60M   94G   1% /mnt/dev-toolkits

至此已经配置完毕,以后每次重启,该磁盘都会自动挂载到配置的目录

其他设置

如果要修改UUID号,可以使用以下命令

$ uuidgen
73cd2ce6-99ec-4be5-9289-1f3439ead8ff
$ sudo tune2fs -U 73cd2ce6-99ec-4be5-9289-1f3439ead8ff /dev/sdf1

为分区设置LABEL

如果要给分区设置LABEL,可以使用以下命令

$ sudo tune2fs -L toolkits /dev/sdf1

查看结果

$ sudo blkid /dev/sdf1
/dev/sdf1: LABEL="toolkits" UUID="3c0633c0-fc64-4252-adae-c124ebeb2962" TYPE="ext4"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值