Arch Linux Installation Notes

Boot Live ISO

Make a bootable media. There are many ways to do that. My personal favorite is using gnome-disks utility and select restore image to write the arch linux ISO onto a USB drive. Insert the drive and boot up your motherboard BIOS by pressing DEL or whatever shortcut key.

I assume you are having a UEFI motherboard which is what is common today. Check from your motherboard bios screen that UEFI mode is selected. Now boot from the USB drive into the live linux environment.

Partitions

#efivar -l //tocheck if booted in EFI mode. No output means no EFI.

The first thing needing your attention is your partitions. This post assumes that you will be making installation on the second disk sdb. Use cfdisk for this purpose. Remember to write partitions at the end:-

#cfdisk /dev/sdb

At the end of this exercise use fdisk to check completed partition setup. If you need some graphical aid in resizing partitions then you may like to use gparted but thats not available now. You will need to boot a live distro which has gparted.

This is my sample partition setup. sdb1 is the key UEFI partition here. This is where your boot loader is going to be installed. sdb2 is the root where linux is going to be installed. sdb3 is not used here.

#fdisk -l /dev/sdb

Device       Start    End Sectors Size Type
/dev/sdb1    2048 1050623 1048576 512M EFI System
/dev/sdb2    1050624 209717247 208666624 99.5G Linux filesystem
/dev/sdb3    209717248 1921525759 1711808512 816.3G Linux filesystem
/dev/sdb4    1921525760 1953523711 31997952 15.3G Linux swap

Prepare partitions

 #mkfs.fat -F32 /dev/sdb1
 #mkfs.ext4 /dev/sdb2
 #mount /dev/sdb2 /mnt
 #mkswap /dev/sdb4 //not req if already formatted as a swap area.
 #swapon /dev/sdb4

Network
Bring up network. Network is mandatory for Arch installation. To avoid complexity at this stage I use my phone which is already connected on WiFi on a USB tether.

#ip link //check the output for something like enp...
#dhcpcd enp0s20u3u1 //In my case. You should be connected after this.

Install
Install base Linux as per standard arch install instructions at https://wiki.archlinux.org/index.php/installation_guide

#pacstrap /mnt base base-devel
#arch-chroot /mnt        //entering chroot
#passwd                  // set your root passwd
#nano /etc/locale.gen    // Uncomment your locale ex:- en_US.UTF-8
#locale-gen
#ln -sf /usr/share/zoneinfo/Asia/Calcutta /etc/localtime //My timezone
#localectl set-locale LANG="en_US.UTF-8" //need this for gnome terminal
//else it does not launch later
#hwclock --systohc --utc
#echo archBox > /etc/hostname

Setup Package Manager

#nano /etc/pacman.conf

//uncomment following 2 lines
[multilib]
Include = /etc/pacman.d/mirrorlist

//add these 3 lines
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch

#pacman -Syu //sync database

Setup Bootloader

We are going to go totally systemd and use systemd boot which is a light and pure UEFI boot manager and not grub

#mkinitcpio -p linux
#pacman -S efibootmgr
#cd /boot
#mkdir efi
#mount /dev/sdb1 /boot/efi
#mkdir /boot/efi/archmain
#cp /boot/vmlinuz-linux /boot/initramfs-linux.img /boot/efi/archmain
#bootctl --path=/boot/efi install
#nano /boot/efi/loader/loader.conf
      //insert these 2 lines
      default archmain
      timeout 3
#nano /boot/efi/loader/entries/archmain.conf
       //insert these 4 lines
      title Arch Linux
      linux /archmain/vmlinuz-linux
      initrd /archmain/initramfs-linux.img
      options root=/dev/sda2 rw  //You can later change this into PARTUUID

Complete base setup

#exit //leaving chroot
#genfstab /mnt >> /mnt/etc/fstab
#cd /
#umount /mnt
#reboot //login as root
#useradd -m -g users -G wheel -s /bin/bash lakshman //your username here
//in /etc/sudoers uncomment wheel and sudo entries
//add user below sudo in same format
#passwd lakshman
#exit

