跳到主要内容
方的代码随记
返回

云主机挂载新数据盘

更新于:

阿里云(/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 因并行启动,不保证在其他服务之后运行。


分享这篇文章:

上一篇
修改 Linux 时区与时间同步
下一篇
CentOS 7.9 源码编译 Nginx 与 PHP