Showing posts with label Linux. Show all posts
Showing posts with label Linux. 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

Monday, 9 March 2020

How to setup LAMP using Fedora 31

There are plenty of documents available on internet and you may be a pro in this field. Well I am new and its for my references and someone like me πŸ˜ƒ trying to learn by doing myself. 
Here I will put the key points to setup a basic LAMP (Linux Apache Mariadb PHP) server all by yourself on your hardware πŸ˜ƒ.

Begin 

To start with we have to have a Fedora server or Worksation  ready. To achieve this one can use Live ISO files from Fedora site. Please refer to Documentation on how to do so. Here I assume knowledge of fedora server installation and setup.
The system may be installed on real hardware or on VM(Virtual Machine).

Basic LAMP packages need to be installed

After the bare minimum Fedora server installation, it is required to install the following packages.

php php-cli php-php-gettext php-mbstring php-mcrypt php-mysqlnd php-pear
php-curl php-gd php-xml php-bcmath php-zip mariadb-server httpd.

Use dnf install as root to install the packages and its dependencies. 

Configuration

It is assumed that the network is configured properly and it is accessible from outside world. For Virtual machine, Network setup is bit involved but Internet has many resource. ( Hint: Install a Bridge and go on)

1) SELinux should be set to permissive. (Please do not dissable it)

  • sudo setenforce 0
  • open /etc/selinux/config as root
  • sudo nano /etc/selinux/config
  • change SELINUX=enforcing to SELINUX=permissive
  • save the file

2) PHP setup

  • set timezone in /etc/php.ini 
  • date.timezone = Asia/Kolkata

3) MySQL configuration

  • open /etc/my.cnf.d/mariadb-server.cnf as root
  • in [mysqld] section change characterset to utf8 
character-set-server=utf8
  • start mariadb service
  • sudo systemctl strat mariadb
  • enable the service to run automatically when system boots
  • sudo systemctl enable mariadb
  • setup root password for mariadb by using mysql_secure_installation
  • remove anonymous user
  • disallow remote root login
  • remove test databases and access to it
  • reload previledge tables

4) Firewall setup

  • allow access for HTTP/HTTPS connections
    sudo firewall-cmd --add-service={http,https} --permanent
  • allow mysql access through firewall
    sudo firewall-cmd --add-service=mysql --permanent
  • reload firewall
    sudo firewall-cmd --reload

now you are done. Enjoy your adventure.

Saturday, 18 April 2015

Installing Arduino IDE

In the last article unboxing and connecting the Arduino UNO was described. In this article how to install the IDE will be discussed. Primarily Fedora and Linux generic installation will be discussed.

Fedora

Fedora and all redhat derivatives uses yum for installation and de-installation. The easiest way to install Arduino IDE under Fedora is to issue the following command
~$ sudo yum install arduino
This command will download and install arduino package and its dependencies. After installation is complete, from terminal  bellow command should be issued.
~$ arduino
This will start the arduino IDE and flash a message box. The message box will ask to add the user to few groups;  Ok should be choosen here. Then it will show after the user login again changes will take effect. So just logging out and logging in is required at this point. Now the system is ready.

The arduino IDE can be started from terminal like above or it can be started from GUI Menu ( Programming -> Arduino ). Once the IDE is started, be familiarize with all the tabs and menu entries in arduino IDE. If arduino board is connected to the system via USB cable then "Tools" tab should be checked. Under "Tools" tab the "Boards" entry it should be checked and it should show the board attached or else the board should be selected manually.

 Next the "Serial Port" entry under the "Tools" tab should be checked. it should be enabled and should show the port, to which Arduino board is connected. In my case it shows "Arduino UNO" ( This is default) and "Serial Port /dev/ttyUSB0".

Hello World

Till this point it seems good. It is time to try out some adventures. for this purpose Select "File -> Examples -> basic -> blink". Corresponding sketch will be opened. Then from "Sketch" tab "Compile/Verify" should be selected. this will Compile the sketch. Next "Upload" should be selected from "Files" tab. When the uploading completes, a message will be flashed. 
Great ... The LED is blinking.

Concluding Remarks  

Here we discussed yum based installation. It is suitable for lazy and Dummies like me. But if some one want to try the harder way then please download the sources and be prepared to wait at least 3 hours until your cross compiler is ready and then manually setup everything. I am afraid of doing this adventure but this will teach how or what are the steps needed for cross compiler generation and setting up a cross compiler environment, Very Good exposure...

Blink sketch is just to check if the whole setup is working properly or not. One can try few other sketches from example too.

This concludes our second instalment in Arduino adventure. Stay tuned for the next instalment.

