购买服务器的同时,买了一个800G的数据盘,数据盘购买后,不会自动添加进系统,需要手动添加
挂载方法
1.在云硬盘控制台的界面上手动挂载
2.执行命令
fdisk -l
出现很多内容,关注有Device Boot 的那一行:
Device Boot | Start | End | Blocks | Id | System |
/dev/vda1* | 2048 | 104857566 | 52427759+ | 83 | Linux |
3.从 Device Boot 的那一行可以看出,盘符大小是50G,明显不对
4.继续往下,查看跟购买的盘符800G相近的盘符,有个Disk /dev/vdb: 859.0 GB,这个/dev/vdb 才是数据盘
Disk /dev/vdb: 859.0 GB,858993459200bytes,1677721600 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
5.如果不放心数据盘是否干净,格式化一下(可跳过此步骤)
mkfs.ext4 /dev/vdb
6.现在挂载,数据盘/dev/vdb 指向我想指定的目录/www/wwwroot/
mount /dev/vdb /www/wwwroot/
7.输入 df -Th 命令,可以看到/dev/vdb 出现了
Filesystem | Type | Size | Used | Avail | Use% Mounted on |
devtmpfs | devtmpfs | 3.9G | 0 | 3.9G | 0% /dev |
tmpfs | tmpfs | 3.9G | 28K | 3.9G | 1% /dev/shm |
tmpfs | tmpfs | 3.9G | 612K | 3.9G | 1% /run |
tmpfs | tmpfs | 3.9G | 0 | 3.9G | 0% /sys/fs/cgroup |
/dev/vda1 | ext4 | 50G | 11G | 37G | 23% / |
tmpfs | tmpfs | 783M | 0 | 783M | 0% /run/user/0 |
/dev/vdb | ext4 | 788G | 73M | 748G | 1% /www/wwwroot |
8.最后将 mount /dev/vdb /www/wwwroot/ 添加/etc/rc.local 开机启动文件中
9.设置开机启动脚本rc.local 的内容
rc.local 会在未来的版本中淘汰,官方建议使用systemd 来替代,在没有使用systemd 之前,如果要在centos7中使用rc.local,
必须给其设置权限(755)
//为其添加权限 # chmod +x /etc/rc.d/rc.local //保险起见也给其链接文件添加权限 # chmod +x /etc/rc.local
安全起见,可以查询一下是否启动
//查看状态 # systemctl status rc-local.service //启动 # systemctl start rc-local.service
ps:umount 是解除挂载