BIPEDU

my ideas in action

update PiHole (inside VM on Freenas)

The PiHole need some updates , from time to time, so is best to setup a cron job to do them automatically. The Pihole updates cannot, at this time , be made form Web interface. In my case Pihole runs inside a VM (ubuntu server) , inside Freenas.

So you need to enter the VM shell , inside your Freenas machine. Open Freenas web interface, then go to VMs –> Pihole –> VNC via web .

Then at the new terminal , after login, you need to sudo a crontab:

sudo crontab -e

Then in crontab editor write this :

5 1 * * * pihole -g -up

15 1 * * * pihole -up

This means that at 1:05am every day the pihole list of ad-serving domains is updated. Then at 1:15am the pihole is updated.

If you want to see the pihole status in real time then use

pihole -c

Screenshot from 2018-12-12 09-21-35

 

 

 

 

Advertisements

recover and boot a VM inside Freenas 11

I made recently a VM inside Freenas with Ubuntu and Pi-Hole to get out some advertisements from my network.

All was configured as described here :

 

The main problem that remains is that after a restart of the VM  ( ubuntu) the system does not reboot correctly. I did not entered in details about the boot process of the VM inside Freenas but apparently is an issue with the EFI file location. The longer explanation is given here :

https://forums.freenas.org/index.php?threads/ubuntu-vm-reboots-to-limited-shell.62558/

https://forums.freenas.org/index.php?threads/howto-how-to-boot-linux-vms-using-uefi.54039/

So … how to fix it ?

first you need to open the VNC to the VM machine ( ubuntu in this case). Then you type “exit”  to get from shell to the EFI menu system and navigate to “Boot Maintenance Manager” and then select “Boot from file” to locate and select your grubx64.efi file.

After booting, execute this command as root (use sudo !!):

grub-install –efi-directory=/boot/efi –boot-directory=/boot –removable

then after reboot of the VM you get back the VNC terminal.

If your VM restarted correctly then it is fine.

If not, then you have to copy some files to be sure that the reboot will happen next time also.

More specifically you have to copy the grubx64.efi from /boot/efi/EFI/ubuntu to /boot/efi/EFI/BOOT.

Do this as root (use sudo !!!) :

cp /boot/efi/EFI/ubuntu/grubx4.efi  /boot/efi/EFI/BOOT/grubx64.efi

cp /boot/efi/EFI/ubuntu/grubx4.efi  /boot/efi/EFI/BOOT/BOOTX64.EFI

 

NB: If grubx64.efi gets updated you will need to re-create bootx64.efi.

So if the VM ubuntu make an automatic update of the grub utility then you may get the VM(ubuntu+PiHole) not restarting correctly. If you do not reboot ever the Frenas and VM then you are fine, but if you get regular restarts ( updates or maintenance) then please remember to do all this steps again.

Unfortunately I do not have yet a permanent fix.

 

For making updates to the VM machine ( ubuntu , in my case) it is better to apply only the security patches and for that is better to use

sudo unattended-upgrade

and not the classical apt-get

sudo apt-get update

sudo apt-get upgrade

 

 

 

 

 

use ffmpeg to edit videos

I want to show here how to produce a video and what are the steps to post-production.

All these are using free and open source software. No need to be expert in computers , only a little bit of courage.

You can use this recipe for homemade videos that you post online, for your vlog/blog or whatever.

I use ffmpeg and Inkscape that are available for Linux and Windows also.

As a general rule, if you have Linux/Unix, then please use the RAM since it is faster (read/write in /tmp folder always for all temporary files).

 

These are the steps :

1= record the video + audio

use a decent camera (preferable HD or 4K) with preferable audio . DSLR is OK also.

If your camera do not have good audio recording from builtin mic, then record the audio separate and clap in front of camera so that you can synchronize video/audio in post-production. Preferably use an external microphone ( ex. lavalier) as close as possible of the sound source. A cheap and good lav mic is Boya BM-M1 (see Amazon)

You can also record with a smartphone but be aware that the sample rate may be 44100 instead of 48000 as camera will record. This may produce audio that is not in sinc with video.

During recording please keep 5-10 seconds of silence , because you may need it later to do some noise reduction (see next step)

2= extract the audio separated and do some processing (if necessary)

Personally I use Audacity ( free and open source) .

I import audio and I do mainly two operations : Noise reduction and Compression. I use default settings from Audacity .. are ok for most cases. In case the audio sample rate is on 44100 then it is preferable to change it to 48000 to match the video.

Save the audio as WAV ( 16bit) in 48000.

3= then replace the video old audio with the new audio (new audio is with noise reduction)

3.1 = strip the audio from the video

ffmpeg -i /tmp/DSC_0009.MOV -an -c:v copy -c:a copy /tmp/p1.mov

3.2 = add new audio to the video

