Showing posts with label COVID-19. Show all posts
Showing posts with label COVID-19. Show all posts

Friday, 24 July 2020

Fedora 32 on Google Cloud



Google doesn't provide a Fedora image for its cloud platform neither Fedora provides one. but this wont stop us. It is a nice learning and adventure for orthodox people like me.

Those who have started there career in Computer in late 80's and early 90's can understand my pain 😬

Well during this time of pandemic COVID-19 I thought of taking an adventure ride into the world of Virtualization. Though Virtualization is not new to me, as during my days at RedHat I did some virtualization stuff by porting drivers, but that is a very short lived assignment for me. Even I was fascinated by Vmware's ESX server Community edition. Even to tryout my toy Operating System NanoOS i need some platform to try out so Was using qemu and BOCHS.
But setting up a VM in a cloud is just a new thing for me. If you like to learn along and how to do it then read along.

Prerequisites 

As I don't know much about Windowz, will restrict to Google's cloud console as much as possible and at some times Linux desktop.
  • Google account
  • Machine with Fedora Desktop(any Linux distro will do but I like Fedora)
  • Google SDK for Linux installed on your machine.
Deploying a VM needs availability of an Image. Though there is no image for Fedora 32 but similar images are available for CentOS and RHEL. We could choose any but I would prefer CentOS over RHEL.

Plan of Action 
  • We will create a VM using CentOS image. This will be a very minimum one as we will use it for creating Fedora 32 image.
  • Download Fedora cloud image from Fedora download site
  • Tweek Fedora image to make it suitable for Google.
  • Upload the image
  • Create an instance of it 
Creating a VM 
Here you need a google account your Gmail Account wont work here. You need to have cloud permission in your account. Please refer to google site for procedure. its not difficult but its not relevant here hence omitted.

Similarly install Google cloud SDK (gcloud and gsutil). Information about the procedure is available on Google SDK site.
  • Login to Google cloud, the bellow screen will be displayed
  • Click on menu (3 horizontal line)

  • from drop down select Compute Engine

  • Next it will display a page with all vm instances if available. for us it should be empty. Next on the top there is an icon with a plus


  • Now a form will be displayed, it will ask to enter a name for your VM instance . We will put boiler-plate there. Dont worry about other options except Boot Disk.

  • On Boot Disk option by default it will be debian. There is a button change next to it. Clicking it will display several options.


  • On clicking change something like this will appear. We will select CentOS. On next screen it will ask which version to use. we will use CentOS 8 as it has dnf command. But If you prefere yum can choose other older versions too.





  • Allow it for some time say 5 Minutes. then on VM Instance page our new VM will be displayed.


Ok we have successfully created a VM on Google Cloud now we can enjoy it for some timeπŸ™† .Relax get a coffee and think what we have achieved.
After this point our journey will be some what tough as we will be doing some sysadmin job (yes SysAdmins are really great people They do a lot of hectic work to ease our life).

Click on ssh button at the end of the line of our newly created VM instance. It will open a newbrowser window with shell prompt of our VM. Check if all your commands are accepted or not.

Download Fedora cloud image

As we know there is no Google compatible image for Fedora available but Cloud images are available. We can download it and adjust  for Google compatibility. 
On the ssh terminal shell prompt check if wget is available or not. Else install it by using dnf or yum.

~]$ sudo dnf install wget

So go ahead and download  Fedora Cloud image. Choose raw image for convenience. Remember we are downloading into VM on google not onto our Desktop.

~]$ wget -c"https://download.fedoraproject.org/pub/fedora/linux/releases/32/Cloud/x86_64/images/Fedora-Cloud-Base-32-1.6.x86_64.raw.xz"

it will be downloaded to the home folder in VM. Give it some time as it is a long file , but don't worry it will be downloaded in few minutes say 2 to 3 minutes.

Preparing the image
Now the raw file is downloaded as *.tar.xz format. It has to be extracted  first 

~]$ tar -xvf Fedora-Cloud-Base-32-1.6.x86_64.raw.xz

It is better to copy this file to a smaller name like disk.raw and work on that.
  • mount the image

