Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, November 27, 2017

micro:bit, bluetooth and Linux




 
After various efforts I was able to read micro:bit sensors data from Linux. While temperature, and accelerometer data is not too difficult to collect, the UART service took a little more time, mainly due to a known issue in the micro:bit BLE implementation.

Here you can find my observations and experiments, with sample Python scripts: https://github.com/alcir/microbit-ble

Saturday, August 5, 2017

Add speech to your Fedora system

This article first appeared on Fedora Magazine

By default, Fedora Workstation ships a small package called espeak. It adds a speech synthesizer — that is, text-to-speech software.
In today’s world, talking devices are nothing impressive as they’re very common. You can find speech synthesizers even in your smartphone, a product like Amazon Alexa, or in the announcements at the train station. In addition, synthesized voices are nowadays more or less similar to human speech. We live in a 1980s science fiction movie!
The voice produced by espeak may sound a bit primitive compared to the aforementioned tools. But at the end of the day espeak produces good quality speech. And whether you find it useful or not, at least it can provide some amusement.

Running espeak

In espeak you can set various parameters using command line options. Examples include:
  • amplitude (-a)
  • pitch adjustment (-p)
  • speed of sentences (-s)
  • gap between words (-g)
Each of these options produces various effects and may help you achieve a cleaner voice.
You can also select different voice variants with command line options. For example, try -ven+m3 for a different English male voice, and -ven+f1 for a female one. You can also use different languages. For a list, run this command:
espeak --voices
Note that many languages other than English are experimental attempts.
To create a WAV file instead of actually speaking something, use the -w option:
espeak -w out.wav "Audio file test"
The espeak utility also reads the content of a file for you.
espeak -f plaintextfile
Or you can pass the text to speech from the standard input. In this way, as a simple example, you can build a talking box that alerts you to an event using a voice. Your backup is completed? Add this command to the end of your script:
echo "Backup completed" | espeak -s 160 -a 100 -g 4
Suppose an error shows up in a log file:
tail -1F /your/log/file | grep --line-buffered 'ERROR' | espeak
Or perhaps you want a speaking clock telling you every minute what time it is:
while true; do date +%S | grep '00' && date +%H:%M | espeak; sleep 1; done
As you can guess, use cases are limited only by your imagination. Enjoy your new talking Fedora system!

Friday, July 14, 2017

Firefox: usare la CNS su Fedora

La presente guida ha funzionato per me, su Fedora 26. Probabilmente è valida per altre distribuzioni di GNU/Linux (usando il gestore di pacchetti opportuno).
Guida per modo di dire, poiché i passi da seguire sono veramente semplici.
Alla fine del conto per installare il lettore e la Carta Nazionale dei Servizi (o Tessera Sanitaria), la procedura descritta sul sito della Regione Toscana  si rivela macchinosa e inutile.
Viene qui usato un lettore di smartcard B4ID
La carta invece è quella che sul sito della Regione viene identificata come modello 2 (AT2012).


Installare i pacchetti

Installate PC/SC Lite (Middleware to access a smart card using SCard API)

sudo dnf install pcsc-tools

Collegate il lettore e lanciare il comando:

pcsc_scan -n

Inserite la carta nel lettore. Dovrebbe apparire qualcosa del genere:

Fri Jul 14 19:51:49 2017
Reader 0: ACS ACR 38U-CCID 00 00
  Card state: Card inserted,
  ATR: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX X


Quindi ok, il lettore funziona.
Se non funziona: SPIPPOLATE.

Abilitate il servizio e fatelo partire:

sudo systemctl start pcscd
sudo systemctl enable pcscd.service


Installate OpenSC (Open source smart card tools and middleware):

sudo dnf install opensc

Firefox

Andate in Preferenze -> Avanzate -> Certificati
Quindi Dispositivi di Sicurezza
Pigiate sul tasto Carica
Come nome del modulo mettete quel che vi pare
Specificate quindi il percorso della libreria: /usr/lib64/opensc-pkcs11.so
Premete ok.

A questo punto dovreste vedere un nuovo device.


Inserendo la carta dovrebbe apparire il nominativo e il codice fiscale.


Premendo su Login dovrebbe venire richiesto il PIN della carta.

