Random Bits

Technical Log from Didik Setiawan

Octopress Setup and Deployment

I will explain how to setup a new blog using octopress, deploy it on github and contribute from other place. Let’s check this out.

First Time Setup

Prerequisite:

  • Install Git and Node.js

On debian system, use apt-get.

$ sudo apt-get install git
$ sudo apt-get install nodejs
  • Install Ruby

We must use version 1.9.3 or higher. To ensure we fulfill this requirement, I prefer to install ruby from source. Download from Ruby official site. The installation process is quite common.

$ tar zxf ruby-2.3.1.tar.gz 
$ cd ruby-2.3.1/
$ ./configure
$ sudo make && make install
  • Install ExecJS

To run JavaScript code from Ruby.

$ sudo gem install execjs
  • Configure bundle

Another octopress dependency.

$ sudo gem install bundler

After all needed requirements fulfilled, then grab the octopress source code.

$ git clone git://github.com/imathis/octopress.git octopress
$ cd octopress

One more dependency:

$ bundle install

Then install octopress default theme.

$ rake install

Setup process is finished. We can now start to blog using rake newpost[“title”], customize _config.yml, add some pages, customize 404 not found page, using custom domain name and so on.

Deploy on Github

There are some way to deploy octopress, either using rsync or git. In this post, I will explain how to deploy octopress on Github. Create a new Github repository and name the repository with the format username.github.io, where username is your GitHub username or organization name.

Github Pages for users and organizations uses the master branch like the public directory on a web server, serving up the files at your Pages url http://username.github.io. As a result, we will to work on the source for our blog in the source branch and commit the generated content to the master branch. Octopress has a configuration task that helps us set all this up.

$ rake setup_github_pages

The rake task will ask for a URL of the Github repo. Copy the SSH or HTTPS URL from our newly created repository (e.g. [email protected]:username/username.github.io.git) and paste it in as a response.

This will:

  • Ask for and store our Github Pages repository url
  • Rename the remote pointing to imathis/octopress from ‘origin’ to ‘octopress’
  • Add our Github Pages repository as the default origin remote
  • Switch the active branch from master to source
  • Configure our blog’s url according to your repository
  • Setup a master branch in the _deploy directory for deployment

Next run:

$ rake generate
$ rake deploy

This will generate our blog, copy the generated files into _deploy/, add them to git, commit and push them up to the master branch.

Don’t forget to commit the source of our blog.

$ git add .
$ git commit -m 'our message'
$ git push origin source

With new repositories, Github sets the default branch based on the branch we push first, and it looks there for the generated site content. If we’re having trouble getting Github to publish our site, go to the admin panel for our repository and make sure that the master branch is the default branch.

Contribute from Other Place

Sometimes we need to develop our octopress site in other place than we currently in. To do that, we will use the benefit of git.
First, we need to get our site copy:

$ git clone [email protected]:username/username.github.io.git
$ cd username.github.io

Switch to source branch

$ git checkout source

Then do all change on our source, after that run “rake generate” or “rake preview” to compile our source onto public directory. Everything seems to be okay until we need to upload to github.

$ rake deploy
## Deploying branch to Github Pages 
## Pulling any updates from Github Pages 
cd _deploy
rake aborted!
Errno::ENOENT: No such file or directory @ dir_chdir - _deploy
/home/didik/octopress/Rakefile:255:in `block in <top (required)>'
/home/didik/octopress/Rakefile:227:in `block in <top (required)>'
Tasks: TOP => deploy
(See full trace by running task with --trace)

Oops, it’s look like we miss something. We have to make a new _deploy directory and add git initialization to it.

$ mkdir _deploy
$ cd _deploy
$ git init
$ git remote add origin [email protected]:username/username.github.io.git
$ git pull origin master
$ cd ..

That’s all. Now, we can upload using rake deploy as usual.
Until next time.

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.