ffmpeg -i /tmp/p1.mov -i /tmp/DSC_0009.wav -vcodec copy -acodec copy /tmp/p2.mov

 

4= cut the video to the correct size

play first the new video and check the quality and note on paper the moments you want to save. For example : from 00:01:12 till 00:25:48 (hh:mm:ss format)

use example : cut from 20 sec till 9min and 36sec :

ffmpeg -i /tmp/p2.mov -vcodec copy -acodec copy -ss 00:00:20 -to 00:09:36 /tmp/p3.mov

5= (optional) add some logo/title/watermark

5.1 = Create the logo

With Inkscape (free and open source) create a image that has the same format as the video. Example if video is HD 1920*1080 then create a page that is 1920*1080. On this place your logo/watermark / artwork and preferable use alpha (transparency) to get more effect. Save the work and export it to PNG and keep the transparency.

5.2 = Overlay the PNG image to the video with ffmpeg

ffmpeg -i /tmp/p3.mov -loop 1 -i /tmp/TitleFile.png -filter_complex “[1:v]fade=in:st=0:d=0.1:alpha=1,fade=out:st=9:d=1:alpha=1[png];[0:v][png]overlay=x=0:enable=’between(t,0,10)'” -b:v 2000k -bufsize 2000k /tmp/p4.mov

Here I overlay the PNG image from second 0 ( st=0) in 0.1sec (d=0.1) and then fadeout starting at second 9 (st=9) for 1 second (d=1). The entire overlay is from seconds 0 to 10 ( see : between(t,0,10) ). Then I also force bitrate to be 2Mb/s (-b:v 2000k -bufsize 2000k) to avoid too much loss of quality. If not the ffmpeg will reduce the bitrate even more and it may be too low.

 

6= (optional) add a static picture at the final with credits/ links/Thanks or other announcements

6.1 = use Inkscape to create a closing image. Same as before, can use transparency (alpha) .

6.2= use ffmpeg to create and concatenate the image at the end of the video:

ffmpeg -i /tmp/p4.mov -loop 1 -framerate 30 -t 5 -i /tmp/Closing.png -f lavfi -t 0.1 -i anullsrc=channel_layout=stereo:sample_rate=48000 -filter_complex “[0:v][0:a][1:v][2:a]concat=n=2:v=1:a=1” -b:v 2000k -bufsize 2000k /tmp/final.mov

options :

framerate=30 : need to match the original framerate of your video ( if you shoot in 60FPS then use 60 here also)

t 5 : generate 5 seconds video that will show your Closing.png image

stereo : add stereo sound if youd video is stereo ( if not you can put mono)

sample_rate=48000 : use the same sample rate as your audio (other option is 44100)

 

7=(optional) post the video online ( Ex: Youtube, Vimeo……etc)

 

 

new lessons on analog CMOS design

Recently I’m working on some free lessons / courses on electronics.

More specifically on custom analog CMOS design.

I think is better to share my knowledge with others. I try to present detailed design with accent on the principle, methods and trade-offs.

My first is about designing a CMOS analog opamp , with full rail-to-rail inputs and outputs.

I go from easy to hard and I hope to be easy for everyone to understand reasons and the decisions that are made during design process.

 

For the moment I have only few 10 minutes video…. I will add more soon.

 

Good movies

Miss Sloane

Contratiempo – Spain 2016

Gone Girl (2014, with Ben Affleck) – tension, thriller

 

incremental backup of Freenas ZFS volume on external drive

When you have a Freenas  you need sometime to make a backup of the entire volume.

I have a external HDD drive ( connected with a  USB interface). I want to have a exact replica of the entire Freenas dataset so that I can store it on a remote location. The GUI menu from Freenas allow you to do this but as a scheduled replication task . This is nice if you have another NAS connected on the network. In my case I have just a external HDD (1TB) and I want to make a backup from time to time.

First connect external HDD on Freenas USB ports. Plug the cable and then from GUI go to Storage–> Volume–> import Volume.

In the new pop-up select the ZFS volume from your HDD. If you do not have a volume yet then you can create it from GUI .

Now you have to open a terminal because next commands are not possible from GUI.

So you can open the Shell from GUI Freenas  ( left side menu) or you can use a SSH to access directly the Freenas terminal.

In the Freenas terminal you need first to check if you see correctly the NAS volumes and also the new inserted external HDD volume.

zfs list –> to see all volumes available

then type :

zfs list -t snapshot –> to see what snapshots you have on your system.

First time when you make this transfer you will need to copy a lot of data since external HDD is empty . Do not worry because next time when you make backup only the difference data will be copied. So it will be much faster.

So first time do:

zfs snapshot -r data1/bsdshare@backup # create a snapshot
zfs send -R data1/bsdshare@backup | zfs receive -vF bkp_1T # transfer it over

where:

zfs snapshot = create a snapshot of the data