Ora potete
provare l'effettivo funzionamento collegandovi a un sito che richiede l'autenticazione via CNS, come per esempio https://accessosicuro.rete.toscana.it (dove trovate, fra l'altro, il Fascicolo Sanitario elettronico), oppure https://iris.rete.toscana.it/ (per i pagamenti online della Regione Toscana). oppure il sito dell'INPS.

Con la tessera sanitaria è anche possibile richiedere le credenziali SPID, il Sistema Pubblico di Identità Digitale: https://www.spid.gov.it/richiedi-spid#altre-modalita

Wednesday, July 12, 2017

How to install Fedora 26 on the Raspberry Pi (Headless and Wireless)

The Raspberry Pi is the most famous SBC (Single-Board Computer). It is a recent news that over five millions of units were sold since it came out.

There are a lot of Linux-based and not Linux-based operating systems that runs on the Raspberry: Fedora is one of the latest landed in this platform. Due to this fact, many things still don’t work: for instance, according to what you can read on the Fedora wiki, expansion HATs, composite TV out, analog sound port and the add-on camera are not yet supported; support for displays other than the official one is not currently planned, GPIO isn't well supported. In addition Fedora supports only Pi version 2 and later.
Obviously the Raspberry Pi Foundation recommends the use of Raspbian, a Debian-based Linux operating system. And as stated before, there are many distributions that have been around for a long time, therefore they probably work better on such platform. Compared to the rest of the world Fedora on ARM could look at early stages of development.
Then, due to these facts the question could be: why using Fedora on the Raspberry Pi when there are more feature rich and widely used distributions? The answer is: isn’t Fedora our favorite distro? So let’s give a try to the ARM version.
Side note: ARM is an architecture officially supported by Fedora.

Let’s get started.


Preparing the SD card

The installation of the Fedora ARM image on an SD card is simple as these two steps:

- download the raw image of your choice (in this case Minimal) from https://arm.fedoraproject.org/

- run this command (supposing you are running Fedora on your PC and that you have installed the fedora-arm-installer package via DNF)

sudo arm-image-installer --image=Fedora-Minimal-armhfp-26-1.5-sda.raw.xz --target=rpi3 --norootpass --resizefs --media=/dev/mmcblk0 -y

Please refer to the Fedora wiki.

Such command will blanks the root password (remember to subsequently set one during first setup) and it will automatically resize the root partition in order to fill up the SD card size.

Once done, remove the SD card from your PC.

The serial console

If you do not have an HDMI screen to connect to the Raspberry Pi, or if you want to run a completely headless box, you have to enable the serial console.

The task is different between the Raspberry 2 and 3. These steps are for the version 3:

- insert the SD card in your PC, it should automatically mount three partitions

- edit the file extlinux.conf

sudo vim /run/media/youruser/__boot/extlinux/extlinux.conf

add "console=tty0 console=ttyAMA0,115200" to the end of the append line

append ro root=UUID=<uuid-uuid> console=tty0 console=ttyS0,115200

- edit the config.txt file in the root partiton

sudo vim /run/media/youruser/sometinglike-4AC9-BABE/config.txt
uncomment the enable_uart line:

enable_uart=1

The onboard wifi adapter

If you want to enable the onboard WiFi adapter, you have to download a file that Fedora can not currently redistribute in the raw image:

sudo curl https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/master/brcm80211/brcm/brcmfmac43430-sdio.txt -o /run/media/youruser/__/lib/firmware/brcm/brcmfmac43430-sdio.txt
 

Booting the Raspberry

Umount the three partitions, using something like

umount /run/media/youruser/__boot ; umount /run/media/youruser/__ ; umount /run/media/youruser/sometinglike-4AC9-BABE

Then insert the SD card in the Raspberry Pi, connect an Usb to Serial/TTL Adapter (the pin 8 on the Raspberry is the TX and pin 10 is the RX). Then power up the device.

You can look at the boot process using a terminal emulator program like minicom or GTKterm, or even the simple screen command:

screen  /dev/ttyUSB0 115200

Once the boot process will reach the end, you should see the Fedora initial setup where you can create an account, set the root password, configure the timezone, etc.

