Random Bits

Technical Log from Didik Setiawan

My Blog

As a person who use internet in daily basis, I think something personal like a domain name is essential to have. But, there is no good personal domain name available for free. Fortunately, the price to “borrow” a domain name from the registrar is fairly affordable. So, without even thinking more about price to pay, I decided that what I invested in this thing will someday get useful for everyone, in anyway.
After I “reserved” one domain name, I need to associate it with other service. The two things that important to be setting up immediately are blog and email.
Blog is like my “broadcasting center”. I store my notes, my journals there. Everyone is welcome to visit there, and I hope it can help someone to answer their question someday. Email become my virtual identity. I use it to register to many service on the internet. Especially with my own custom domain name, I can make my blog and email look more personally. Here I explain how I build my blog step by step.

Domain Name

I register my domain from a web hosting provider. I just pay for the domain name, not the hosting service.
About what provider I currently use, it can be found using a domain tool easily.

Blog

In order to build my infrastructure, I need to have a server, dedicated internet or static IP address to run the software up. But I don’t have any of them, so I just use free service from external providers. There is a lot of providers who can give us some space to host our web and email.
In early time I touch with internet, I did use some blogging framework to run my blog. I ever use Blogger, Joomla, Drupal and Wordpress. I spend a long time with Wordpress. But, due to personal favor, finally I switch to Octopress.

Why Octopress? Because that is simple. It has beautiful design, while easy to use. I can create post directly from Vim on my Linux console. It can be updated using git, so I can feel the sysadmin way to write a post. It use a simplify html-like syntax, markdown. I can host my blog together with my application repository in Github. You can check this article for more details. With this Octopress take control my way to blog, I can focus on contents that I want to share rather than have to be confused to setup and design my blog.

SSL

For security purpose, I use free ssl service from CloudFlare. The setup process is fairly easy. The requirements for its service is just a domain name with top level domain. I just need to set my DNS configuration to point CloudFlare DNS. Additionally, there is a feature so I can force my blog visitor to use https in order to see the ssl sign.

Email

Rather than using well-known free email service, I need to host my own email because I want to use my own domain name. Fortunately, there is email provider that provide free email service using custom domain, thanks to Zoho Mail. Even with free service, I can use my own domain name.

That’s all about my blog. I hope it all will be useful. Thanks for reading.

Insert USB Module in Linux Kernel

After I re-compile my kernel using a vanilla one, I found that my usb flashdrive can not be detected by my operating system. I check on dmesg, there are entry about my usb flashdrive on the log:

[email protected]:~$ dmesg
--- output omitted ---
[  123.616624] usb 1-1.2: new high-speed USB device number 3 using ehci-pci
[  123.710606] usb 1-1.2: New USB device found, idVendor=0951, idProduct=1666
[  123.710617] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  123.710631] usb 1-1.2: Product: DataTraveler 3.0
[  123.710634] usb 1-1.2: Manufacturer: Kingston
[  123.710637] usb 1-1.2: SerialNumber: 60A44C3FACDBBDB1796E36C9
--- output omitted ---

But, after a moment I wait, there is no notification about new flashdrive inserted. I check using blkid, still there is no sign of the thing.

[email protected]:~$ sudo blkid
[sudo] password for didik: 
/dev/sda1: LABEL="SYSTEM" UUID="70E80099E8005FA8" TYPE="ntfs" PARTUUID="ba6ded71-01"
/dev/sda2: UUID="92521783-0211-4b1d-8f66-b9a62c16fc89" UUID_SUB="fdb1cb3e-1a44-4e53-864e-b29f6fdfb153" TYPE="btrfs" PARTUUID="ba6ded71-02"
/dev/sda3: UUID="4723c4f7-9624-4b8d-9b41-3079442641b4" TYPE="swap" PARTUUID="ba6ded71-03"
/dev/sda5: LABEL="DATA" UUID="01CD0094E26EBB80" TYPE="ntfs" PARTUUID="ba6ded71-05"

Apparently, I forget to insert usb-storage module in my kernel, after I recompile it. So, I try to modprobe the needed module.

[email protected]:~$ modprobe usb-storage
modprobe: FATAL: Module usb-storage not found in directory /lib/modules/4.6.2