NOTE:  A nice document describing installation methods is available from Sparkfun here.

Thursday, 16 April 2015

Arduino UNO Adventure

Hello friends,
Priyasloka generously donated me an Arduino UNO. Though I have experience in other embedded board development, this is first time i am soiling my hand with Arduino.

This will be a series not a big chain of series. But few small parts. dealing with basics to some level of programming.

 Comparison of Arduino UNO with PIC microcontroller development board.

I have used PIC 18F4550 boards. Those board has one advantage, if a boot loader is burnt, then it is detected as a USB storage device and just copying the compiled code is sufficient. But to burn the bootloader, serial port (UART/USART) is needed. 
Arduino UNO has a serial to USB converter onboard. Which is better for beginner and dummies like me.( I hate External programmer and JTAG ) Geeeee

Getting started

I use Linux(Fedora) for casual use and also for my bread and butter.
so i decided to use my Fedora laptop for arduino adventure.

Arduino UNO has micro USB connector which is used for powering the board
as well as communicating with the board. Though UNO has a DC power supply connector.
We will get a micro USB cable which can connect to Arduino and laptop.
Mobile phone/smart phone charger cable might work for this purpose. (WARNING... I DON'T GUARANTEE IT)

We get a USB connector which connects to Arduino UNO and laptop. Bellow is the dump of messages linux throws.
Apr 16 11:36:13 localhost kernel: [ 1552.431146] usb 3-1: new full-speed USB device number 2 using uhci_hcd
Apr 16 11:36:13 localhost kernel: usb 3-1: new full-speed USB device number 2 using uhci_hcd
Apr 16 11:36:13 localhost kernel: [ 1552.583165] usb 3-1: New USB device found, idVendor=1a86, idProduct=7523
Apr 16 11:36:13 localhost kernel: [ 1552.583183] usb 3-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
Apr 16 11:36:13 localhost kernel: [ 1552.583191] usb 3-1: Product: USB2.0-Serial
Apr 16 11:36:13 localhost kernel: usb 3-1: New USB device found, idVendor=1a86, idProduct=7523
Apr 16 11:36:13 localhost kernel: usb 3-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
Apr 16 11:36:13 localhost kernel: usb 3-1: Product: USB2.0-Serial
Apr 16 11:36:14 localhost mtp-probe: checking bus 3, device 2: "/sys/devices/pci0000:00/0000:00:1d.1/usb3/3-1"
Apr 16 11:36:14 localhost mtp-probe: bus: 3, device: 2 was not an MTP device
Apr 16 11:36:15 localhost kernel: [ 1554.157815] usbcore: registered new interface driver ch341
Apr 16 11:36:15 localhost kernel: [ 1554.157850] usbserial: USB Serial support registered for ch341-uart
Apr 16 11:36:15 localhost kernel: [ 1554.157880] ch341 3-1:1.0: ch341-uart converter detected
Apr 16 11:36:15 localhost kernel: usbcore: registered new interface driver ch341
Apr 16 11:36:15 localhost kernel: usbserial: USB Serial support registered for ch341-uart
Apr 16 11:36:15 localhost kernel: ch341 3-1:1.0: ch341-uart converter detected
Apr 16 11:36:15 localhost kernel: [ 1554.170609] usb 3-1: ch341-uart converter now attached to ttyUSB0
Apr 16 11:36:15 localhost kernel: usb 3-1: ch341-uart converter now attached to ttyUSB0
 The above messages shows us that the device(UNO) has ch341 UART converter chipset, and the virtual serial port assigned to ttyUSB0.
In Unix language it will be /dev/ttyUSB0. Your board may show different USB tty so dont panic. see the messages dumped by your system.
In the Next article I will explain about Arduino IDE instalation.

Tuesday, 4 November 2014

Welcome to my first post

Hello There!!!!
I Thought to post few things here which will be beneficial to others. After all It is everybody's duty to give back something to the society. 

I have 20 years of software development Experience. Throughout this 2 decade long career I used OpenSource platform 99.999% of time. Rest fractional part is spent on old favourite MS-DOS (versions 3,5,6,6.2). I have learnt so many things from OpenSource Projects. So I started few open source projects back in 2007-2012. All my projects are hosted here. 

Besides software I also keep interest in Electronics(Hobby), Photography, Aero modelling and SWL(Radio listening). In this blog time to time I will post my experiments on these topics and few social concerns too. What ever is posted will be purely my personal experience. If any thing which is not my own is presented due credit will be given to the source.

This is all for now, stay tuned for more in future.

Thank you for your patience and visit.
 

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...