As soon as you log in, if the Raspberry is connected to the network using the Ethernet interface, and there is a DHCP server in the LAN, you are almost done. Check if you are really online and perform a system update:

sudo dnf update

Setup the wifi

If for some reason you can’t use the Ethernet interface and you need to connect to the WiFi network, you have to configure the wireless interface using the Network Manager command line interface (nmcli).

For instance, if your network uses WPA or WPA2, and there is a DHCP this task is pretty simple:

nmcli radio

nmcli device wifi connect YOURSSID password secretpassword

If you need to set up a static IP there are instead various steps to perform:

Add a connection profile and set the IP/netmask and the default gateway

nmcli con add con-name ConnectionName ifname wlan0 type wifi ssid YOURSSID ip4 192.168.100.200/24 gw4 192.168.100.1

Set up the DNS

nmcli con modify ConnectionName ipv4.dns "8.8.8.8 8.8.4.4"

Configure the wireless security (in this case wpa-psk) and the password

nmcli con modify ConnectionName wifi-sec.key-mgmt wpa-psk

nmcli con modify ConnectionName wifi-sec.psk verysecurepassword

Now you can bring up the connection:

nmcli con up ConnectionName

Conclusion

Here we have an headless and wireless Raspberry Pi 3 running our favorite GNU/Linux distribution!

Please refer to the Fedora Project wiki for more and up to date informations:
https://fedoraproject.org/wiki/Raspberry_Pi

Saturday, May 20, 2017

rpmbuild random notes

sudo dnf install rpmdevtools

rpmdev-setuptree

~/rpmbuild/SRPMS/
~/rpmbuild/SPECS/
~/rpmbuild/SOURCES/
~/rpmbuild/RPMS/
~/rpmbuild/BUILD/
~/.rpmmacros

sudo dnf download --source package

Monday, March 6, 2017

Tuesday, February 21, 2017

Oracle Database Appliance: random notes

How to create a shared repository

[root@oda11 ~]# oakcli create repo shared1 -dg data -size 50G

How to import a VM template

You must/can download a template from edelivery.oracle.com
You need to put the template or the assemly inside the DOM0, then import it from ODA_BASE.
[root@oda11 ~]# oakcli import vmtemplate prova -assembly /tmp/OVM_OL7U2_x86_64_PVHVM.ova -repo shared1 -node 0

How to create a VM

[root@oda11 ~]# oakcli clone vm pigna -vmtemplate prova -repo shared1 -node 0

How to create a vdisk

A vdisk that will be attacched to the VM
[root@oda11 ~]# oakcli create vdisk pignadiskl -repo shared1 -size 5G -type local

How to create a cpupool

The same pool name must be configured on each node.
[root@oda12 ~]# oakcli create cpupool provapool -numcpu 2 -node 1
[root@oda12 ~]# oakcli create cpupool provapool -numcpu 2 -node 0

How to configure the VM

Add two network interfaces

[root@oda11 ~]# oakcli configure vm pigna -network "['type=netfront,bridge=net1','type=netfront,bridge=net2']"

Enable failover

[root@oda11 ~]# oakcli configure vm pigna -failover true

Attach an additional disk

[root@oda11 ~]# oakcli modify vm pigna -attachvdisk pignadiskl

Configuring cpupool

[root@oda11 ~]# oakcli configure vm pigna -cpupool provapool

Starting the VM

[root@oda11 ~]# oakcli start vm pigna

Attacching to the console

You must ssh to the ODA_BASE using -Y flag.
[root@oda11 ~]# oakcli show vmconsole pigna
A VNC session will start

Expanding the disk space from inside the VM

This is the vdisk created before.
[root@pigna ~]# btrfs device add /dev/xvdb /
You can attach additional vdisks, and the VM OS will see them without the need to reboot it.

Adding space to the repo

[root@oda11 ~]# oakcli configure repo shared1 -incsize 25G

Monday, November 28, 2016

rsyslog gnutls: could not load module

Starting rsyslog with gnutls configured I got this error:

Nov 27 21:57:03 prometeo rsyslogd-2068: could not load module '/usr/lib64/rsyslog/lmnsd_gtls.so', rsyslog error -2078 [try http://www.rsyslog.com/e/2068 ]

The suggested link is not useful as the description (module could not be loaded - init failed) is too generic.

The problem here was that in the config file, the line DefaultNetstreamDriverCAFile was pointing to a non existent file.


Thursday, March 24, 2016

Arduino IDE and persistent serial port (Linux)

In the development of a little project with Arduino, I have to plug and unplug the USB cable a lot of times.
And I have a big annoyance: every time I plug the USB cable again, the port name changes from /dev/ttyUSB0 to /dev/ttyUSB1 and vice versa. So, in the IDE I have to go in Tools -> Port menu and select the right serial port every time before uploading the new sketch.
What a bore!

I've found this post, but the Arduino IDE seems that doesn't detect fancy names like /dev/arduino, but only names starting with "tty".

So my solution, in order to get a persistent name, is based on the http://hintshop.ludvig.co.nz/ blog post, but using a different port name:

sudo vi /etc/udev/rules.d/98-usb-serial.rules

SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ttyUSB10"

Reload udev rules with:

sudo udevadm control --reload-rules -R

Now in the IDE you can select this port and it never change every time you unplug and plug the USB cable.

Sunday, June 7, 2015

How-To: Ubuntu Kiosk

How-To: Ubuntu Kiosk

This article first appeared in Full Circle Magazine, issue #93.


If you work in a place open to the public, for example a library or a hospital, sometimes it could be useful to provide a computer to the visitors. Such a computer, even if equipped with a mouse and a keyboard, must be configured in a way that people should not be able to use all the system functions, but only a limited set of them. For instance, people could use the computer to access the Internet, or only an internal website providing information related to your company or your activity. And you must configure the system in order to prevent shell access, and inhibit the launch of all the other programs you don't wish to offer to the visitors.

Such a computer is a kiosk. (http://en.wikipedia.org/wiki/Interactive_kiosk).

You can eventually configure a PC attached to a large TV, without keyboard and mouse, in order to show information slides or videos. To achieve this last goal, you can take a look to Xibo instead, which is a digital signage content management system (http://xibo.org.uk/).

Installing

Let's start with installing Ubuntu server 14.04 LTS. Why Ubuntu server? Well, because, in your kiosk, you don't need a lot of software. Also note the use of the –no-install-recommends parameter used with apt-get.

Please keep in mind that after the configuration of the kiosk environment, it is supposed that you will access the computer from SSH, and not from the terminal.

So, let's install Ubuntu, enabling automatic security updates and installing Openssh server.

After the first reboot, log in as the (administrator) user you have created during the installation and then upgrade the system:

sudo apt update
sudo apt upgrade 

And install these packages:

sudo apt install --no-install-recommends xorg openbox firefox xscreensaver plymouth-theme-sabily cups 

Install CUPS if you plan to allow printing to your visitors.

Create a user, the kiosk user.

sudo useradd -m kiosk  
sudo mkdir /opt/kiosk

Set up the environment

In this configuration, you will not launch a desktop manager, but you will invoke X11 and start only the Firefox executable.

sudo vi /opt/kiosk/kiosk.sh

#!/bin/bash 
home_tar="/opt/kiosk/kiosk_home.tar"  
rewritehome() {         
  echo $home_tar         
  if [ -f $home_tar ]         
  then                 
    rm -rf $HOME/*                 
    tar xvf $home_tar -C /         
  fi
}  
xset -dpms 
xset s 
off openbox-session &
rewritehome
xscreensaver -nosplash &
while true; 
do         
  rewritehome         
  /usr/bin/firefox 
done

The script shown above will be invoked by upstart when the system boots up. It essentially replaces the kiosk user home directory before starting Firefox. And the Firefox executable is placed inside a loop, in order to relaunch it whenever it is closed.

sudo chmod +x /opt/kiosk/kiosk.sh

Now you need to create an upstart script:

sudo vi /etc/init/kiosk.conf 

start on (filesystem and stopped udevtrigger)  
stop on runlevel [06]  
console output
emits starting-x  
respawn  
exec sudo -u kiosk startx /etc/X11/Xsession /opt/kiosk/kiosk.sh

Since X needs root privileges to start, you need to issue this command and select “Anybody”.

sudo dpkg-reconfigure x11-common 

At this point we are nearly finished. You need to reboot the machine.

sudo reboot 

And Firefox should start automatically.

Make the desired changes now, like adding CA certificates, security devices, adding some kind of extensions, etc.

Finally you need to install the srkiosk extension https://addons.mozilla.org/en-US/firefox/addon/srkiosk/

Please carefully read the documents (http://blogoless.blogspot.it/2012/07/firefox-srkiosk-add-on-full-screen.html), in order to understand this handcrafted item and better suit it to your needs, like changing the home page, or showing the address bar.

Close Firefox. At this point Firefox will restart in a locked-down kiosk mode.

To continue the configuration, you have to remotely log in via SSH.

Last steps.

The use of the screensaver can be useful – not only to have a nice effect on the screen after an amount of time. It is useful to “reset” the session after a period of inactivity. For instance, it is nice to go to the home page, instead of leaving the kiosk in the last visited page by the last user. So you need to configure the screensaver only if you need to reset your kiosk periodically.

Place the xscreensaver configuration file in the kiosk user home directory. The timeout option is the one you need to change in order to suit your needs (in this example the kiosk will be reloaded every quarter of an hour).

sudo vi /home/kiosk/.xscreensaver

timeout:        0:15:00 
lock:           False 
verbose:        False 
splash:         False 
captureStderr:  True 
dpmsEnabled:    False 
dpmsQuickOff:   False 
mode:           one 
selected:       0 
programs: resetkiosk.sh -root 
\n\

Next, you need the script that xscreensaver will invoke after the period of inactivity (Listing 4). As said, xscreensaver, instead of launching a real screen saver, will actually run this script.

sudo vi /usr/lib/xscreensaver/resetkiosk.sh
#!/bin/bash
PID=`ps -u $UID -f |grep firefox |grep -v grep | awk '{ print $3 }'`
kill $PID

Snapshot Time

Finally, you need to take a snapshot of the kiosk user home directory. Such snapshot will overwrite the home directory every time the machine reboots, or when the kiosk session is reset, or when Firefox is closed.

So, remember that every time you make changes to the kiosk user home directory, you will need to make a tar of that directory, and place it in the appropriate place: take a look at the kiosk.sh script (previous page, top right).

rm -rf /home/kiosk/.cache/  
tar cpvf /opt/kiosk/kiosk_home.tar /home/kiosk/  

Configuring GRUB and disabling ttys  

Another useful task to accomplish is related to some hardening of the system. For instance, you can prevent naughty users from booting the system into single-user mode, or from switching between virtual consoles (the terminals you can use by pressing functions keys like CTRL+ALT+F1).  Let's start with GRUB. First of all, it needs to be as quiet (less verbose) as possible, just for aesthetic purposes (Listing 5).

sudo vi /etc/default/grub

... 
GRUB_TIMEOUT=0 
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=current loglevel=0"
...

Then, you can set a password in order to disallow users to boot Linux into single-user mode. Use the command grub-mkpasswd-pbkdf2 to create an encrypted password, then edit some files.  Put the following lines at the end of /etc/grub.d/00_header

cat << EOF  
set superusers="root"
password_pbkdf2 root  <the_sting_obtained_from_the_grub-mkpasswd-pbkdf2_command>
EOF

At this point, a user and a password will be requested for each GRUB menu entry, even for booting Linux in the normal way; that is what we don't want. So add the –unrestricted parameter (shown below in black) in each menuentry line of the configuration files. For instance in /etc/grub.d/10_linux

...
   echo "menuentry '$(echo "$title" | grub_quote)'  --unrestricted ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s    /^/$submenu_indentation/"
else
   echo "menuentry '$(echo "$os" | grub_quote)'  --unrestricted ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu    _indentation/"
...

In this way, a user and a password will be asked only if the user tries to edit the GRUB menu entries, using the 'e' key.

Now you must issue the sudo update-grub command to make the changes effective.

At the end, you can disable virtual terminal consoles by deleting the tty files under the /etc/init directory:

sudo rm /etc/init/tty*

Further works and conclusion 

In order to harden the machine, you should set up a password in the BIOS, and prevent boot from CD/DVD or USB ports. And about USB, you should prevent the use of such ports at least by making the PC inaccessible from the users.

Other things to do? Configure a custom theme for the boot screen. Look at ways to disable possible keyboard shortcuts.

Instead of running Firefox, you might wish to run a video player or a pictures slide-show: you can give it a try by putting some other command in the while loop.

This paper is based on a post found on https://thepcspy.com/read/building-a-kiosk-computer-ubuntu-1404-chrome/

Maybe a kiosk solution could be better achieved, but as far as I know, I have not found any better alternatives. This solution works for my needs: maybe it could be useful to you or it could be a starting point for a better implementation.


Friday, November 21, 2014

mysql-workbench issues on Ubuntu 14.10

Since the Ubuntu 14.10 installation I am no more able to use mysql-workbench.


Data grid not displaying resultset is blank

https://bugs.launchpad.net/ubuntu/+source/mysql-workbench/+bug/1376154

 
Unable to connect to remote MySQL server via SSH using MySQLWorkbench 

Thursday, July 31, 2014

"Bundled JRE is not binary compatible with host OS/Arch or it is corrupt. Testing bundled JRE failed."

I was installing SUN STORAGE COMMON ARRAY MANAGER SOFTWARE 6.9, LINUX on a Centos 6 installation.
Such Centos 6 server was installed using the SmartOS image.

Running the script

./HostSoftwareCD_6.9.0.16/RunMe.bin -c

I got
 
"Bundled JRE is not binary compatible with host OS/Arch or it is 
corrupt.  Testing bundled JRE failed."

I've solved in that way:

yum install glibc.i686

Monday, April 28, 2014

Apache Directory Studio "A fatal error has been detected by the Java Runtime Environment"

Ubuntu 14.04 64 bit
oracle-java7

Apache Directory Studio (ApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628.tar.gz)

When I start the program from the command line (./ApacheDirectoryStudio), I get an error like this:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f518c1502a1, pid=18722, tid=139989739792128
#
# JRE version: Java(TM) SE Runtime Environment (7.0_55-b13) (build 1.7.0_55-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.55-b03 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libsoup-2.4.so.1+0x6c2a1]  soup_session_feature_detach+0x11
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /opt/ApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628/hs_err_pid18722.log
[thread 139988370728704 also had an error]
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#



To solve this issue, try to put this line

org.eclipse.swt.browser.DefaultType=mozilla

at the end of this file

configuration/config.ini

Wednesday, August 7, 2013

nsca and send_nsca version incompatibility

I have a Nagios NSCA server running on Debian squeeze. The installed nsca package is the 2.7.2

I want to send passive nagios checks from a SmartOS zone. But the pkgsrc version of nsca client package is 2.9.1

There are incompatibility issues between the 2.7 server 2.7 and a 2.9 client (example http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=670373).

Dropping packet with invalid CRC32 - possibly due to client using wrong password or crypto algorithm?

To resolve the problem without upgrading Debian to a newer release, you can use backports.
Following the instructions I've added a new source to apt

vi /etc/apt/sources.list.d/backports.list

deb http://mi.mirror.garr.it/mirrors/debian-backports squeeze-backports main

apt-get update

And I've installed the newer version of NSCA server.

apt-get -t squeeze-backports install nsca

Now the latest version of send_nsca available on SmartOS works.

Quick testing shows that the 2.7.2 clients seems to work with the 2.9.1 server.

Thursday, March 14, 2013

iPxe server (on CentOS) to serve SmartOS

This document talks about how I set up an iPXE server on CentOS 6 mainly to serve SmartOS.
Although I've not understood some things (like undionly or the fact that there are many dhcp requests from the pxe client) the following procedure works for me

Links

Install dhcp and tftp services

yum install dhcp.x86_64
yum install tftp-server.x86_64 

Get iPXE undionly


cd /var/lib/tftpboot/
curl http://cuddletech.com/IPXE-100612_undionly.kpxe > undionly.kpxe 
curl http://boot.ipxe.org/undionly.kpxe > undionly.kpxe

Download iPxe

Optional.
Useful to get some network modules if the client uses gPxe (like KVM one) that is unable to work with iPxe
cd /root
mkdir git
cd git/
git clone git://git.ipxe.org/ipxe.git
cd ipxe/src
make
make bin/ipxe.pxe
cp bin/ipxe.pxe /var/lib/tftpboot/
  
 

DHCP Configuration

It is useful to configure the DHCP server to provide IP addresses only to known MAC addresses. I think it is also useful to link MAC addresses with IP addresses. So a server always get the usual IP.

Note: 192.168.56.10 is the TFTP server (may be the same server as DHCP)

vi /etc/dhcp/dhcpd.conf
ddns-update-style none;

option domain-name "my.domain";
option routers 192.168.56.1;
option domain-name-servers 192.168.56.2, 192.168.56.3;

default-lease-time 600;
max-lease-time 7200;

log-facility local7;

subnet 192.168.56.0 netmask 255.255.255.0 {

   deny unknown-clients;
   next-server 192.168.56.10;

   host hcn2 {
      hardware ethernet 00:19:99:e0:87:30;
      fixed-address 192.168.56.20;
      if exists user-class and option user-class = "iPXE" {
         filename = "menu.ipxe";
      } else {
         filename = "undionly.kpxe";
      }
   }

}

Configuring iPXE

vi /var/lib/tftpboot/menu.ipxe
#!ipxe

######## MAIN MENU ###################
:start
menu Welcome to iPXE's Boot Menu
item
item --gap -- ------------------------- Operating systems ---------------
item smartos    Boot SmartOS (platform-20121228T011955Z)
item --gap -- ------------------------------ Utilities ------------------
item shell      Enter iPXE shell
item reboot     Reboot
item
item exit       Exit (boot local disk)
choose --default smartos --timeout 30000 target && goto ${target}

########## UTILITY ITEMS ####################
:shell
echo Type exit to get the back to the menu
shell
set menu-timeout 0
goto start

:failed
echo Booting failed, dropping to shell
goto shell

:reboot
reboot

:exit
exit

########## MENU ITEMS #######################
:smartos
set base-url ${boot-url}/images/smartos/20130111T010112Z/platform/i86pc
kernel ${base-url}/kernel/amd64/unix -v -B console=text,smartos=true
module ${base-url}/amd64/boot_archive
boot || goto failed
goto start

Preparing the SmartOS image

From the SmartOS wiki:
There are 2 files of importance, the kernel ("unix") and the boot archive ("boot_archive"). The paths to these files are significant and should not be omitted. They should be:
  • (prefix)/platform/i86pc/kernel/amd64/unix
  • (prefix)/platform/i86pc/amd64/boot_archive
The prefix may be anything you wish (a common prefix would be "/tftpboot/smartos/20121004T212912Z/") but the path after the prefix must be in the form above. If you do not the OS will fail to boot with an error saying "krtld: error during initial load/link phase"; in this case the image make sure your path is in the proper form. The important point being, don't just untar the latest platform image into your TFTP directory and boot it, you'll have problems unless you change the typical "platform_20121004T212912Z/" to simply "platform/".

So:

cd /var/lib/tftpboot/
mkdir images
cd images/
mkdir smartos
cd smartos
curl https://download.joyent.com/pub/iso/platform-latest.tgz > /tmp/platform-latest.tgz
cat /tmp/platform-latest.tgz | tar xz
ls | grep platform- | sort | tail -n1
platform-20130111T010112Z
mv platform-20130111T010112Z 20130111T010112Z
cd 20130111T010112Z/
mkdir platform
mv i86pc/ platform/

Please note: change 20130111T010112Z with the current version

Configuring iptables

To allow DHCP

vi /etc/sysconfig/iptables-config
IPTABLES_MODULES="ip_conntrack_tftp"

vi /etc/sysconfig/iptables
-A INPUT -m udp -p udp --dport 67:68 --sport 67:68 -j ACCEPT
-A INPUT -m tcp -p tcp --dport 69 -j ACCEPT
-A INPUT -m udp -p udp --dport 69 -j ACCEPT
/sbin/service iptables restart 

Configuring xinetd

To enable TFTP

vi /etc/xinetd.d/tftp
...

        disable                 = no

...
 
/etc/init.d/xinetd restart
 
 
 

Friday, February 15, 2013

linux scp and umask

I use CentOS 5.x
The problem is that if I use scp or sftp to copy a file on such CentOS server, the umask is not taken in consideration.
Behavior of scp and sftp is different.

Btw, a solution is to use openssh 5, but I don't like to alter the distribution, since CentOS 5 install openssh 4.

Using google I've found different solution (pam? etc.) but no one works for me.

So, a way to make what I want is:

For sftp

vi /etc/ssh/sshd_config
...
# override default of no subsystems
# Subsystem       sftp    /usr/libexec/openssh/sftp-server
Subsystem sftp /bin/sh -c 'umask 0002; /usr/libexec/openssh/sftp-server'

and restart sshd


And for scp

vi /home/myuser/.bashrc




adding (0002 or what you want)

umask 0002

Friday, January 4, 2013

linux: printing pdf in booklet format

I have a 44 pages PDF. I like trees. I want to save money.

So I want to print a booklet (page 1 and 44 on paper 1 side A, page 2 and 43 on paper 1 side B, etc.) from Ubuntu. I can't find the right way to accomplish this from Document Viewer (Evince?).

sudo apt-get install psutils

pdftops -nocrop -paper A4 -expand origin.pdf test.ps

psbook test.ps test-book.ps

psnup -2 test-book.ps test-book2.ps

We use the last command to put 2-pages together.
Note:  /etc/papersize is consulted, so it is better to set a different page size, using psnup -pa4


References:
https://sites.google.com/site/ocastillofelisola/Home/linux-stuff/convertingpsfilesintobooklets
http://ubuntuforums.org/archive/index.php/t-1210934.html

Thursday, December 13, 2012

nagios linux software raid plugin

Until now, I was using Hari Sekhon 0.7.2 check_md_raid plugin to monitor Centos software disk RAIDs.

There was an issue: in Centos there is a weekly cron job /etc/cron.weekly/99-raid-check that resync all the md raid devices.
So every weekends there were Nagios warnings for each Centos linux server about unclean md status, until resync finished.

Not so nice.

So I switched to a plugin found under the contrib directory of official Nagios plugins: /usr/lib64/nagios/plugins/check_md_raid

command[check_raid]=/usr/lib64/nagios/plugins/contrib/check_linux_raid.pl

Friday, October 19, 2012

centos kvm console

To enable console access from the host command line to a CentOS guest, this was an useful link

Thursday, October 18, 2012

Centos 6: bridge vlan and bond

/etc/sysconfig/networking/devices/ifcfg-em1
/etc/sysconfig/network-scripts/ifcfg-em1

DEVICE=em1
BOOTPROTO=none
HWADDR=78:2b:cb:xx:xx:xx
ONBOOT=yes
MASTER=bond0
SLAVE=yes
TYPE=Ethernet
IPV6INIT=no
USERCTL=no


/etc/sysconfig/networking/devices/ifcfg-em1
/etc/sysconfig/network-scripts/ifcfg-em2

DEVICE=em2
BOOTPROTO=none
HWADDR=78:2b:cb:yy:yy:yy
ONBOOT=yes
MASTER=bond0
SLAVE=yes
TYPE=Ethernet
IPV6INIT=no
USERCTL=no


/etc/sysconfig/networking/devices/ifcfg-bond0
/etc/sysconfig/network-scripts/ifcfg-bond0


DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
BONDING_OPTS="mode=4 miimon=100 lacp_rate=1"
TYPE=Ethernet
IPV6INIT=no
USERCTL=no
NOZEROCONF=yes



/etc/init.d/network restart

vconfig add bond0 11
brctl addbr brvlan11
brctl addif brvlan11 bond0.11


/etc/sysconfig/network-scripts/ifcfg-bond0.11

DEVICE=bond0.11
ONBOOT=yes
BRIDGE=brvlan11

VLAN=yes


/etc/sysconfig/network-scripts/ifcfg-brvlan11

DEVICE=brvlan11
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=static
IPADDR=10.96.11.40
NETMASK=255.255.255.0
GATEWAY=10.96.11.1

VLAN=yes
STP=on
DELAY=0



On the HP switch

configure

trunk 3-4 Trk4 LACP

vlan 11
tagged Trk4
end