Okay, it seems that the file I need is not available from the kernel tree. So, I need to insert the module manually.
Time to go to kernel tree.

[email protected]:~$ cd linux-4.6.2/
[email protected]:~/linux-4.6.2$ make menuconfig

From this menu, I will include the module that I need for usb-storage. Press / to search module name. It is called USB_STORAGE.

usb-module0.png

After I found its location, I insert it with “M” become my choice between the tri-state mode.

usb-module1.png

I exit and save this configuration.
Then I make it.

[email protected]:~/linux-4.6.2$ make -j4

Note that the “4” value is changeable depends on processor specs.
I use “4” because my processor Install old and new compiled module, as root of course.

[email protected]:~/linux-4.6.2$ sudo make modules_install

My new module finally installed. Now I can plug the usb drive on my computer.
Just in case you are curious about system message of the inserted device, you can use dmesg.

[email protected]:~$ dmesg
--- output omitted ---
[ 3231.314581] usb 1-1.2: USB disconnect, device number 3
[ 3233.198257] usb 1-1.2: new high-speed USB device number 4 using ehci-pci
[ 3233.292379] usb 1-1.2: New USB device found, idVendor=0951, idProduct=1666
[ 3233.292390] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3233.292395] usb 1-1.2: Product: DataTraveler 3.0
[ 3233.292399] usb 1-1.2: Manufacturer: Kingston
[ 3233.292403] usb 1-1.2: SerialNumber: 60A44C3FACDBBDB1796E36C9
[ 3233.990697] usb-storage 1-1.2:1.0: USB Mass Storage device detected
[ 3233.990994] scsi host6: usb-storage 1-1.2:1.0
[ 3233.991196] usbcore: registered new interface driver usb-storage
[ 3234.995392] scsi 6:0:0:0: Direct-Access     Kingston DataTraveler 3.0 PMAP PQ: 0 ANSI: 6
[ 3234.996242] sd 6:0:0:0: Attached scsi generic sg2 type 0
[ 3234.996655] sd 6:0:0:0: [sdb] 31293440 512-byte logical blocks: (16.0 GB/14.9 GiB)
[ 3234.998693] sd 6:0:0:0: [sdb] Write Protect is off
[ 3234.998705] sd 6:0:0:0: [sdb] Mode Sense: 2b 80 00 08
[ 3235.000537] sd 6:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 3236.101997]  sdb: sdb1
[ 3236.108153] sd 6:0:0:0: [sdb] Attached SCSI removable disk
--- output omitted ---

And modinfo to view module details.