~]$ sudo losetup  /dev/loop0 disk.raw
~]$ kpartx -a /dev/loop0

mount the disk
$ sudo mkdir /mnt/disk
$ sudo mount /dev/mapper/loop0p1 /mnt/disk


  • Bind mount some filesytem

~]$ sudo mount --bind /dev /mnt/disk/dev
~]$ sudo mount --bind /sys /mnt/disk/sys
~]$ sudo mount --bind /proc /mnt/disk/proc

besides this another file has to be created that is /etc/resolv.conf content of that file is very small and as follows.

search domain.name
nameserver 8.8.8.8

Its now time to go into chroot
$ sudo chroot /mnt/disk
After chrooting check if ping works, that is if network works else adjust your network to work in chroot environment.

First thing to do is update the image. by
~]$ sudo dnf update

Next we have to install 
~]$ sudo dnf -y remove cloud-init
~]$ sudo dnf -y install google-compute-engine-tools
~]$ sudo dnf clean all

Now we are almost done. Google need some service to be enabled.
~]$ sudo systemctl enable google-accounts-daemon google-clock-skew-daemon \
    google-instance-setup google-network-daemon \
    google-shutdown-scripts google-startup-scripts

Well our Image is almost ready. Now we should leave chroot environment unbind and unmount the filesystems we have mounted earlier.

~]$ sudo umount /mnt/disk/dev /mnt/disk/sys /mnt/disk/proc
~]$ sudo umount /mnt/disk
~]$ sudo losetup -d /dev/loop0

In above steps, unmounting disk will throw "resource busy error" dont worry. Give it some time to finish writing stuffs, 5 to 10 minutes maximum. then unmount the disk and delete the loop0. We are done.
Google need its image to be in *.tar.gz format so we will compres the image in tar.gz format.

~]$ tar cvzf fedora-32-google-cloud.tar.gz disk.raw

Now we will upload the image just created "fedora-32-google-cloud.tar.gz"

We have created in side Fedora VM. We have to put it into Google cloud bucket. Using Web console
  • Goto Storage
  • Create a bucket
remeber its name. Now from within VM we can copy this image to bucket.
~]$ gsutil cp "fedora-32-google-cloud.tar.gz" "gs://[name of the bucket]/"
Replace with your bucket name in above comand. Well it will be uploaded to the bucket in a while. It can be seen listed under the bucket created.

From your desktop fedora fire this command.
~]$ gcloud compute images create --source-uri \
    gs://[your bucket]/fedora-32-google-cloud.tar.gz \
    --licenses "https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx" \
    fedora-32-google-cloud-image
Wait for few seconds, an image will be created in images section of console. it can be seen under Images section of Web console. Note the --licenses calause. it is optional. you can omit it. but if you omit it then the created image wont be able to run virtual machines under it. Yes you read it correctly a Nested VM.

I think you enjoied your second coffee ... Jocking...

Now the image is ready and we can create an instance out of it as we created our boiler-plate only difference will be in case of Boot Image we will choose our image and we will choose a multi CPU configuration. After the instance is created check it using SSH and enjoy your Multi CPU Fedora Server on Google cloud.

Well This is enough for Now. Please contact me if you need any help.

73's
DE VU3VFU
Ashok.

Sources :
1) major io
2) linuxmint
3) media com

Wednesday, 6 May 2020

Covid-19 Lockdown Update

Hi friends, in this time of global pandemic, all are forced to be inside. To avoid the boredom of self exile some thing extra has to be done to dissipate stored energy. I adapted few of my hobbies to do the same. Today I want to share how and what I was doing during past few weeks.

2m Flower pot Antenna

For my VHF activity I made VK2ZOI design flowerpot antenna. The first one i made is a described here. This one worked exceptionally well it outperformed my existing (refurbished) 5/8 GP. i could reach 30 km with only 5 watts with 59 report from 2 stations and 57 from other stations. Earlier it was not possible to reach them from my QTH (location). After tremendous success, i decided to make its big brother hi-gain dual band antenna described here. I tried it 2 times but i failed miserably. this designed didn't work for me (Might be i missed something). So i kept experimenting on that design on hold 🌝🌝🌝.