-r = snapshot is recursive

data1/bsdshare = my volume is “data1″ and dataset is”bsdshare”

backup = arbitrary name for my snapshot. (you can see it also in GUI on Storage–>Snapshot)

zfs send = copy the dataset

zfs receive = paste the dataset

bkp_1T = is the name I chose for my external HDD volume ( choose any name you like)

The zfs send/receive command take very long time  !! hours !! since will copy now the entire data. May be longer/shorter depending on the total data, HDD speed, USB interface..etc.

At the end , after the send/receive finished you can detach the external volume from GUI . Go to Storage–> Volumes, click on the “bkp_1T” and select “detach”.  Now you can unplug the external HDD and you are ready.

 

Next time when you want to update the data from external HDD you need to do the following. The idea is to make a incremental update so that you do not spend hours copying entire data again . For this we will do:

First plug the external HDD on USB port. ( Notice that Freenas do not require any reboot !!, all is live)
From GUI import volume . Go to Storage –> Volumes –> import volume. Select the volume from your HDD ( mine is called “bkp_1T”)

Now open again a terminal in Freenas ( from GUI menu or with SSH) and type:

zfs rename -r data1/bsdshare@backup   data1/bsdshare@backup_old

# rename the “old” snapshot made last time from “backup” into “backup_old”.

zfs snapshot data1/bsdshare@backup # take a new snapshot
zfs send -Ri data1/bsdshare@backup_old data1/bsdshare@backup | zfs receive -v bkp_1T # incremental replication

Notice that now we use -i and we add both snapshot ( old and new) for send command. Now only the delta between old-new will be copied to HDD so it should take seconds or minutes, not hours/days.

At the end check one more time ( from GUI or terminal) that sizes, disks and snapshots are ok . If OK then you can optionally cleanup the storage by removing the old snapshots from Freenas and also from external HDD.

zfs destroy -r data1/bsdshare@backup_old # get rid of the previous snapshot from Freenas
zfs destroy -r bkp_1T@backup_old # get rid of the previous snapshot from external HDD

At the end from GUI you can detach the external HDD ( Storage–> Volumes , click on volume and select detach)

That’s it !

 

use PAC file for automatic proxy selection

I will explain how to use automatic proxy selection for a local network.

For example let’s say that you have a proxy server but that proxy is not available all time. In this case the you need to find each time if the proxy is alive (available) and if yes to use it. If not then browser will select direct connection.

The easiest way to use it is to create a PAC file and to add it in the Firefox as automatic proxy selection.

Go to Preferences–>Advanced –> Network –>Settings and choose “Automatic proxy configuration URL”

Then type there the path to a local PAC file. Normally there should be a web page address but if the file is locals works also ( no web server needed)

FFsettings

To create the PAC file use any text editor and create a file called “autoproxy.pac” and put this content:

function FindProxyForURL(url, host)
{
return “PROXY 192.168.1.29:3128; DIRECT”;
}

The Proxy in this case is on local network at 192.168.1.29 (Squid Proxy on port 3128) and Firefox try to use it first . In case it is not responding it will use direct connection.

You can set there multiple proxy servers. The order is important.

In the example below you can have two proxies. If the first one (192.168.1.29) is not responding then the second one (192.168.1.42) will be selected, and if the second one also do not respond the direct network connection will be used.

function FindProxyForURL(url, host)
{
return “PROXY 192.168.1.29:3128; PROXY 192.168.1.42:3128; DIRECT”;
}

The name of the PAC file is not important ( “autoproxy.pac” is name used by me), any name will do.

More details regarding the PAC file , examples, more advanced functions can be found here : http://findproxyforurl.com/

 

 

 

Fixing “RPC: AUTH_GSS upcall timed out.” from dmesg ( Debian and other linux distro)

In case you see this in your dmesg then please read further. The issue is also giving slow connection ( first) time on a NFS share (takes ~30seconds ).

There is a bug (!?) in the NFS client configuration and it runs a module called rpcsec_gss_krb5.

You can check if this module is running with “lsmod”.

Solution : do not load the module :

as root type :

echo blacklist rpcsec_gss_krb5 > /etc/modprobe.d/dist-blacklist.conf

then reboot

Problem solved : fast connection on NFS share and no dmesg error message.

 

 

email me the result of a cronjob/script in Freenas

This is the simplest method to email the result of a command in Freenas.
For example if you run certain scripts with Cron you can use it also.

Personally I use this to get the SMART report about a HDD that may fail soon. So what I put in Cron this (all in one line) :

smartctl -a /dev/ada1 | /usr/bin/mail -s "MyFREENAS HDD /ada1 report " my.email@address.com

For user you can put “root” and any redirect should be off.

Of course to make the email work you have to configure the email server, ..etc… in the user config. Fill the settings here : System –> Email.

for all spammers in the world !