找回密码
 加入怎通
查看: 252|回复: 5

宝塔面板 bt.cn CentOS6.x/7.x系统盘迁移到数据盘操作方法(宝塔面板安装教程)

[复制链接]
我来看看 发表于 2023-03-18 02:58:32 | 显示全部楼层 |阅读模式
: `6 h% [2 m% O4 y

(此处已添加小程序,请到今日头条客户端查看)最近操作了几个宝塔面板系统盘迁移到数据盘的项目,找了好多网上的教程,发现大部分写的比较片面,今天特意整理了一下操作方案,经验分享给大家~首先要明确以下几个步骤:

. \' _7 U8 ?( o, d( k3 X7 Q

第一步 格式化数据盘、挂载磁盘第二步 移动系统盘宝塔数据到新挂载的数据盘第三步 将新挂载的磁盘目录链接到www第四步 重新启动服务器后重启面板(所有操作全部在命令行操作,请提前简单学习linux命令行操作)

7 M( G0 L( y8 K: H; W- w: a

第一步 格式化数据盘并挂载磁盘通常在增加磁盘或新系统,必不可少的就是格式化磁盘,分区,挂载分区使用过阿里ECS的朋友都知道,数据盘是需要自己分区并挂载的,对于新手确实是个难题,特记之,以供参考!(1)先使用 df -lh 命令查看 ,发现系统只有系统盘。

7 k6 _9 x: ] M8 e( l j

(2)使用 fdisk -l 查看磁盘情况,从下图可看到 有一个磁盘未分区,并记住为分区的 标识,我们这里是 /dev/vdb:

' g& C, ~* v3 {

(3)执行 fdisk /dev/vdb 对磁盘分区,需要依次输入 "n","p","1"(注意:这里一般是写1 看要分几个区),两次回车,"w":[root@iZtl9h0eoqfyy7Z ~]# fdisk -l

" J8 i) p) N& Z. ?; m: ~

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x590ca8b1.

0 M+ ?9 `: R/ @0 D0 Y9 A3 v# G

Changes will remain in memory only, until you decide to write them.After that, of course, the previous content wont be recoverable.

9 y2 B7 S$ x* Z4 R

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. Its strongly recommended to switch off the mode (command c) and change display units to

8 j9 `8 l! S0 y/ X

sectors (command u).Command (m for help): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First cylinder (1-39162, default 1):

7 O" d Z6 e- l! x5 r

Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-39162, default 39162):Using default value 39162Command (m for help): p

& J0 A" ?( |& e' T% @0 j+ V

Disk /dev/vdb: 322.1 GB, 322122547200 bytes255 heads, 63 sectors/track, 39162 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes

7 r$ q |3 k z" S# W3 S

Sector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes

& w$ {6 a7 D$ }. }3 V' c8 W

Disk identifier: 0x590ca8b1Device Boot Start End Blocks Id System/dev/xvde1 1 39162 314568733+ 83 Linux

" W$ Y! F) K* R

Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.

9 m! W% H" V* k1 e2 B% {1 L' `" a

Syncing disks.(4) 创建分区 命令: mkfs.ext4 /dev/vdb1 (相当于win的格式化)[root@iZtl9h0eoqfyy7Z ~]# mkfs.ext4 /dev/vdb1

: ^) \& {, x) W4 Y. G3 Z

mke2fs 1.41.12 (17-May-2010)Could not stat vdb1 --- No such file or directoryThe device apparently does not exist; did you specify it correctly?[root@qxyw ~]# mkfs.ext4 /dev/vdb1

+ Q( r/ O6 H) K: Q, z1 ~

mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)

