最近公司买了一台阿里云服务器,附加三块磁盘用于存储 mongodb、mariadb以 及其他数据,本文主要讲述我是如何格式化并挂载这三块磁盘的,涉及公司业务,本文跟我实际的操作略有不同,分区过程是完整的记录,修改 fstab 表则使用了不同的目录,这点无伤大雅哈。
挂载 阿里云 数据盘 过程 - linux 命令行分区
1、云盘买后应该先挂载到主机,我这边的主机是已经挂载了,可能是购买的人员已经处理好了,至于如何挂载到云主机,请自行百度哈。如果是在自己电脑学习分区,请忽略。
2、使用 fdisk -l 查看磁盘列表,你看到的可能如下:
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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 Disklabel type: dos Disk identifier: 0xb2ac676a Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 83886046 83883999 40G 83 Linux Disk /dev/vdb: 100 GiB, 107374182400 bytes, 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 /dev/vdc: 40 GiB, 42949672960 bytes, 83886080 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 /dev/vdd: 40 GiB, 42949672960 bytes, 83886080 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
这里,vda 明显已经分区了,而 vdb、vdc、vdd 没有分区,如果你只看到了 vda 说明云盘没有挂载成功哦,挂载成功这里必然会有多个磁盘哈。是否分区你需要看是否有 vdb1 vdc1 等。
3、输入 fdisk /dev/vdb 并回车,你可能看到:
Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier xxxxx. Command (m for help):
这里 xxxxx 是你实际的磁盘信息啊,敏感信息,隐藏了。输入 m 并回车看到如下:
Command (m for help): m Help: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Generic d delete a partition F list free unpartitioned space l list known partition types n add a new partition p print the partition table t change a partition type v verify the partition table i print information about a partition Misc m print this menu u change display/entry units x extra functionality (experts only) Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file Save & Exit w write table to disk and exit q quit without saving changes Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table Command (m for help):
具体我就不解释了,懒得翻译,都很简单哈,然后输入 n,并回车,即添加一个分区,你会看到:
Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p):
这里输入 p 即主分区,e 指扩展分区,输入 p 并回车,你将看到:
Partition number (1-4, default 1):
这里,输入 1 并 回车 或者直接回车, 接下来两步也是直接回车就好。
4、最后,格式化分区:mkfs.ext4 /dev/vdb1 接着是 mkfs.ext4 /dev/vdc1 和 mkfs.ext4 /dev/vdd1
5、其实现在才是最后哈,我们修改下 fatab 表,让它自动挂载:vim /etc/fstab ,在文件最后 新增如下三行即可:
/dev/vdb1 /home/mongodb ext4 defaults 0 0 /dev/vdc1 /home/mysql ext4 defaults 0 0 /dev/vdd1 /home/other ext4 defaults 0 0
保存后重启,重启完毕,输入 df -h 即可查看啦。分区和挂载至此完毕。