Build rpm example:zram
rpmbuild
#ll zram-1.0.0
total 32
-rw-r--r-- 1 root root 948 Aug 21 16:44 Makefile
-rw-r--r-- 1 root root 221 Aug 21 16:44 mkzram.service
-rw-r--r-- 1 root root 2633 Aug 21 16:44 README.md
-rw-r--r-- 1 root root 395 Aug 23 11:29 zram
-rw-r--r-- 1 root root 1780 Aug 21 16:44 zram.spec
-rwxr-xr-x 1 root root 988 Aug 22 11:17 zramstart
-rwxr-xr-x 1 root root 931 Aug 22 12:32 zramstat
-rwxr-xr-x 1 root root 162 Aug 21 16:44 zramstop
#ls
zram-1.0.0
#tar -czf zram-1.0.0.tar.gz zram-1.0.0
#cp zram-1.0.0.tar.gz /root/rpmbuild/SOURCES/
#cp zram-1.0.0/zram.spec /root/rpmbuild/SPECS/zram.spec
#rpmbuild -ba /root/rpmbuild/SPECS/zram.spec
文件准备
/usr/lib/systemd/system/mkzram.service
[Unit]
Description=Enable compressed swap in memory using zram
After=multi-user.target
[Service]
RemainAfterExit=yes
ExecStart=/usr/sbin/zramstart
ExecStop=/usr/sbin/zramstop
Type=oneshot
[Install]
WantedBy=swap.target
#cat /usr/sbin/zramstart
#!/bin/sh
#$(nproc) get cpu core number
num_cpus=$(nproc)
[ "$num_cpus" != 0 ] || num_cpus=1
#memory percentage,If have mem:100G cpu:24, default value per disksize=33G/24
MEM_FACTOR_PERCENT=33
num_device=$num_cpus
if [[ -f /etc/sysconfig/zram ]];then
source /etc/sysconfig/zram
if [[ -n $MEM_FACTOR_PERCENT ]];then
mem_percentage=$MEM_FACTOR_PERCENT # memory percentage
fi
if [[ -n $DEVICE_NUM ]];then
num_device=$DEVICE_NUM #device number
fi
fi
memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
mem_per_device=$(($memtotal/${num_device}*${mem_percentage}/100*1024))
modprobe -q zram num_devices=${num_device}
last_num=$(($num_device - 1))
for i in $(seq 0 $last_num); do
#enable lz4 if that supported
if [[ -e "/sys/block/zram$i/comp_algorithm" ]];then
grep -q lz4 /sys/block/zram$i/comp_algorithm && echo lz4 > /sys/block/zram$i/comp_algorithm
fi
echo $mem_per_device > /sys/block/zram$i/disksize
mkswap /dev/zram$i
swapon -p 100 /dev/zram$i
done
#cat /usr/sbin/zramstat
#!/bin/sh
ls /sys/block/zram* > /dev/null 2>&1 || exit 0
for i in /sys/block/zram*; do
each_zram=`echo ${i##*/}`
compr=$(< $i/compr_data_size)
orig=$(< $i/orig_data_size)
ratio=0
if [ $compr -gt 0 ]; then
ratio=$(echo "scale=2; $orig/$compr" | bc -q)
#ratio=$(echo "scale=2; $compr/$orig*100" | bc -q)
fi
orig_human_MB=`scale=2;echo "$orig/1024/1024" | bc`
compr_human_MB=`scale=2;echo "$compr/1024/1024" | bc`
swap_size=`cat /proc/swaps | grep -w "${each_zram}" | awk '{print $3}'`
swap_used=`cat /proc/swaps | grep -w "${each_zram}" | awk '{print $4}'`
swap_ratio=$(printf "%.2f" `echo "scale=2;${swap_used}/${swap_size}*100"|bc`)
#echo -e "/dev/${i/*\/}:\t${ratio}% (${orig} bytes (${orig_human_MB} MB) -> ${compr} bytes (${compr_human_MB} MB))"
echo -e "/dev/${i/*\/}:\tswap_used:${swap_ratio}% compress_ratio:${ratio}:1 (${orig} bytes (${orig_human_MB} MB) -> ${compr} bytes (${compr_human_MB} MB))"
done
#cat /usr/sbin/zramstop
#!/bin/sh
for i in $(grep '^/dev/zram' /proc/swaps | awk '{ print $1 }'); do
swapoff "$i"
done
if grep -q "^zram " /proc/modules; then
sleep 1
rmmod zram
fi
#cat /etc/sysconfig/zram
# The factor is how much (from 0 to 100, percentage)
# of system RAM to allocate to ZRAM block devices
# Too big, and your system will start killing off processes
# If total_mem=100G, MEM_FACTOR_PERCENT=33, /dev/zram0+/dev/zram1+... = 33G ,default value is 33%
MEM_FACTOR_PERCENT=33
#Define /dev/zramxx number,if you do not define , default DEVICE_NUM value equal cpu core number
#DEVICE_NUM=1
spec文件准备
#cat zram.spec
Summary: Enable compressed swap in memory
Name: zram
Version: 1.0.0
Release: 2%{?dist}
License: GPLv2
Group: System Environment/Daemons
Source0: %{name}-%{version}.tar.gz
BuildArch: noarch
BuildRequires: systemd-units
Requires(post): systemd-sysv
Requires(post): systemd-units
Requires(preun): systemd-units
Requires(postun): systemd-units
Requires: filesystem >= 2.0.1, initscripts, bc > 1.0
# No debug info for bare scripts, right?
%define debug_package %{nil}
# http://fedoraproject.org/wiki/Changes/UnversionedDocdirs
%{!?_pkgdocdir: %global _pkgdocdir %{_docdir}/%{name}-%{version}}
%global _docdir_fmt %{name}
%description
zram compresses swap partitions into RAM for performance.
You need Linux kernel version 2.6.37.1 or better to use zram.
%prep
%setup -q
%build
%install
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
mkdir -p $RPM_BUILD_ROOT%{_unitdir}
ln -s $RPM_BUILD_ROOT/usr/lib $RPM_BUILD_ROOT/lib
mkdir -p $RPM_BUILD_ROOT%{_sbindir}
%makeinstall DESTDIR=$RPM_BUILD_ROOT
%post
%systemd_post mkzram.service
%preun
%systemd_preun mkzram.service
%postun
%systemd_postun_with_restart mkzram.service
%files
%doc README.md
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%{_unitdir}/mkzram.service
%{_sbindir}/zramstart
%{_sbindir}/zramstop
%{_sbindir}/zramstat
%exclude /lib
%changelog
* Tue Nov 25 2014 Juan Orti <jorti@fedoraproject.org> - 1.0.0-1
- Spec file cleanup
* Mon Nov 25 2013 Doncho Gunchev <dgunchev@gmail.com> - 0:1.0.0-2
- http://fedoraproject.org/wiki/Changes/UnversionedDocdirs
- Added kmod-staging dependency
- Test on Fedora 19
* Mon Sep 02 2013 Doncho Gunchev <dgunchev@gmail.com> - 0:1.0.0-1
- Add Darren Steven's build fix for fedora 18
* Tue Mar 19 2013 Doncho Gunchev <dgunchev@gmail.com> - 0:1.0.0-0
- Initial package
Build rpm example:zram的更多相关文章
- Build RPM package from source code
# yum install rpm-build# wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz# vim rsync.specNam ...
- Hadoop build error java.lang.NoClassDefFoundError: org/sonatype/aether/graph/DependencyFilter
When running the command: + mvn site site:stage -DskipTests -DskipTest -DskipITs you get an error: ...
- 制作nginx的rpm包出现问题
在学习打包rpm,找到了个不错的参考站点 https://src.fedoraproject.org/cgit/rpms/ 过程: git clone -b el6 git://pkgs.fedor ...
- gbs build使用说明
注:本文从:https://source.tizen.org/documentation/articles/gbs-build 翻译而来. 1 前言 通过使用gbs build指令,开发者可以在本地编 ...
- ceph 生成rpm包
概述 从ceph的源码build出rpm包: #git clone --recursive https://github.com/ceph/ceph.git #./instal-dep.sh 以上两点 ...
- 制定RPM包和加入YUM源
##################################################### ##如有转载,请务必保留本文链接及版权信息 ##欢迎广大运维同仁一起交流linux/unix ...
- CentOS6.3 编译安装LAMP(2):编译安装 Apache2.2.25
所需源码包: /usr/local/src/Apache-2.2.25/httpd-2.2.25.tar.gz 编译安装 Apache2.2.25 #切换到源码目录 cd /usr/local/src ...
- CentOS6.3 编译安装LAMP(2):编译安装 Apache2.4.6
Apache官方说: 与Apache 2.2.x相比,Apache 2.4.x提供了很多性能方面的提升,包括支持更大流量.更好地支持云计算.利用更少的内存处理更多的并发等.除此之外,还包括性能提升.内 ...
- RHEL6.4编译安装企业级LAMMP平台
一.LAMMP简介 二.使用软件及服务器架构说明 三.配置及安装过程 1.安装arp与httpd 2.安装mysql 3.安装php(php-fpm) 4.安装Xcache ...
随机推荐
- Rmq Problem mex
求区间mex.莫队可做. 但如果强制在线,就可以用主席树做. 建立权值线段树,找每个数最后一次出现的位置.查询的时候找第r棵线段树最近出现位置在l之前的最小数即可.update的时候可以update这 ...
- linux双网卡配置
一.VM虚拟机添加一个网络适配器. 选择自己需要的模式类型 二.启动虚拟机,配置网卡 按原先配置网卡的方式配置完(ip地址及默认网关还有网卡名不能跟原先的一样) 重启所有网卡(service netw ...
- 小松之LINUX 驱动学习笔记(二)
这两天一直在看字符驱动那块,后来从网上找啦几个例子,自己编译啦下,安装啥的都挺正常,就是用测试程序测试的时候总出问题,现在找到一个能测试的代码,自己先看看和原来的那个代码有啥不同,后面会继续更新,说下 ...
- AOP经典2种配置演示样例
第一种: 使用aop指定切面aspect. <bean id="LogAdvice" class="com.thinkmore.framework.monitor. ...
- Android 获取屏幕截图 和保存到本地的sd卡路径下
/** * 获取和保存当前屏幕的截图 */ private void GetandSaveCurrentImage() { //1.构建Bitmap WindowManager windowManag ...
- Ubuntu下的用户和权限(三)
七.增删群组相关的命令 相同的我们要先介绍两个重要的设定档:/etc/group和/etc/gshadow,前面那个事实上和/etc/passwd一样.而后者就是群组的password表了.先看看长啥 ...
- ubuntu解压命令全览(rar)
sudo apt-get install p7zip-full Ubuntu下解压rar文件的方法 2010-05-13 12:47 一般通过默认安装的ubuntu是不能解压rar文件的,只有在安装了 ...
- DPI深度报文检测架构及关键技术实现
DPI深度报文检测架构及关键技术实现 当前DPI(Deep Packet Inspect深度报文识别)技术是安全领域的关键技术点之一,围绕DPI技术衍生出的安全产品类型也非常的多样.在分析DPI的进一 ...
- 使用神经网络-垃圾邮件检测-LSTM或者CNN(一维卷积)效果都不错【代码有问题,pass】
from sklearn.feature_extraction.text import CountVectorizer import os from sklearn.naive_bayes impor ...
- 调试相关blogs收集
Debug Diag官方blog https://blogs.msdn.microsoft.com/debugdiag/ Tess https://blogs.msdn.microsoft.com ...