SDR on Raspberry PI 3B

SDR is my passion. I am a fan of this Software Defined Radio(SDR) technology. During this boring lock-down, I thought to put SDR softwares on a RPI-3B. Well yes there images available to do SDR on RPI. But they are all based on Raspbian. Though i can work on it as I worked on Ubuntu and Armbian. But Fedora is my choice as I have worked with Redhat earlier.

For Experimenting I need to change image often hence first I enabled USB booting on RPI-3B. Then  Tried some images. If any of you trying or replicating then do remember fedora is a heavier OS for RPI.

Installing Fedora.

REMEMBER  Never jump to load a GUI image directly by downloading.
You know Why I am telling πŸ˜… ......... Yes you are right. So download Fedora minimal image for armhfp from here.  Now either use "dd" or use "disk image writer" to create a USB. USB pendrive should be more than or equals to 8GB. 
(I downloaded Fedora 31 but you can go for latest Fedora 32 also.)
After making the disk boot from it. Next is to enable wifi. the key is you have only nmcli to configure and setup your network. After you are connected to Internet you need to update the system.

sudo dnf update

next is installing SDR software. basic thing is to install RTL-SDR driver. Its easy just use dnf to install if you are ok with 28MHz and above reception. If you need  HF reception without any up-converter , then stock RTL-SDR from fedora repo wont work. For that purpose I will recomend AB9IL . down load it and compile and install it. After installation try rtl_test and rtl_tcp. if you want to use this as remote then you can stop here. Execute 

rtl_tcp -a <ip address of RPI> -p <port default is 1234> -s12000 

Yes keep sampling rate small as RPI doesn't have much power and wifi is unreliable πŸ˜›πŸ˜›πŸ˜›. From another machine on the same network use gqrx to connect to your RPI and tune FM stations and of course tune  HF to see if you get any... I am sure you will get plenty of Chinese and Arabic stations. I could receive our Local Medium wave station on 972.0KHz only. so you can try your luck.( Note: the sensitivity and frequency range varies from Dongle to Dongle)

Well if you want to venture in to a standalone SDR, then stay with me. The Next step is to put a GUI Desktop environment. One must choose as per his/her personal choice but my experience is bitter with LXQt Gnome and XFCE on RPI-3B. Only LXDE worked smoothly and without much problem. Though i prefere LXQt on my Desktop. 

Next is you have to install SDR Radio software like gqrx or CubicSDR. For any SDR software One need a DSP library. liquidDSP andGnuradio are best in my view. GNURadio available from Fedora repo installs Python-2. But GNURadio 3.8 from github uses Pythom-3 hence no old dependencies. So be prepare to compile GNURadio by yourself. 

How to compile for RPI? 

Well You can compile it on RPI itself but it is never intended. So 
1- copy everything to a folder on your desktop PC 
2- install qemu-user-static on your pc
3- locate qemu-arm-static
4- copy it in to the folder in point 1
5- use chroot and compile on your PC

Though it is standard method this is slow in comparison to compiling directly on RPI.( Atleast on my Intel(R)Core(TM)2Duo CPU E6750@2.66GHz )

using this process GNURadio, gqrx, LiquidDSP, WxWidget, SoapySDR, SoapySDRserver, SoapySDRremote,soapy-rtlsdr and CubicSDR are compiled.
Please refer to individual compilation process described for respective  packages. 

Now Copy back the compiled apps to your Pen drive. Boot from it and try executing gqrx and CubicSDR. 

Note: May complain about Library not found even after executing ldconfig so adjust /etc/ld.so.conf to include /usr/local/lib  
now everything will be fine.

Executing gqrx

Try finding optimum sample rate, band width. Next adjust FFT buffer and speed. Reasonable sound quality will be heard.

Executing CubicSDR

Here multiple settings at multiple areas should be adjusted. Sampling rate, Audo sampling rate and gain to get a good sound quality.





 Cheers 73's
DE VU3VFU 

Neural Network from Scratch Using C (Part-3)

  XOR Problem In part 2, AND gate and OR gate could be trained using a single perceptron. But XOR gate could not be as it is not linearly...