红联Linux门户
Linux帮助

破解SQLServer for Linux预览版的3.5GB内存限制(RHEL篇)

发布时间:2017-05-16 09:49:26来源:linux网站作者:q303248153
微软发布了SQLServer for Linux,但是安装竟然需要3.5GB内存,这让大部分云主机用户都没办法尝试这个新东西。
这篇我将讲解如何破解这个内存限制。
要看关键的可以直接跳到第6步,只需要替换4个字节就可以破解这个限制。
 
1.首先按照微软的给出的步骤安装和配置
https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-setup-red-hat
 
2.到执行/opt/mssql/bin/sqlservr-setup时可以看到这个错误
sqlservr: This program requires a machine with at least 3250 megabytes of memory.
 
3.按错误文本查找消息在哪个文件里面
[root@localhost ~]# cd /opt/mssql/bin/
[root@localhost bin]# grep -irn "3250"
[root@localhost bin]# grep -irn "megabytes of memory"
Binary file sqlpackage matches
Binary file sqlpackage matches
Binary file sqlservr matches
[root@localhost bin]# strings sqlservr | grep "megabytes of memory"
%s: This program requires a machine with at least %zu megabytes of memory.
[root@localhost bin]# strings sqlpackage | grep "megabytes of memory"
%s: This program requires a machine with at least %zu megabytes of memory.
看来sqlservr和sqlpackage会检测这个限制,并且这个限制是一个常量
 
4.查找错误消息的位置
[root@localhost bin]# hexdump -C sqlservr | less
找到这里
0006baf0  72 69 6e 67 29 00 25 73  3a 20 54 68 69 73 20 70  |ring).%s: This p|
0006bb00  72 6f 67 72 61 6d 20 72  65 71 75 69 72 65 73 20  |rogram requires |
可以看到消息在0006baf6的位置
 
5.查找调用错误消息的位置
[root@localhost bin]# objdump -C -S sqlservr | less
找到这里
破解SQLServer for Linux预览版的3.5GB内存限制(RHEL篇)
判断的函数在这里
破解SQLServer for Linux预览版的3.5GB内存限制(RHEL篇)
调用判断的函数的代码在这里
破解SQLServer for Linux预览版的3.5GB内存限制(RHEL篇)
顺道再用hexdump查找一下有多少处地方用了80 10 b7 c1,结果是只有一处
00014860  00 00 48 89 df e8 66 15  00 00 be 80 10 b7 c1 4c  |..H...f........L|
00014870  89 e7 e8 69 f0 00 00 0f  57 c0 0f 29 85 70 ff ff  |...i....W..).p..|
 
6.使用python修改代码
改条件判断的jb或者改8010b7c1都可以,我这里把8010b7c1改成更小的值0080841e(512M)
[root@localhost bin]# mv sqlservr sqlservr.old
[root@localhost bin]# python
>>> a = open("sqlservr.old", "rb").read()
>>> b = a.replace("\x80\x10\xb7\xc1", "\x00\x80\x84\x1e")
>>> open("sqlservr", "wb").write(b)
[root@localhost bin]# chmod +x sqlservr
可以继续替换掉sqlpackage中的限制值,但是不替换也可以使用
 
7.继续配置sqlserver
[root@localhost bin]# /opt/mssql/bin/sqlservr-setup
[root@localhost bin]# systemctl status mssql-server
如果你执行完命令后没有看到服务正常启动,可能是之前的配置没有成功导致的
删除mssql的数据文件夹并重试即可
[root@localhost bin]# rm -rf /var/opt/mssql
[root@localhost bin]# /opt/mssql/bin/sqlservr-setup
正常启动后可以看到
破解SQLServer for Linux预览版的3.5GB内存限制(RHEL篇)
启动成功后使用微软提供的命令行工具连接也可以,使用windows上的客户端连接也可以
https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-setup-tools
下图是2G内存上运行的mssql
破解SQLServer for Linux预览版的3.5GB内存限制(RHEL篇)
破解SQLServer for Linux预览版的3.5GB内存限制(RHEL篇)
 
Ubuntu上的破解会不一样,因为Ubuntu安装前会运行检测程序,如何破解将在下一篇讲解。
 
题外话
mssql for linux有日期限制和联网验证,预计正式版以后免费的可能性很小
mssql在linux上编译开启了pie选项并且没有符号表导出,这让gdb跟踪变得很困难,但这次破解只需要静态分析
mssql的本体封在了/opt/mssql/lib/sqlservr.sfp里面,如果需要破解其他限制可能还需要花功夫研究这个文件。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/30805.html