Bring up Graphical Environment [X , xfce4 and gdm]
Also check out http://www.tecmint.com/install-cinnamon-desktop-in-arch-linux/ for setting up the video drivers

//login as lakshman
//Bring up network like described before
$sudo pacman -Syu
$sudo pacman -S xorg-server xorg-utils xorg-xinit xorg-server-utils xorg-twm xterm xorg-xclock xorg-apps
mesa dialog wpa_supplicant leafpad git dkms linux-headers bash-completion
$lspci | grep VGA // to identify your video manufacturer
$sudo pacman –Ss | grep xf86-video //to identify corresponding driver
$sudo pacman -S xf86-video-intel //xf86-video-intel identified
$sudo pacman -S xfce4 xfce4-goodies cinnamon nemo-fileroller gdm
$sudo systemctl enable gdm
$sudo systemctl start gdm 
//You should be in xfce now
//open gnome-terminal
$sudo pacman –S net-tools iw networkmanager network-manager-applet
$sudo systemctl enable NetworkManager
//reboot now and login
$ifconfig //to check if your networking device is there
//Ex:- en01:ethernet wired, wlp0s20u10:wifi
//Now use network applet to setup your network
$sudo pacman -S yaourt //AUR repository
$yaourt -S pamac-aur //package manager applet in system tray

Install some Apps with Package Manager GUI

Sample:-
pulseaudio pulseaudio-alsa pavucontrol alsa-utils gnome-terminal firefox flashplugin vlc unzip unrar zip p7zip
 firefox flashplugin gksu leafpad xdg-user-dirs gparted, brasero, dosfstools, transmission,
 gnome-disks, xfburn, libreoffice, geany, cups-pdf, screenfetch, mpg123, seahorse, arc-gtk-theme,
 gnome-disk-utility, google-chrome, pix, ttf-roboto, ttf-droid, jdk

Last Steps

Setup mkinitcpio hooks for moving kernel and initramfs from /boot into /boot/efi/archmain. Also check mkinitcpio hook2 at https://wiki.archlinux.org/index.php/EFISTUB#Using_systemd

# sudo nano /etc/mkinitcpio.d/linux.preset
# /etc/mkinitcpio.d/linux.preset 
# mkinitcpio preset file for the 'linux' package

# Directory to copy the kernel, the initramfs...
ESP_DIR="/boot/efi/archmain"

ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-linux"

PRESETS=('default' 'fallback')

#default_config="/etc/mkinitcpio.conf"
default_image="${ESP_DIR}/initramfs-linux.img"
default_options="-A esp-update-linux"

#fallback_config="/etc/mkinitcpio.conf"
fallback_image="${ESP_DIR}/initramfs-linux-fallback.img"
fallback_options="-S autodetect"
$sudo nano /usr/lib/initcpio/install/esp-update-linux
$sudo chmod +x /usr/lib/initcpio/install/esp-update-linux
# /usr/lib/initcpio/install/esp-update-linux
# Directory to copy the kernel, the initramfs...
ESP_DIR="/boot/efi/archmain"

build() {
 cp /boot/vmlinuz-linux "${ESP_DIR}/vmlinuz-linux"
 # If ucode is used uncomment this line
 cp /boot/intel-ucode.img "${ESP_DIR}/"
}

help() {
 cat <<HELPEOF
This hook copies the kernel to the ESP partition
HELPEOF
}

Test the hooks

sudo mkinitcpio -p linux

Also check that kernel and initramfs are going to the correct place in /boot/efi/archmain by updating linux kernel when you get the chance. With this setup you should be having a kernel copy in /boot on the sdb2 partition which is copied into /boot/efi/archmain. The initramfs-linux.img is directly installed in /boot/efi/archmain.

LTS Kernel