4 R* X6 B: { V- R( a

Stride=0 blocks, Stripe width=0 blocks19660800 inodes, 78642183 blocks3932109 blocks (5.00%) reserved for the super user

]2 H0 y3 A$ h0 _3 j" o2 M7 c

First data block=0Maximum filesystem blocks=42949672962400 block groups32768 blocks per group, 32768 fragments per group8192 inodes per group

4 E" C7 {/ X, Q1 ]1 P% c( ~- u9 |

Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616Writing inode tables: done

5 P( p% F! S0 F5 k4 E& E, S" c6 j

Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 25 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.

* w3 b E* A- J/ f3 F' T9 H q

(5)根目录新建文件夹 命令: mkdir /mydata ,然后使用命令 mount /dev/vdb1 /mydata 将/dev/vdb1 挂载到mydata文件夹[root@iZtl9h0eoqfyy7Z ~]# mount /dev/vdb1 /mydata。

' B+ J2 y" W' v5 R2 P& }* s

[root@iZtl9h0eoqfyy7Z ~]# df -h复制(6)mount直接挂载,一旦系统重新启动就会失效,所以要设置系统启动自动挂载命令: echo "/dev/vdb1 /mydata ext4 defaults 0 0" >>/etc/fstab。

5 z8 i) t* ]/ k5 {

[root@iZtl9h0eoqfyy7Z ~]# echo "/dev/vdb1 /mydata ext4 defaults 0 0" >>/etc/fstab[root@iZtl9h0eoqfyy7Z ~]#

/ D5 S# Y2 _2 N# h8 w

复制使用命令 mount -a 查看是否有错误注意:要是有错误,可以通过vim /etc/fstab编辑挂载表第二步 移动系统盘宝塔数据到新挂载的数据盘(1)先通过命令: /etc/init.d/bt stop 停止宝塔。

' g$ H0 f# v/ [& x* k9 D* E

[root@iZtl9h0eoqfyy7Z ~]# /etc/init.d/bt stopStopping Bt-Tasks... doneStopping Bt-Panel... doneStoping nginx... done

6 J7 Y) D3 [$ @5 N I7 q9 T7 P. \

Shutting down MySQL.. SUCCESS!Stopping Pure-FTPd... Pure-FTPd is not running.Gracefully shutting down php-fpm warning, no pid file found - php-fpm is not running ?

, a5 T9 c( \: h$ b2 J% f

Gracefully shutting down php-fpm . done复制(2)通过命令: mv /www /mydata 将宝塔数据移动到自定义文件夹注意:移动时间是根据你数据的大小来定的,在移动过程中不要操作。

3 g2 }" H) ?3 y2 G# `

[root@iZtl9h0eoqfyy7Z ~]# mv /www /mydata[root@iZtl9h0eoqfyy7Z ~]#复制第三步 将新挂载的磁盘目录链接到www(1)删除/www文件夹 通过命令: rm -rf /www 实现。

E/ J; z# c$ k; X

删除文件夹 可能性的会出现2个问题,第一是宝塔默认的swap交换分区删除不了 可以通过命令 swapoff swap 来关闭swap , 然后再执行rm swap命令删除这个文件,第二个可能性问题就是部分文件可能权限不够删除不了 如:.user.ini 可以通过命令 chattr -i 。

, o+ p$ p# x: y

/wwww/wwwroot/yoursite/.user.ini 来提权,再执行rm命令删除文件(2)删除www文件夹后,通过命令 ln -s /mydata/www /www 将/mydata/www 链接到 /www 文件夹。

% f3 Z3 V! |% y# n& H- \( q! Z

[root@iZtl9h0eoqfyy7Z ~]# ln -s /mydata/www /www[root@iZtl9h0eoqfyy7Z ~]#复制第四步 重新启动服务器后重启面板首先重新启动服务器,再次连接后 执行命令: /etc/init.d/bt restart 重新启动宝塔面板。

. n$ M4 @( p* L+ J7 i. b

[root@localhost ~]# /etc/init.d/bt restartStarting Bt-Panel... doneStarting Bt-Tasks... doneStarting nginx... done

; K% q) o; r$ j- \5 |, R

Starting MySQL.. SUCCESS!复制自此 迁移完成!!!

/ n, y* V# n6 x9 A: y1 i) f$ X' O. i2 f: \$ J; ~ 9 f2 A( X* X, {' `4 F5 `, i( h- m5 m( y7 p + Y8 @# [ E6 S& o

暂时无法加载帖子列表

回复

使用道具 举报

wang_wei 发表于 2026-01-13 06:06:50 | 显示全部楼层
分析得很透彻,很多细节都说到点子上了~
回复

使用道具 举报

流水岁月 发表于 2026-01-21 14:11:24 | 显示全部楼层
学习到了,之前一直没注意过这个点,受教了
回复

使用道具 举报

任务终结者 发表于 2026-09-15 09:45:49 | 显示全部楼层
这个思路很新颖,打开了新世界的大门,谢谢分享
回复

使用道具 举报

戴草帽的王子 发表于 2026-09-20 03:56:01 | 显示全部楼层
刚好遇到类似问题,看完这个帖子心里有底了
回复

使用道具 举报

东方大国打过 发表于 2026-10-18 12:19:20 | 显示全部楼层
楼主辛苦了,整理这么多内容,必须点赞收藏
回复

使用道具 举报

    您需要登录后才可以回帖 登录 | 加入怎通

    本版积分规则

    QQ|手机版|小黑屋|网站地图|真牛社区 ( 苏ICP备2023040716号-2 )

    GMT+8, 2026-10-31 19:05 , Processed in 0.037637 second(s), 25 queries , Gzip On.

    免责声明:本站信息来自互联网,本站不对其内容真实性负责,如有侵权等情况请联系420897364#qq.com(把#换成@)删除。

    Powered by Discuz! X3.5

    快速回复 返回顶部 返回列表