linux的磁盘挂载

故事扮演 提交于 2020-03-24 02:30:06

创建虚拟硬盘

        1、关闭VM中正在运行的虚拟系统;

        2、EDIT Virtual Machine Settings;(右键单击图标,点击settings)

        3、在Hardware页点“Add...”->Add a hard disk->Create a new virtual disk->SCSI(recommended)->分配空间大小->OK;(只是一直点next就行了,至于你要添加的大小在中间设 置)

        4、可以看见Hardware中出现了一块新的硬盘Hard Disk 2。

 

开始添加

[root@localhost ~]# fdisk -l  //用来检查系统中有几块硬盘

 

Disk /dev/sda: 21.5 GB, 21474836480 bytes  //这是已经分区的磁盘

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00044451

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26         157     1048576   82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3             157        2611    19717120   83  Linux

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes  //这是未分区的磁盘

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

 

Disk /dev/sdb doesn't contain a valid partition table//这句话表明磁盘/dev/sdb是无效的,是还未分区的

 

[root@localhost ~]# fdisk /dev/sdb //开始对磁盘/dev/sdb分区,这里的/dev/sdb即是上面的
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x87a42715.
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)
 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
 
Command (m for help): m  //显示菜单
Command action
   a   toggle a bootable flag  //切换一个可启动的标志
   b   edit bsd disklabel  //编辑BSD的disklabel
   c   toggle the dos compatibility flag //切换DOS兼容标志
   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  //创建一个新的空DOS分区表
   p   print the partition table  //打印分区表
   q   quit without saving changes  //退出不保存更改的情况下
   s   create a new empty Sun disklabel  //创建一个新的空太阳的disklabel
   t   change a partition's system id //改变一个分区的系统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): p //打印出目前该硬盘下的分区列表
 
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x87a42715
 
   Device Boot      Start         End      Blocks   Id  System
 
Command (m for help): n //开始创立新的分区
Command action
   e   extended  //扩展
   p   primary partition (1-4) //主分区(1-4)
p
Partition number (1-4): 1  //分区号
First cylinder (1-2610, default 1):  //第一柱面这里使用
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):  //添加的磁盘的大小,使用默认值的话即为把全部空间加入进去
Using default value 2610
 
Command (m for help): p  //查看分区
 
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x87a42715
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux
 
Command (m for help): w  //保存退出
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks. //同步磁盘的意思
[root@localhost ~]# mkfs.ext3 /dev/sdb1 //对/dev/sdb1进行格式化,格式化为ext3
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=0
160 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
 
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
 
This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.[root@localhost ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=0
160 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
 
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
 
This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# fdisk -l //检查是否格式化好了
 
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00044451
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         157     1048576   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             157        2611    19717120   83  Linux
 
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x87a42715
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux
[root@localhost ~]# mkdir /data1 //建立挂载目录/data1
[root@localhost ~]# mount /dev/sdb1 /data1 //将sdb1挂载到data1 
[root@localhost ~]# df -h  //查看是否挂载成功
文件系统              容量  已用  可用 已用%% 挂载点
/dev/sda3              19G  955M   17G   6% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/sda1             194M   22M  163M  12% /boot
/dev/sdb1              20G  173M   19G   1% /data1 //这是刚填的磁盘
在/目录下多了data1的目录
 
 
总的来说添加磁盘分为以下几步:
     1.创建虚拟硬盘

          1)右键单击虚拟机图标,点击settings

      2在 Hardware页点“Add...”->Add a hard disk->Create a new virtual disk->SCSI(recommended)->分配空间大小->OK;(只是一直点next就行了,至于你要添加的大小在中间设 置)

      3)可以看见Hardware中出现了一块新的硬盘,点击OK就好了

2.对虚拟硬盘进行分区和格式化(在实体机中应该只要把硬盘插上去,在进行第二步就行了)

    检查系统中有几块硬盘   [root@localhost ~]# fdisk -l 

      磁盘/dev/sdb分区       [root@localhost ~]# fdisk /dev/sdb 

              创立新的分区                             Command (m for help): n               
           保存退出                               Command (m for help): w
           dev/sdb1格式化为ext3    [root@localhost ~]# mkfs.ext3 /dev/sdb1
           检查是否格式化好了       [root@localhost ~]# fdisk -l      
           建立挂载目录/data1        [root@localhost ~]# mkdir /data1      
           将sdb1挂载到data1        [root@localhost ~]# mount /dev/sdb1 /data1  

           查看是否挂载成功          [root@localhost ~]# df -h           

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!