If you need to use a LTS kernel for stability concerns install linux-lts and linux-lts-headers. This includes installation of vmlinuz-linux-lts, initramfs-linux-lts.img, initramfs-linux-lts-fallback.img and linux-lts.preset. If you have followed the steps for setting up the kernel paths for linux kernel setup the approach for linux-lts kernel is similar. Note the “-lts” filename difference.

$sudo mkdir /boot/efi/archmain-lts
$sudo nano /boot/efi/loader/entries/archmain-lts.conf
$sudo nano /etc/mkinitcpio.d/linux-lts.preset
$sudo nano /usr/lib/initcpio/install/esp-update-linux-lts
//finally put the kernel and initramfs in place
$sudo mkinitcpio -p linux-lts

Now the LTS kernel will be available as a second boot option in the Linux Boot Manager.

Android Studio Gradle Build

Ongoing work with Android Studio. I had a library project + 1 pro project + 1 free project and it was very cumbersome in Eclipse. With gradle it becomes 1 project with two flavors. The main concepts are appended. This is a developing post and this is my fourth edit. I will refine it further as I get more insights.

Project Structure

D:\
repository/                       //Custom Maven repository
MyExtLib/                         //External Lib Project
MyProject/                        //Project Root

   MyModule/
      libs/
         myJar.jar               //Lib as a jar in libs folder
      src/
         main/
            java/                //Common Classes
            res/                 //Common res
            AndroidManifest.xml
         proflavor/
            java/
            res/
            AndroidManifest.xml
         freeflavor/
            java/
            res/
            AndroidManifest.xml
      proguard-project.txt
      xxyy.keystore
      build.gradle               //Module level gradle build file

   MyLib/
      src/
         main/
            java/
            res/
            AndroidManifest.xml
      build.gradle             //Lib Module gradle build file

   settings.gradle
   build.gradle                //Top level gradle build file

Top level settings.gradle file

include ':MyModule'

Common module level build.gradle file

apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1625
        versionName '9.2.5'
    }

    signingConfigs {
        myConfig {
            storeFile file('../xxyy.keystore')
            storePassword "*********"
            keyAlias "*******"
            keyPassword "********"
        }
    }

    buildTypes {
        debug {
        }
        release {
            zipAlignEnabled true
            signingConfig signingConfigs.myConfig
            minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android.txt')
        }
    }

    productFlavors {
        freeflavor {
            applicationId 'com.cls.xxx'
            proguardFile('freeflavorproguard.txt')
        }
        proflavor {
            applicationId 'com.cls.xxxpro'
            proguardFile('proflavorproguard.txt')
        }
    }
}

dependencies {
    compile 'com.android.support:support-v13:21.0.0'
    compile 'com.android.support:appcompat-v7:22.1.1'
}

You can have four approaches to libraries:-
1. Local Library Module
2. Library jar in /libs folder
3. External Library Project
4. Library jar in custom local maven repository

Approach 1 – Local Library Module

#Insert this line into the top level settings file

include ':MyLib'

#Insert this line into the module level gradle file

dependencies {
   compile project(':MyLib')
}

Approach 2 – Library jar in /libs folder

#Insert this line into the module level gradle file
dependencies {
   compile files('libs/myJar.jar')
}

Approach 3 – External library project

#Insert this line into the top level settings file

include ':MyExtLib'
project(':MyExtLib').projectDir = new File('D:/MyExtLib')

#Insert this line into the module level gradle file

dependencies {
   compile project(':ExtMyLib')
}

Approach 4 – Custom Local Maven Repository

Step 1 upload jars into maven

Install maven from maven.org
Issue maven command for uploading your jars which are not available in mavenCental to a custom local maven repository d:\repository

D:\store\Applications\apache-maven-3.1.0\bin>mvn install:install-file
-Dfile=d:\My\ Project/My\ Module/libs/myJar.jar
-DgroupId=com.cls.mycustomjar
-DartifactId=mycustomjar
-Dversion=1.0.0
-Dpackaging=jar
-DgeneratePom=true
-DlocalRepositoryPath=d:\repository

