阿里云(/dev/vdb)
# 创建挂载目录
mkdir /data
# 检查数据盘情况
fdisk -l
# 分区:输入 n, p, 1, w
fdisk /dev/vdb
# n add a new partition
# p primary (0 primary, 0 extended, 4 free)
# 1 分区号 (1-4,默认 1)
# w write table to disk and exit
# 格式化分区
mkfs -t ext4 /dev/vdb1
# 挂载数据盘
mount /dev/vdb1 /data/
# 写入 fstab,重启后永久生效
echo '/dev/vdb1 /data ext4 defaults 0 0' >> /etc/fstab
亚马逊(/dev/nvme1n1p1)
fdisk -l
fdisk /dev/nvme1n1p1 # 同样输入 n, p, 1, w
mkfs -t ext4 /dev/nvme1n1p1
mkdir /data
mount /dev/nvme1n1p1 /data/
开机自动挂载:/etc/rc.local
rc.local 需要可执行权限才会被执行:
chmod +x /etc/rc.d/rc.local
示例内容:
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
mount /dev/vdb1 /data
ulimit -c unlimited
ulimit -n 65535
官方建议在 systemd 环境下改用自定义 service 或 udev 规则;
rc.local因并行启动,不保证在其他服务之后运行。