[email protected]:~$ modinfo usb-storage
filename:       /lib/modules/4.6.2/kernel/drivers/usb/storage/usb-storage.ko
license:        GPL
description:    USB Mass Storage driver for Linux
author:         Matthew Dharm <[email protected]>
srcversion:     D0235102D9160CC35A9A1C4
alias:          usb:v*p*d*dc*dsc*dp*ic08isc06ip50in*
alias:          usb:v*p*d*dc*dsc*dp*ic08isc05ip50in*
--- output omitted ---
alias:          usb:v03EEp6906d0003dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v03EBp2002d0100dc*dsc*dp*ic*isc*ip*in*
depends:        
intree:         Y
vermagic:       4.6.2 SMP mod_unload modversions 
parm:           option_zero_cd:ZeroCD mode (1=Force Modem (default), 2=Allow CD-Rom (uint)
parm:           swi_tru_install:TRU-Install mode (1=Full Logic (def), 2=Force CD-Rom, 3=Force Modem) (uint)
parm:           delay_use:seconds to delay before using a new device (uint)
parm:           quirks:supplemental list of device IDs and their quirks (string)

Until next time.

Learn Programming Faster

One common theme across many of these tips is:

don’t go too fast; get it right before moving on.

You must have a strong grasp of the fundamentals. Don’t go too fast through the introductory part of the course, thinking you know it all-but you rarely did.

At the same time, you must not stop making progress–you can go too slow as well as too fast. Don’t avoid a topic after you’ve mastered everything leading up to it. By facing more challenging ideas, you’ll help cement your grasp of the basics.

do one thing and do it well.

Look at the Example Code

Reading is usually about the words on the page, but learning to program is about code. When you’re first learning to program, you should make sure to look at, and try to understand, every example. When I first learned to program, I would sometimes read the code examples before the text, and try to figure out what they did. It doesn’t always work, but it did force me to look at the example very carefully, and it often helped make the writeups clearer.

There are plenty of open source projects that we can look at their code. Get one and start diving in it.

Don’t Just Read Example Code–Run It

But when you’re reading a programming tutorial (or book), it’s easy to look at the sample code and say “I get it, I get it, that makes sense”. Of course, you might get it, but you might not get it, and you just don’t know it. There’s only one way to find out–do something with that code.

If you haven’t already, get a compiler like gcc and other useful tools.

Then type the sample code into a compiler. If you type it, instead of copying and pasting it, you will really force yourself to go through everything that is there. Typing the code will force you to pay attention to the details of the syntax of the language–things like those funny semicolons that seem to go after every line.

Then compile it and run it. Make sure it does what you think it does.

Then change it. Software is the most easily changed machinery on the planet. You can experiment easily, try new things, see what happens; the changes will happen almost immediately, and there is no risk of death or mayhem. The easiest way to learn new language features is to take some code that works one way, and change it.

Write your Own Code as Soon as Possible

Once you understand something about the language, or even if you’re still getting your head around it, start writing sample programs that use it. Sometimes it’s hard to find good ideas for what programs to write. That’s OK, you don’t have to come up with every idea at the beginning.

You can also reimplement the examples from the book or tutorial you are reading. Try to do so without looking back at the sample code; it won’t be as easy as it seems. This technique can work especially well if you tweak the sample code.

If you can’t think of a small program to write, but you have in mind a larger program you want to implement, like a game, you could start building small pieces that you can later use for a game. Whether you use them later or not, you will get the same useful experience.

Learn to Use a Debugger

The sooner you learn good debugging techniques, easier it will be to learn to program. The first step in doing so is to learn how to use a tool called a debugger, which allows you to step through your code.

A debugger will allow you to step line by line through a piece of code. It will let you see the values of variables, and whether the code inside an if statement is executed.

A debugger can help you quickly answer questions about what your code is doing.

int main()
{
    int x;
    int y;
    if (x > 4)    // <-- what is the value of x here?
    {
        y = 5; // <-- did this line of code execute?
    }
}

A final word about debuggers: the first time you learn about a debugger, it will take you longer to fix the problems with your code. After the tenth or so bug, it will really start to pay off. And believe me, you will have way more than ten bugs in your programming career. The sooner you learn to use a debugger, the sooner it will pay off.

Seek out More Sources

If you don’t understand something, there’s a good possibility the way it was explained just didn’t click.

First, look for alternative explanations. The internet is filled with information about programming, and some explanations work better for different people; you might need pictures, someone else might not. There are also lots of good books with detailed explanations.

But if that doesn’t work, the easiest way to figure out where your misunderstanding lies is to ask someone else. But try to go beyond saying, “I don’t understand. Please explain.” You’re likely to get a link back to the same text you didn’t understand. Instead, rephrase your understanding of the text in your words. The more your question reveals about what you are thinking, the easier it will be for a knowledgeable expert to answer it. Programmers sometimes have a reputation for being grumpy about answering questions, but I think the reason is that they want to make progress in a conversation, and that requires both sides to put in effort. If you ask a smart, detailed question that shows you are thinking, you will generally get good results.

Reference(s):
http://www.cprogramming.com/how_to_learn_to_program.html

Build Custom Linux Kernel

Install Custom Linux Kernel

To build this custom Linux Kernel, I use Ubuntu 14.04 64 bit operating system. At first, ensure all the required utilities installed correctly.

$ sudo apt-get install gcc make git libssl-dev libncurses5-dev

Download source from Linux Kernel Archives, for example, I use version 4.4.
https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.4.tar.xz

Extract the tarball file.

$ tar xJf linux-4.4.tar.xz
$ cd linux-4.4

We need to change configuration parameters to determine which settings and modules we need to build. Use make *config command as follow. Choose one that match to your favor. I usually use number 2.

1. Use default kernel configuration.

This settings comes from the kernel maintainer.

$ make defconfig

2. Use our existing configuration.

Just press “Enter” when asked for configuration options.

$ make localmodconfig

3. Manual selection with graphical menu.

$ make menuconfig

4. Duplicate our current config.

$ sudo cp /boot/config-`uname -r`* .config

Then, compile source, this process can take a while.

$ make -j4

The parameter “4” is based on processor specification. Set this at your own favor.
Install modules.

$ sudo make modules_install

Bootloader setup.

$ sudo make install

Double check bootloader setup.

$ sudo update-grub2

Reboot the system. We can check our new installed kernel with this command.

$ uname -a

Uninstall Custom Linux Kernel

Find out the version of custom kernel.
Update filesystem search index.

$ sudo updatedb

In this example, I want to remove kernel version 3.16.0-30-generic.

$ CUSTOM_KERNEL_VERSION="3.16.0-30-generic"
$ locate $CUSTOM_KERNEL_VERSION

Ensure our system has other kernel installed beside $CUSTOM_KERNEL_VERSION.
Then, delete all files & folders which contain $CUSTOM_KERNEL_VERSION name.

$ sudo rm /boot/vmlinuz-$CUSTOM_KERNEL_VERSION
$ sudo rm /boot/initrd.img-$CUSTOM_KERNEL_VERSION
$ sudo rm /boot/System.map-$CUSTOM_KERNEL_VERSION
$ sudo rm /boot/config-$CUSTOM_KERNEL_VERSION
$ sudo rm -rf /lib/modules/$CUSTOM_KERNEL_VERSION/
$ sudo rm /var/lib/initramfs-tools/$CUSTOM_KERNEL_VERSION

Do some cleaning.

$ sudo update-initramfs -k all -u
$ sudo update-grub2

Finish. Our custom kernel has been uninstalled from our system.

Cacti Monitoring via Email Notification

Cacti can be configured so it can send email notification if something has occured in our system. This is can be useful, especially for system administrator to monitor their server condition. It can be done with help from one of cacti plugin that is thold. I do this procedure to monitor computer harddrive capacity on Windows.

So, if there is a computer which harddrive capacity near the capacity limit, cacti will send notification via email. This is useful to avoid misinformation that can bring system stop working or failed periodic system backup.

The installation procedure itself is easy enough. Before this plugin thold installation, we need to install settings plugin http://docs.cacti.net/plugin:settings. We can install those plugins concurently. Download files that are needed:

$ cd /tmp
$ wget http://docs.cacti.net/_media/plugin:settings-v0.71-1.tgz
$ wget http://docs.cacti.net/_media/plugin:thold-v0.5.0.tgz

Rename download files in order to avoid error at extract time.

$ mv plugin:settings-v0.71-1.tgz settings-v0.71-1.tgz
$ mv plugin:thold-v0.5.0.tgz thold-v0.5.0.tgz

Extract tarball files.

$ tar zxf settings-v0.71-1.tgz
$ tar zxf thold-v0.5.0.tgz

Move extrated files to folder cacti/plugins.

$ sudo mv settings thold /var/www/html/cacti/plugins/

Then we configure cacti via web interface.

cactiemail1

Install and activate plugin Setting and Thold. After success, we need to configure thos plugins. Set configuration for email. We will use gmail account for mail service configuration. Configure following parameters:

cactiemail2

We can test to send email to confirm email sending process running well.

cactiemail3

After test passed, we can save the configuration. In the notification lists menu, add our email address for thold plugin which need to be sent if some notification raised by system.

cactiemail4

Choose graph which need to monitor the threshold. In this example, I will monitor a Windows host, so I can use harddrive free space percentage to trigger the thold.

cactiemail5

Configure the following parameter:

  • Threshold Name: Desired treshold name
  • Re-Alert Cycle: Notification sending interval
  • Warning Low Threshold: Minimum limit value for threshold warning
  • Alert Low Threshold: Maximum limit valuefor threshold warning
  • Warning Notification List: List of email address notification for warning
  • Alert Notification List: List of email address notification for alert

cactiemail6

Thold has been done configured. We just need to monitor the result. Cacti will send notification contain email and graph concerned about monitored device. In the example above, cacti will check harddrive capacity of server within a day. If something has found that harddrive capacity meet the condition of below 25%, then cacti will send email notification warning. And if harddrive capacity below 10% then cacti will send email notification alert.
This is an example of email notification from cacti.

cactiemail7

Reference:
http://docs.cacti.net/plugin:thold