Step 2 upload library projects as aar into maven

//build.gradle for Mylib
//uploadArchives task
apply plugin: 'com.android.library'
...
apply plugin: 'maven'
group = 'com.cls.mylibrary'
version = '1.0.0'
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri("d:/repository"))
        }
    }
}

Execute gradle tasks to upload library projects as aar into the custom rep

//In mylibrary project execute task
gradlew uploadArchives

Step 3

OK Now your jars and libraries are ready to be pulled from your local custom repository.

//build.gradle for module
//Insert repository code into the module level build.gradle file

repositories {
    maven { url uri("d:/repository") }
}

dependencies {
    compile 'com.cls.mycustomjar:mycustomjar:1.0.0'
    compile 'com.cls.mylibrary:mylibrary:1.0.0'
}

GPS Programming Insights

Here is a quick insight into GPS programming for Android. It is by no means a complete reference but it may be able to give you the missing perception you are looking for.

GPS Primer

The location in GPS is calculated by measuring the distance from orbitting satellites and doing a process called triliteration which is similar to triangulation. GPS calculates the distances by measuring the time it took for the satellite signal to reach the receiver. So distance = travel time t x 300000 km/sec. The satellites broadcast their own position through data sets called Almanac(Imprecise data) and Ephemeris(Precise data)
So in theory the receiver can solve for position using the three satellites and the distances from them.
As is evident the travel time can only be calculated with any degree of accuracy if the receiver clock is perfectly in sync with the satellites. The satellites transmit a Pseudo Random Code which is also known to and repeated by the receivers. If the clocks are in sync then this code will be perfectly in step. However due to inaccuracies in receiver clock the code will be quiet off. The secret to GPS is that using this inaccurate clock the receiver solves for position using the three satellites and then uses a fourth satellite to eliminate the sync error. Thus 4 satellites are required to get a position fix.

Android LocationManager

The code to start listening to location updates in your Activity is:-

// Comment

public class GpsActivity extends Activity implements GpsStatus.Listener, LocationListener{
   //...
   @Override
   protected void onResume() {
      LocationManager lm=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
      lm.addGpsStatusListener(this);
      lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, mintime, mindistance,this);
   }

   @Override
   public void onPause(){
      lm.removeGpsStatusListener(this);
      lm.removeUpdates(this);
   }
   @Override
   public void onGpsStatusChanged(int event) {
      switch(event){
         case GpsStatus.GPS_EVENT_FIRST_FIX:
         break;
      case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
         break;
      case GpsStatus.GPS_EVENT_STARTED:
         break;
      case GpsStatus.GPS_EVENT_STOPPED:
         break;
      }
   }

   @Override
   public void onLocationChanged(Location loc) {
   }

   @Override
   public void onProviderDisabled(String provider) {
   }

   @Override
   public void onProviderEnabled(String provider) {
   }

   @Override
   public void onStatusChanged(String provider, int status, Bundle extras) {
   }
}

The GPS engine starts when the requestlocationupdates( ) is called. This engine is power hungry and guzzles power from EVENT START to EVENT STOP received in GPS status listener. The engine needs to download almanac and ephemeris and solve for multiple satellites to get location fixes so be very careful how long it runs. Commercial GPS receiver have dedicated multiple channels for simultaneous downloading and processing satellites almanac and ephemeris data. So solution emerges faster. How many channels do mobile GPS sets have ? If it is single channel it will be slow to converge location fix.
The validity of almanac data or orbital data of satellites is an imprecise long term data which typically remains valid for months. The ephemeris on the other hand is precise data and short term and the platform may invalid it in terms of a few hours. The ephemeris of each satellite is repeated in 30 sec intervals consisting of 3 packets with 6 sec blocks. So if 4 satellites are available and snr is > 28 dB and at least 30 sec for collecting ephemeris of one satellite. For four satellites 4*30=120 secs in single channel. For 4 channel rx it is only 30 sec. While collecting ephemeris if platform is moving then this critical process may need to be repeated until success.

