阿里云 Linux下磁盘挂载

2019年2月25日

具体步骤如下:
1、查看是否已经分配

[root@iZ2ze1tefvghtbgkdur3xfZ /]# fdisk -l

  1. Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
  2. Units = sectors of 1 * 512 = 512 bytes
  3. Sector size (logical/physical): 512 bytes / 512 bytes
  4. I/O size (minimum/optimal): 512 bytes / 512 bytes
  5. Disk label type: dos
  6. Disk identifier: 0x0009e68a
  7. Device Boot Start End Blocks Id System
  8. /dev/vda1 * 2048 83884031 41940992 83 Linux
  9. Disk /dev/vdb: 64.4 GB, 64424509440 bytes, 125829120 sectors
  10. Units = sectors of 1 * 512 = 512 bytes
  11. Sector size (logical/physical): 512 bytes / 512 bytes
  12. I/O size (minimum/optimal): 512 bytes / 512 bytes

2、发现有磁盘,路径为/dev/vdb。然后使用fdisk命令进行建立分区

[root@iZ2ze1tefvghtbgkdur3xfZ /]#fdisk /dev/vdb

  1. fdisk命令如下:
  2. 命令(输入 m 获取帮助):m
  3. 命令操作
  4. a toggle a bootable flag
  5. b edit bsd disklabel
  6. c toggle the dos compatibility flag
  7. d delete a partition
  8. g create a new empty GPT partition table
  9. G create an IRIX (SGI) partition table
  10. l list known partition types
  11. m print this menu
  12. n add a new partition
  13. o create a new empty DOS partition table
  14. p print the partition table
  15. q quit without saving changes
  16. s create a new empty Sun disklabel
  17. t change a partition's system id
  18. u change display/entry units
  19. v verify the partition table
  20. w write table to disk and exit
  21. x extra functionality (experts only)

3、然后先新建分区(我这里因为要存储大数据库文件 所以逻辑全部是一个分区)

  1. 命令(输入 m 获取帮助):n
  2. Partition type:
  3. p primary (0 primary, 0 extended, 4 free)
  4. e extended
  5. Select (default p):
  6. Using default response p
  7. 分区号 (1-4,默认 1):
  8. 起始 扇区 (2048-3221225471,默认为 2048):
  9. 将使用默认值 2048
  10. Last 扇区, +扇区 or +size{K,M,G} (2048-3221225471,默认为 3221225471):
  11. 将使用默认值 3221225471
  12. 分区 1 已设置为 Linux 类型,大小设为 1.5 TiB

4、最后保存分区

  1. 命令(输入 m 获取帮助):w
  2. The partition table has been altered!
  3. The partition table has been altered.
  4. Calling ioctl() to re-read partition table.
  5. Syncing disks.

5、使用fdisk -l命令查看,已经有分区了

  1. 磁盘 /dev/sdb:1649.3 GB, 1649267441664 字节,3221225472 个扇区
  2. Units = 扇区 of 1 * 512 = 512 bytes
  3. 扇区大小(逻辑/物理):512 字节 / 512 字节
  4. I/O 大小(最小/最佳):512 字节 / 512 字节
  5. 磁盘标签类型:dos
  6. 磁盘标识符:0xe0bc0098
  7. 设备 Boot Start End Blocks Id System
  8. /dev/sdb1 2048 3221225471 1610611712 83 Linux

6、建好分区后要格式化分区,建立文件系统

  1. [root@localhost home]# mkfs.ext4 /dev/vdb
  2. meta-data=/dev/sdb1 isize=256 agcount=4, agsize=100663232 blks
  3. = sectsz=512 attr=2, projid32bit=1
  4. = crc=0 finobt=0
  5. data = bsize=4096 blocks=402652928, imaxpct=5
  6. = sunit=0 swidth=0 blks
  7. naming =version 2 bsize=4096 ascii-ci=0 ftype=0
  8. log =internal log bsize=4096 blocks=196607, version=2
  9. = sectsz=512 sunit=0 blks, lazy-count=1
  10. realtime =none extsz=4096 blocks=0, rtextents=0

7、挂在磁盘

  1. [root@localhost ~]# mkdir /mnt
  2. [root@localhost ~]# mount /dev/vdb /mnt

还有一种方式 就是将/mnt 下的某个文件夹 挂在到制定的位置 mount --bing

  1. [root@localhost ~]# mkdir /mnt
  2. [root@localhost ~]# mkdir /mnt/media
  3. [root@localhost ~]# mount --bind /mnt/media/ /home/disk/media/

8、查看一下挂载是否成功了

  1. [root@localhost home]# df -h
  2. 文件系统 类型 容量 已用 可用 已用% 挂载点
  3. Filesystem Size Used Avail Use% Mounted on
  4. udev 10M 0 10M 0% /dev
  5. tmpfs 791M 780K 790M 1% /run
  6. /dev/vda1 40G 26G 12G 69% /
  7. tmpfs 2.0G 0 2.0G 0% /dev/shm
  8. tmpfs 5.0M 0 5.0M 0% /run/lock
  9. tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
  10. /dev/vdb 20G 44M 19G 1% /mnt
  11. /dev/vdb 20G 44M 19G 1% /home/disk/media

9、设置系统启动后自动挂载,否则重启系统就掉了
修改一下系统配置加入下列行到/etc/fstab

  1. UUID=c44f5977-ba8e-49a5-b7c1-bbdabdb12933 /mnt ext4 defaults,barrier=0 1 1

UUID 查看

  1. blkid
  2. [root@HK-WEB ~]# blkid
  3. /dev/vda1: LABEL="/" UUID="91971138-152b-43b1-9d45-1b01198c581b" TYPE="ext4" PARTUUID="6e808324-01"
  4. /dev/vdb: UUID="c44f5977-ba8e-49a5-b7c1-bbdabdb12933" TYPE="ext4"

10 、 卸载挂载磁盘

  1. umount /home/disk

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注