Tag Archives: linux

Converting a PDF to JPG and back again, without looking terrible

Sometimes you need to convert a pdf to jpg, mess around with it, then recreate a pdf. Here’s the method I use:


convert -density 400 file.pdf -alpha remove file.jpg # this create file-0.jpg, file-1.jpg, etc. Between 300-600 is a good density, alpha remove is needed if there is transparency in the pdf
gimp file-0.jpg
convert -units PixelsPerInch -density 400 -quality 25 $(ls -v file-*.jpg) file.pdf # gimp usually uses a dpi of 72, so need to change resolution back to 400, a high quality = large file

That’s it! Almost. If there’s transparency in the pdf, jpg won’t like it so you’ll need to use png. But PNG doesn’t automatically add numbers, so you need to do:


convert -density 400 ~/Downloads/PBH.PDF pbh-%d.png

Sometimes you need to convert the pngs to jpg before making a pdf. YMMV.

Telling Yum to Keep a Certain Kernel Version

VPS providers only support a set of kernels. Yum updates can sometimes remove old kernels, which can cause problems if the VPS provider doesn’t support the newer kernels yet. Yum supports pinning a certain kernel, so you can be sure that the system can boot after an upgrade and have an orderly kernel upgrade when the time comes.

From this article:

# prevent yum from deleting old kernel
yumdb set installonly keep kernel-core-3.17.4-301.fc21.x86_64

# allow yum to delete old kernel
yumdb del installonly kernel-core-3.17.4-301.fc21.x86_64

Recompiling nginx on Fedora to use Google pagespeed

Google Pagespeed is a nice minify module for nginx/apache, but in order to run on nginx it needs to be compiled into nginx from source. Luckily it’s not too hard.

Google’s directions

https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source

What I did


sudo yum install gcc-c++ pcre-dev pcre-devel zlib-devel make unzip
NPS_VERSION=1.9.32.1
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz # extracts to psol/
rpm -ivh https://dl.fedoraproject.org/pub/fedora/linux/updates/20/SRPMS/nginx-1.4.7-1.fc20.src.rpm

Edit /root/rpmbuild/SPECS/nginx.spec

Add to the configure command:

--add-module=/root/ngx_pagespeed-release-1.9.32.1-beta/ \

Rebuild and Install


rpmbuild -bb /root/rpmbuild/SPECS/nginx.spec
rpm -Uvh /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.fc17.x86_64.rpm
service restart nginx

Xdefaults file

Reload with xrdb ~/.Xdefaults


!URxvt*font: xft:Anonymous Pro:bold:size=10
!urxvt.background: black
urxvt.foreground: white
URxvt*depth: 32
URxvt*background: rgba:0000/0000/0000/dddd

!black
URxvt*color0: #171717
URxvt*color8: #737373
!red
URxvt*color1: #FF5E5E
URxvt*color9: #FF7878
!green
URxvt*color2: #9CE82B
URxvt*color10: #9ACD32
!yellow
URxvt*color3: #F0E68C
URxvt*color11: #EEE8AA
!blue
URxvt*color4: #008AFF
URxvt*color12: #4F98FF
!magenta
URxvt*color5: #E88CFF
URxvt*color13: #EDA6FF
!cyan
URxvt*color6: #87CEFA
URxvt*color14: #B0E2FF
!white
URxvt*color7: #DCDCCC
URxvt*color15: #FFFFFF

URxvt.perl-ext-common: ...,font-size,...
URxvt.keysym.C-Up: perl:font-size:increase
URxvt.keysym.C-Down: perl:font-size:decrease
URxvt.keysym.C-S-Up: perl:font-size:incglobal
URxvt.keysym.C-S-Down: perl:font-size:decglobal
URxvt.iso14755: false
URxvt.iso14755_52: false

Self-Signing Modules on Fedora 20

I recently got a new computer for work. So new that the wireless drivers are not yet included in the kernel mainline, though they do exist in the staging tree in the main branch. It’s relatively easy to compile the module following the directions post on this blog post:
http://www.linlap.com/asus_transformer_book_trio_tx201la

Updated kernel source for 3.15:
https://kernel.googlesource.com/pub/scm/linux/kernel/git/next/linux-next.git/+archive/v3.15/drivers/staging/rtl8821ae.tar.gz

Makefile append:

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) CONFIG_R8821AE=m modules

Basically you download that tarball, append to the Makefile, and run make. Simple.

The problem I ran into is that UEFI SecureBoot is set up, meaning that all code inserted in the kernel needs to be signed and recognized by the bios. It’s really not obvious how to do this, I guess because people are not really encouraged to build custom modules and kernels. I did eventually find a post from the SystemTap guy on how to do it:
http://sourceware.org/systemtap/wiki/SecureBoot

x509.genkey openssl config file

[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
prompt = no
string_mask = utf8only
x509_extensions = myexts

[ req_distinguished_name ]
CN = Modules

[ myexts ]
basicConstraints=critical,CA:FALSE
keyUsage=digitalSignature
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid

Creating the x509 certs, and adding them to MoK (machine-owner keys):

openssl req -new -nodes -utf8 -sha256 -days 36500 -batch -x509 -config x509.genkey -outform DER -out signing_key.x509 -keyout signing_key.priv
sudo mokutil --import signing_key.x509
reboot

Sign modules and install:

/usr/src/kernels/`uname -r`/scripts/sign-file sha512 signing_key.priv signing_key.x509 rtl8821ae.ko
sudo cp rtl8821ae.ko /lib/modules/3.16.0-1.fc22.x86_64/kernel/drivers/staging/rtl8821ae/

It kernel panic’d the first time (oops). The second time it ran ok.

Lustre Crash Tool Extensions

This will let you dump the Lustre log from a kernel vmcore:
https://github.com/Xyratex/crash-tools/tree/master/cr-ext

This is an extended backtrace plugin/extension for crash that decodes the parameters in a nice way, and maybe works:
https://wiki.hpdd.intel.com/display/~jhammond/XBT+-+extended+backtrace+extension+for+crash

Here’s how to load the extension:
sh> mod -S
MODULE NAME SIZE OBJECT FILE
MODULE NAME SIZE OBJECT FILE
ffffffffa000f460 dm_mod 84337 /lib/modules/2.6.32-431.20.3.el6_lustre.g5a7c614.x86_64/kernel/drivers/md/dm-mod.ko

crash> extend /root/lustre-ext.so
/root/lustre-ext.so: shared object loaded
crash> lustre -l /tmp/foo.dl
lustre_walk_cpus(0, 5, 1)
cmd: p (*cfs_trace_data[0])[0].tcd.tcd_cur_pages
p (*cfs_trace_data[0])[0].tcd.tcd_pages.next

lustre: Dumped 355 total debug pages from 2 CPUs to /tmp/foo.dl