So a lot of processing is to be done by GPS engine for giving location fix which has power implication.

There are some things to keep in mind while programming :-

If update rate is more than 3 secs for requestlocationupdates( ) then engine then will not work continuously. To conserve power at slower update rates a STOP_EVENT will start coming in between followed by a START_EVENT when the update interval comes.
When engine is ON wakelock is held. This also means that when you keep updaterate at <=3 secs no sleep for device.
The engine will call ongpsstatuschanged( ) listener when
1. FIRST FIX – First time location fix
2. EVENT STARTED – When Engine starts
3. EVENT STOPPED – When Engine stops
4. SAT STATUS – When the satellite data changes.
The SAT STATUS is a high throughput call and mutiple calls come so throttle your processing here if any. Here you can retreive an iterable satellite list through a gpsstat object and get loads of information like prn no , validity of ephemeris etc.
The engine will cal onlocationchanged( ) when solution is available at the rate passed to requestlocationupdates ( ). Here you can retreive location and other stuff like accuracy.
This is an ongoing article and I will update this as I get more insights.

Android Studio and AndEngine Setup

My efforts at setting up AndEngine with Android Studio. Hope it benefits somebody. Without much ado here it is:-

Steps

1. Clone AndEngine and AndEnginePhysicsBox2DExtension

C:\ProjectDir>git clone https://github.com/nicolasgramlich/AndEngine.git andEngine
C:\ProjectDir>git clone https://github.com/nicolasgramlich/AndEnginePhysicsBox2DExtension.git andEnginePhysicsBox2DExtension

2. Checkout AnchorCenter Branch

C:\ProjectDir\andEngine>git checkout -b GLES2-AnchorCenter origin/GLES2-AnchorCenter
C:\ProjectDir\andEnginePhysicsBox2DExtension>git checkout -b GLES2-AnchorCenter origin/GLES2-AnchorCenter

  • Now you have github link and anytime you need to update the AndEngine repositories just do git pull.
  • The ET is the project module. andEngine and andEnginePhysicsBox2DExtension are the two library modules.
  • The build.gradle in the two library modules is customized to cater for the default Eclipse sourcesets structure received from the github repository.

3. build.gradle[andEngine]

apply plugin: 'com.android.library'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "org.andengine"
        minSdkVersion 15
        targetSdkVersion 19

        ndk {
            moduleName "andengine_shared"
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jni.srcDirs = [] // This needs to be done so that gradle does not know about your jni. There are errors otherwise
            jniLibs.srcDirs = ['libs']
        }
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

4. build.gradle [andEnginePhysicsBox2DExtension]

apply plugin: 'com.android.library'
android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "org.andengine.extension.physics.box2d"
        minSdkVersion 15
        targetSdkVersion 19

        ndk {
            moduleName "andenginephysicsbox2dextension"
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jni.srcDirs = []
            jniLibs.srcDirs = ['libs']
        }
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
dependencies {
    compile project(':andEngine')
}

5. build.gradle [ET Module]

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'

    defaultConfig {
        applicationId "com.cls.etxxxxx"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':andEngine')
    compile project(':andEnginePhysicsBox2DExtension')
}

6. settings.gradle [Project]

include ':ET', ':andEngine', ':andEnginePhysicsBox2DExtension'

7. ndk-build

Now to compile the jni part. Add this line to Application.mk located inside jni folders of both the andEngine library modules.

APP_PLATFORM:=android-19

Now give the command inside the jni folders:-

C:....../jni>ndk-build

This will compile the .so and put them in the libs folders of the modules

8. gradle sync and build

Thats all. Hopefully it should build for you :-).

Edits

Added github integration