阿里云centos7 新购买的磁盘挂载

系统阿里云服务器 centos7 ,新购买了1块100G磁盘,还需要手动挂载才能正常使用

  • 查看磁盘挂载情况: fdisk -l
    阿里云centos7 新购买的磁盘挂载_第1张图片
    有一个 100G 的未使用磁盘 /dev/vdb

  • 分区: fdisk /dev/vdb (注意,我这里是vdb ,读者可能不一样,需要注意自己需要分区的盘名,读者的可能是vdbc或其他的,下面操作过程中也要注意这点)

    注: 如果不熟悉磁盘操作,建议照着下面提示做。
    阿里云centos7 新购买的磁盘挂载_第2张图片
    磁盘分区完得到 /dev/vdb1 ,下面挂载的时候会用到。 注意:我这里是vdb1 读者注意自己分区后的磁盘名

[root@server-logic-yrlos admin]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x22092a9d.
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-208050, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-208050, default 208050): 
Using default value 208050

Command (m for help): p

Disk /dev/vdb: 107.4 GB, 107374182400 bytes
16 heads, 63 sectors/track, 208050 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x22092a9d

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1      208050   104857168+  83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@server-logic-yrlos admin]# 
  • 格式化: mkfs -t ext3 -c /dev/vdb1 (注意:我这里是/dev/vdb1,读者根据自己实际磁盘更改)
    如果不格式化下面mount 会报错: mount: you must specify the filesystem type
    阿里云centos7 新购买的磁盘挂载_第3张图片

  • 挂载: mount /dev/vdb1 /opt (注意,这里 磁盘/dev/vdb1 和 挂载目录/opt ,读者需要根据自己需求更改,还有一个特别需要注意的就是要挂载的目录,如果要挂载的目录存在且有内容,需要考虑内容是否都有用,是否要事先转移,又或者重新选择一个别的空的目录挂载,不注意这个的话可能会造成线上产品出问题的!)
    在这里插入图片描述
    挂载后 df 命令查看是否挂载成功
    阿里云centos7 新购买的磁盘挂载_第4张图片

  • 配置系统启动自动挂载
    vi /etc/fstab
    最后一行添加
    /dev/vdb1 /opt ext3 defaults 1 2

    注意:/dev/vdb1 上面分区后格式化的磁盘,/opt 是我这里要挂载的目录,读者需要根据自己实际情况更改!
    配置说明:

/dev/sdb1 指分区
/opt 要挂载的目录
ext3 分区格式
defaults 挂载参数rw、dev、exec、auto、nouser、async
1 使用dump要记录 
2 是开机时检查的顺序,是boot系统文件就为1,其他文件系统都为2,如不要检查就为0

你可能感兴趣的:(linux)