linux环境

宝塔Linux自动磁盘挂载工具 一键挂载数据盘到/www目录

cmboy · 8月21日 · 2019年 · · · 本文5495字 · 阅读14分钟8,158

我们在购买服务器时有些商家会赠送数据盘,时间久了以后我们站点数据趋于庞大,需要购买更大的磁盘来存储,此时我们需要挂载数据盘到指定的目录。今天草蜢在宝塔官方论坛看到了一个关于挂载数据盘的脚本,可以一键自动挂载数据盘到/www目录。当然如果你需要挂载到其他目录的话可以把脚本下载到本地,把“setup_path=/www”后的“/www”改成你要挂载的目录即可。

脚本说明

  1. 默认将数据盘挂载到/www目录
  2. 服务器上已存在/www目录,为了您的数据安全,挂载工具会自动跳过
  3. 服务器之前安装过Windows系统,需要手动删除NTFS分区,挂载工具会直接跳过NTFS分区
  4. 若您的磁盘已分区,且未挂载,工具会自动将分区挂载到/www
  5. 若您的磁盘是新磁盘,工具会自动分区并格式化成ext4文件系统
  6. 本工具只自动挂载一个分区,若您有多块数据盘,请手动挂载未被自动挂载的磁盘
  7. 若要挂载到其它目录,请在第一个参数传入目录名
  8. 只有一个磁盘或www目录已被挂载的情况下,自动退出脚本,不执行任何操作

输入fdisk -l 查看硬盘信息

[root@VM_0_11_centos ~]# fdisk -l

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk 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 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

挂载命令

Centos/Fedora:

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:

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:

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分钟,命令自动运行。小白如草蜢依然不费吹灰之力,赞一个。

过程预览(示例)

[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.sh
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Package wget-1.14-15.el7_4.1.x86_64 already installed and latest version
Nothing to do
--2018-08-31 01:16:14--  https://download.bt.cn/tools/auto_disk.sh
Resolving 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 OK
Length: 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): y
Do you want to try to mount the data disk to the /www directory?(y/n): y

stop bt-service
停止宝塔服务

Stopping Bt-Tasks... done
Stopping 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 table
Building a new DOS disklabel with disk identifier 0xf4593d5d.

Command (m for help): Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039
Partition 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: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing 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% /dev
tmpfs           920M   32K  920M   1% /dev/shm
tmpfs           920M  364K  920M   1% /run
tmpfs           920M     0  920M   0% /sys/fs/cgroup
tmpfs           184M     0  184M   0% /run/user/0
/dev/vdb1        20G   45M   19G   1% /www

move disk...
迁移数据中...

Done
迁移完成

start bt-service
启动宝塔服务

Starting Bt-Panel... done
Starting Bt-Tasks... done
[root@VM_0_11_centos ~]# fdisk -l

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk 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 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 label type: dos
Disk identifier: 0xf4593d5d

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    41943039    20970496   83  Linux
[root@VM_0_11_centos ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  2.7G   44G   6% /
devtmpfs        911M     0  911M   0% /dev
tmpfs           920M   32K  920M   1% /dev/shm
tmpfs           920M  364K  920M   1% /run
tmpfs           920M     0  920M   0% /sys/fs/cgroup
tmpfs           184M     0  184M   0% /run/user/0
/dev/vdb1        20G  1.1G   18G   6% /www
[root@VM_0_11_centos ~]#
账号:
相关文章
暂无相关文章!
0 条回应

必须 注册 为本站用户, 登录 后才可以发表评论!

×