centos自动磁盘挂载教程 一键自动挂载数据盘到/www目录

[复制链接]
查看: 10233   回复: 4
发表于 2024-2-27 00:02:49 | 显示全部楼层 |阅读模式
我们在购买服务器时有些商家会赠送数据盘,时间久了以后我们站点数据趋于庞大,需要购买更大的磁盘来存储,此时我们需要挂载数据盘到指定的目录。今天草蜢在宝塔官方论坛看到了一个关于挂载数据盘的脚本,可以一键自动挂载数据盘到/www目录。当然如果你需要挂载到其他目录的话可以把脚本下载到本地,把“setup_path=/www”后的“/www”改成你要挂载的目录即可。
脚本说明
1、默认将数据盘挂载到/www目录

2、服务器上已存在/www目录,为了您的数据安全,挂载工具会自动跳过

3、服务器之前安装过Windows系统,需要手动删除NTFS分区,挂载工具会直接跳过NTFS分区

4、若您的磁盘已分区,且未挂载,工具会自动将分区挂载到/www

5、若您的磁盘是新磁盘,工具会自动分区并格式化成ext4文件系统

6、本工具只自动挂载一个分区,若您有多块数据盘,请手动挂载未被自动挂载的磁盘

7、若要挂载到其它目录,请在第一个参数传入目录名

8、只有一个磁盘或www目录已被挂载的情况下,自动退出脚本,不执行任何操作
挂载方法/命令

输入fdisk -l 查看硬盘信息
  1. [root@VM_0_11_centos ~]# fdisk -l Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000c5e30    Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048   104857599    52427776   83  Linux Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
复制代码
Centos/Fedora:
  1. yum install wget -y && wget -O auto_disk.sh https://download.bt.cn/tools/auto_disk.sh && bash auto_disk.sh#备用:yum install wget -y && wget -O auto_disk.sh https://raw.githubusercontent.com/wn789/www/master/auto_disk.sh && bash auto_disk.sh
复制代码
Ubuntu:
  1. wget -O auto_disk.sh https://download.bt.cn/tools/auto_disk.sh && sudo bash auto_disk.sh#备用:wget -O auto_disk.sh https://raw.githubusercontent.com/wn789/www/master/auto_disk.sh && sudo bash auto_disk.sh
复制代码
Debian:
  1. wget -O auto_disk.sh https://download.bt.cn/tools/auto_disk.sh && bash auto_disk.sh#备用:wget -O auto_disk.sh https://raw.githubusercontent.com/wn789/www/master/auto_disk.sh && bash auto_disk.sh
复制代码
本站用的是centos7系统,复制相应命令到ssh即可,喝口水等个2分钟,命令自动运行。小白不费吹灰之力,赞一个。
磁盘挂载过程预览(示例)
  1. [root@VM_0_11_centos ~]# yum install wget -y && wget -O auto_disk.sh https://download.bt.cn/tools/auto_disk.sh && bash auto_disk.shLoaded plugins: fastestmirror, langpacksRepository epel is listed more than once in the configurationLoading mirror speeds from cached hostfilePackage wget-1.14-15.el7_4.1.x86_64 already installed and latest versionNothing to do--2018-08-31 01:16:14--  https://download.bt.cn/tools/auto_disk.shResolving download.bt.cn (download.bt.cn)... 183.131.200.94, 183.131.200.105, 183.131.200.87, ...Connecting to download.bt.cn (download.bt.cn)|183.131.200.94|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 7530 (7.4K) [application/x-sh]Saving to: ‘auto_disk.sh’ 100%[================================================================================================================================================>] 7,530       --.-K/s   in 0s 2018-08-31 01:16:14 (19.4 MB/s) - ‘auto_disk.sh’ saved [7530/7530]  +----------------------------------------------------------------------| Bt-WebPanel Automatic disk partitioning tool+----------------------------------------------------------------------| Copyright © 2015-2017 BT-SOFT(https://www.bt.cn) All rights reserved.+----------------------------------------------------------------------| Auto mount partition disk to /www+---------------------------------------------------------------------- Do you want to try to mount the data disk to the /www directory?(y/n): yDo you want to try to mount the data disk to the /www directory?(y/n): y stop bt-service停止宝塔服务 Stopping Bt-Tasks... doneStopping Bt-Panel... done disk partition...磁盘分区... Welcome to fdisk (util-linux 2.23.2). 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 tableBuilding a new DOS disklabel with disk identifier 0xf4593d5d. Command (m for help): Partition type:   p   primary (0 primary, 0 extended, 4 free)   e   extendedSelect (default p): Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039Partition 1 of type Linux and of size 20 GiB is set Command (m for help): The partition table has been altered! Calling ioctl() to re-read partition table.Syncing disks.mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks1310720 inodes, 5242624 blocks262131 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=2153775104160 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,        4096000 Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done Filesystem      Size  Used Avail Use% Mounted on/dev/vda1        50G  2.7G   44G   6% /devtmpfs        911M     0  911M   0% /devtmpfs           920M   32K  920M   1% /dev/shmtmpfs           920M  364K  920M   1% /runtmpfs           920M     0  920M   0% /sys/fs/cgrouptmpfs           184M     0  184M   0% /run/user/0/dev/vdb1        20G   45M   19G   1% /www move disk...迁移数据中... Done迁移完成 start bt-service启动宝塔服务 Starting Bt-Panel... doneStarting Bt-Tasks... done[root@VM_0_11_centos ~]# fdisk -l Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000c5e30    Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048   104857599    52427776   83  Linux Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xf4593d5d    Device Boot      Start         End      Blocks   Id  System/dev/vdb1            2048    41943039    20970496   83  Linux[root@VM_0_11_centos ~]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/vda1        50G  2.7G   44G   6% /devtmpfs        911M     0  911M   0% /devtmpfs           920M   32K  920M   1% /dev/shmtmpfs           920M  364K  920M   1% /runtmpfs           920M     0  920M   0% /sys/fs/cgrouptmpfs           184M     0  184M   0% /run/user/0/dev/vdb1        20G  1.1G   18G   6% /www[root@VM_0_11_centos ~]#
复制代码
回复

使用道具 举报

发表于 2024-2-27 00:03:23 | 显示全部楼层
感谢,收藏了
回复 支持 反对

使用道具 举报

发表于 2024-2-27 00:04:11 | 显示全部楼层
收藏
回复 支持 反对

使用道具 举报

发表于 2024-2-27 00:05:07 | 显示全部楼层
收藏加吃灰
回复 支持 反对

使用道具 举报

发表于 2024-2-27 00:05:23 | 显示全部楼层
宝塔有一键挂载的脚本啊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则