centos7 挂载数据盘

  1. 使用远程连接工具,输入用户名 root 和密码登录到实例。

  2. 运行 fdisk -l 命令查看数据盘。注意:在没有分区和格式化数据盘之前,使用 df -h 命令是无法看到数据盘的。在下面的示例中,有一个 5 GB 的数据盘需要挂载。 
    如果执行了 fdisk -l 命令后,没有发现 /dev/xvdb,则表示您的实例没有数据盘,因此无需挂载。可以忽略这一章。

     [root@xxxx ~]# fdisk -l
    
     Disk /dev/xvda: 42.9 GB, 42949672960 bytes
     255 heads, 63 sectors/track, 5221 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: 0x00078f9c
    
     Device Boot      Start         End      Blocks   Id  System
     /dev/xvda1   *           1        5222    41940992   83  Linux
    
     Disk /dev/xvdb: 5368 MB, 5368709120 bytes
     255 heads, 63 sectors/track, 652 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
    
  3. 执行下列命令,对数据盘进行分区。
     fdisk /dev/xvdb
    
  4. 根据提示,依次输入 np1,两次回车,wq,分区就开始了。

     [root@xxx ~]# fdisk /dev/xvdb
     Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab            el
     Building a new DOS disklabel with disk identifier 0x33eb5059.
     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): n
     Command action
        e   extended
        p   primary partition (1-4)
     p
     Partition number (1-4): 1
     First cylinder (1-652, default 1): 
     Using default value 1
     Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):
     Using default value 652
    
     Command (m for help): wq
     The partition table has been altered!
    
     Calling ioctl() to re-read partition table.
     Syncing disks.
    
  5. 执行 fdisk -l 命令,查看新的分区。新分区 xvdb1 已经创建好。如下面示例中的/dev/xvdb1。

     [root@xxx ~]# fdisk -l
    
     Disk /dev/xvda: 42.9 GB, 42949672960 bytes
     255 heads, 63 sectors/track, 5221 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: 0x00078f9c
    
     Device Boot      Start         End      Blocks   Id  System
     /dev/xvda1   *           1        5222    41940992   83  Linux
    
     Disk /dev/xvdb: 5368 MB, 5368709120 bytes
     255 heads, 63 sectors/track, 652 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: 0x33eb5059
    
     Device Boot      Start         End      Blocks   Id  System
     /dev/xvdb1               1         652     5237158+  83  Linux
    
  6. 执行下列命令,对新分区进行格式化。格式化所需时间取决于数据盘大小。您也可自主决定选用其他文件格式,如 ext14 等。

     mkfs.ext3 /dev/xvdb1
    
  7. 执行下列命令写入新分区信息。

     echo '/dev/xvdb1 /mnt ext3 defaults 0 0'>> /etc/fstab
    


    完成后,可以使用 cat /etc/fstab 命令查看。 
    注意: Ubuntu 12.04 不支持 barrier,所以对该系统正确的命令是:

     echo '/dev/xvdb1 /mnt ext3 barrier=0 0 0'>>/etc/fstab
    


    如果需要把数据盘单独挂载到某个文件夹,比如单独用来存放网页,可以修改以上命令中的 /mnt 部分。

  8. 执行 mount /dev/xvdb1 /mnt 挂载新分区,然后执行 df -h 查看分区。如果出现数据盘信息,说明挂载成功,可以使用新分区了。

     [root@xxx ~]# mount /dev/xvdb1 /mnt
     [root@xxx ~]# df -h
     Filesystem      Size  Used Avail Use% Mounted on
     /dev/xvda1       40G  1.5G   36G   4% /
     tmpfs           498M     0  498M   0% /dev/shm
     /dev/xvdb1      5.0G  139M  4.6G   3% /mnt
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值