Friday, February 12, 2016

HOW TO CREATE A LINUX FROM SCRATCH (LFS) BOOTABLE FLASH DRIVE

This is part of my journey in building an LFS system. I have previously posted the details in creating an LFS bootable usb flash drive, but I was not able to give the step-by-step details. This post will give the step-by-step details that I do to create the LFS bootable usb flash drive.

Note: This will erase the data on your usb flash drive.

There is an instruction in the LFS site here that provides the information on how to create a bootable usb flash drive, and I quote


BOOTING FROM ISO IMAGE


If you want to boot this CD on a computer without a CD-ROM drive, follow the steps below.

Store the ISO image of this CD as a file on a partition formatted with one of the following filesystems: vfat, ntfs, ext2, ext3, ext4, jfs, reiserfs, reiser4, xfs
Copy the boot/isolinux/{linux,initramfs_data.cpio.gz} files from the CD to your hard disk
Configure the boot loader to load “linux” as a kernel image and “initramfs_data.cpio.gz” as an initrd. The following parameters have to be passed to the kernel:
rw root=iso:/dev/XXX:/path/to/lfslivecd.iso rootfstype=fs_type
where /dev/XXX is a partition where you stored the LiveCD image, and fs_type is the type of the filesystem on that partition. You may also want to add “rootflags=…” option if mounting this partition requires special flags.
If there is only Windows on the target computer, please use grub4dos as a boot loader. It is available from http://sourceforge.net/projects/grub4dos.

MAKING A BOOTABLE USB DRIVE

Install GRUB on a flash drive, then follow instructions in the “BOOTING FROM ISO IMAGE” above, using a partition on your flash drive. The following tips will ensure that the flash drive is bootable in any computer:
  • Use the persistent symlink such as “/dev/disk/by-uuid/890C-F46A” to identify the target partition.
  • Add “rootdelay=20” to the kernel arguments.

In summary and  from the instructions above, to create the bootable usb flash drive we will:

1. Format the flash drive.
2. Install grub on the flash drive.
3. Create a grub config file.
4. Copy the livecd iso to the flash drive.
5. Mount the livecd iso.
6. Copy the files /boot/isolinux/{linux, initramfs_data.cpio.gz} to the flash drive.
7. Edit the grub.cfg file.

Now for the details:

--> FORMAT THE FLASH DRIVE:
Before I format the flash drive, I delete everything from my flash drive by deleting and then creating a new partition. To delete/create a new partition:

# fdisk /dev/sdb      // where /dev/sdb is my flash drive

Inside fdisk:

d - delete the partition
o - create a new empty dos partition table (mbr)
n - add a new partition, then accept all the defaults
w - write then exit.

To format the flash drive

# mkfs.ext2 /dev/sdb1    // I first try to use ext4 as the file system but 
                         // it won't boot complaining about the filesytem
                         // So, I format the drive as ext2.


--> INSTALL GRUB ON THE FLASH DRIVE:
To install grub on the flash drive:

# grub-install --root-directory=/media/usb0 /dev/sdb

where: /media/usb0 is the mount point of the flash drive.

--> CREATE A GRUB CONFIG FILE:
To create a grub.cfg file:

# grub-mkconfig -o /media/usb0/boot/grub/grub.cfg

Note: the grub.cfg file that will be created will contain the files similar to
      the linux system that you are using, thus the need to edit the file.

--> COPY THE LIVECD ISO TO THE FLASH DRIVE:
To copy the livecd iso go to the directory where you put your livecd iso then:

# cp lfslivecd.iso /media/usb0

--> MOUNT THE LIVECD ISO:
To mount the livecd iso:

First create a mount point on your present linux system.

# mkdir /mnt/mount_point

where: mount_point is any name that you like.

Then mount the lfslivecd iso:

# mount -o loop -t iso9660 lfslivecd.iso /mnt/mount_point

--> COPY THE FILES /boot/isolinux/{linux,initramfs_data.cpio.gz} TO THE FLASH DRIVE:
To copy the two files to the flash drive, go inside the directory where you mount the lfslivecd:

# cd /mnt/mount_point/

Then copy the two files:

# cp boot/isolinux/{linux,initramfs_data.cpio.gz} /media/usb0

-->EDIT THE GRUB.CFG FILE:
Editing the grub.cfg file is done because when we create the grub.cfg file with
grub-mkconfig command, the created grub.cfg file reflects the grub.cfg file of the system that we are working on. And also to reflect the instructions by the site as quoted above:

The edited grub.cfg file should look something like this:

menuentry 'Linux From Scratch LIVE USB' {
    search --no-floppy --fs-uuid --set=root fb90e35b-5223-489e-9a21-01d2e343f9
    echo  'Loading Linux From Scratch....'
    linux  /linux rw root=iso:/dev/sdb1:/lfslivecd.iso rootfstype=ext2 rootdelay=20
    initrd  /initramfs_data.cpio.gz
}

where:  fb90e35b-5223-489e-9a21-01d2e343f9 is the uuid of my flash drive
        you can find the uuid by:
             # blkid

That's it. This are what I did to create my bootable LFS live USB.

        


Saturday, January 16, 2016

How to build libimobiledevice from source in Linux (kali)

In this post and this post, I was able to restore an iphone 5 and iphone 4s using idevicerestore which uses the libimobiledevice library. Below is the procedure on how I build libimobiledevice from source.

My OS:

Linux sil3ntBox 4.0.0-kali1-686-pae #1 SMP Debian 4.0.4-1+kali2 (2015-06-03) i686 GNU/Linux


This is after I fresh-install the xfce version of kali linux.

A libimobiledevice library is already installed by default. It is called
as libimobiledevice4 when you do apt-cache search. This is the reason
why when I connect the iPhone, it is detected by the OS.

But the important thing is to use the utilities based on libimobiledevice
to communicate with the iPhone. The utilities such as ideviceinfo, idevice_id,
etc. To be able have the utilites, you have to download the source of
libimobiledevice. Using apt-get you can download the source of the library.

        apt-get source libimobiledevice

notice that I only use libimobiledevice rather than libimobiledevice4. They are
the same since according to apt-cache show libimobiledevice4:

        Package: libimobiledevice4
        Source: libimobiledevice

After downloading the source, extract them on the current folder or any folder
you want.


Inside the  extracted directory I run:

        ./configure


  eventhough according to the README file included

        to compile run:

           ./autogen.sh
           make
           make install

  since there is no autogen.sh file inside the folder.


This is where I encounter my first error.

Silly me. :)

According to the README

  ---------------------------------------------------
        Requirements
        ============

        Development Packages of:
                libgnutls or openssl
                libplist
                libusbmuxd

        Software:
                usbmuxd
                make
                autoheader
                automake
                autoconf
                libtool
                pkg-config
                gcc

        Optional:
                cython (Python bindings)
                doxygen (Documentation)
   -----------------------------------------------------

So I downloaded all the packages stated above.

This are the errors in sequence as I do ./configure after every package I
installed just to see what is going on..

    --------------------------------------------------------------------------------
        ERROR                                   |       SOLVED BY:
    --------------------------------------------------------------------------------
                                                |
    configure: error: The pkg-config script.... | apt-get install pkg-config

    No package 'libusbmuxd' found               | apt-get install libusbmuxd-dev

    No package 'libplist' found                 | apt-get install libplist-dev

    No package 'libplist++' found               | apt-get install libplist++-dev

    Error:                                      |
       You probably have to install the         |
       development version of the python        |
       package....                              | apt-get install cython

   ..cannot find libplist Cython bindings..     |
   configure: error: OpenSSL support            | apt-get install libssl-dev


After the last installation, ./configure continues without any error.

Then sudo make, sudo make install, to complete the installation.

----------------------

The above is copy-pasted from my notes as I do the installation. Sorry for being lazy.. :) ..










Thursday, November 5, 2015

Restoring iPhone 4s using idevicerestore in Linux

Below is a recording of the restore process of my iPhone 4s as I restore it to the latest version of 9.1 using idevicerestore in Linux. Restore is done at the 7:57 mark.


Monday, September 28, 2015

Speed Test in Linux

If you want to test your internet speed using command line in Linux without using a browser, you can use speedtest-cli.

speedtest-cli is an application created in python by sivel (Matt Martz). At his git repository  https://github.com/sivel/speedtest-cli , there are several ways to download and install the application. In my case, I git-clone it.

here's what I did:

git clone https://github.com/sivel/speedtest-cli

then install:

 python setup.py install

here's the screenshot of my internet speed.



Tuesday, September 22, 2015

CHERRY MOBILE OMEGA ICON hang on logo only Problem.

Phone Problem:

    Hang on logo

Files needed:

1. Omega icon stock firmware to be downloaded here.
    (This is a 17-part rar'ed flash file.)

2. PC with adb and fastboot installed.

Procedure:

This procedure is done using Linux.

Extract the flash files in a directory. Open terminal and cd to the directory
where you extracted the files. Then type the ffg one by one.

    fastboot flash aboot emm_appsboot.mbn
    fastboot flash sbl1 sbl1.mbn
    fastboot flash tz tz.mbn
    fastboot flash rpm rpm.mbn
    fastboot flash sdi sdi.mbn
    fastboot flash modem NON-HLOS.bin
    fastboot flash cache cache.img
    fastboot flash usbmsc usbdisk.img
    fastboot erase splash
    fastboot flash splash splash.img
    fastboot -S 256M flash system system.img
    fastboot flash recovery recovery.img
    fastboot -S 256M flash userdata userdata.img
    fastboot flash boot boot.img
    fastboot reboot

Afte the phone reboots, wait till it fully opens.

below are the screenshots of the flashing process and the phone after flashing.



Wednesday, July 1, 2015

My Journey to building Linux From Scratch (LFS) system PART3

 
CHAPTER 3

Now that we have the bootable USB flash drive, we can continue now by creating a partition onto which we will install our LFS system.

According to the book, we create a linux native partition and a swap partition using either cfdisk or fdisk.

using fdisk, I created a 40GB primary partition and a 2GB swap partition.

Now we will create a file system on the newly created partition. According to
the book, we should create an ext3 file system using the E2fsprogs
utilities. Specifically mke2fs.

    #mke2fs -jv /dev/sda1 
where:

sda1 is my first partition.
mke2fs - is a program that creates an ext2/ext3 filesystem
- the "-j" means the create the filesystem with an

Then we initialize our swap partition.

    #mkswap /dev/sda2

    where: /dev/sda2 is our swap partition

To check, type blkid at the prompt, there should be an entry about /dev/sda1
and /dev/sda2

To access the partition, we mount it at /mnt/lfs.

    #export LFS=/mnt/lfs    -sets a variable LFS equal to /mnt/lfs
    #mkdir -pv $LFS            -create a directory /mnt/lfs
                                            -"-p" means parent, "-v" means verbose
    #mount -v -t ext3 /dev/sda1 $LFS
                                            -mount our first partition to /mnt/lfs
                                            -meaning we can access our first partition via
                                             /mnt/lfs
note: make sure that the partition is mounted without too many restrictions
e.g. nosuid,nodev or noatime options, by using mount command.

    #mount
   
    the /dev/sda1 line should not show (nosuid,nodev,noatime)


Enable the swap partition using the swapon command

    #/sbin/swapon -v /dev/sda2


Now we can download the packages and patches needed to build the basic LFS system. But since we are using the livecd as our base system, we don't need to download the packages, we just copy the packages from the /lfs-sources/ directory of the livecd to our newly created partition.   

We need to create first a directory where we will install the packages and the patches.

    #mkdir -v $LFS/sources

then we make this directory writable and sticky. sticky means multiple user
have write permission but only the owner can delete a file within this
directory.

    #chmod -v a+wt $LFS/sources

   where:     a+w - means all have write access
                       t   - means sticky

Now we download, or in our case, copy all the contents of /lfs-sources
directory to $LFS/sources.

inside /lfs-sources directory:

    root[ /lfs-sources ]# cp * $LFS/sources

    where: cp - the copy command

After copying the files and patches:



CHAPTER 4 - Final preparations

According to the book, we will create a $LFS/tools directory. This directory
will contain the installed programs compiled in CHAPTER 5 to separate them from the programs compiled in CHAPTER 6. The programs compiled here are temporary tools only and will not be a part of the final LFS system.

as root:
   
    #mkdir -v $LFS/tools

then we create a /tools symlink on the host system that will point to the
$LFS/tools directory we just created

    #ln -sv $LFS/tools /


the command ln above creates a link between the two files. The target file is
$LFS/tools (/mnt/lfs/tools), with a link name that is the same as the target
file and is located at the / (root) directory. The -s means create a symbolic
(or soft) link. So from the command above a soft link with a name /tools is
created that is linked to the directory $LFS/tools (or /mnt/lfs/tools).

Then we add user/group both named lfs

    #groupadd lfs
    #useradd -s /bin/bash -g lfs -m -k /dev/null lfs

where:  -s /bin/bash  : makes bash the default shell for the user
                  -g lfs         : adds user to the group lfs
                      -m         : create a home directory for user lfs
             -k /dev/null    : the skeleton directory that contains the files and
                                     directories to be copied to the home directory.
                                     /dev/null contains nothing. The significance of -k
                                    option is that if it is not specified the default
                                    /etc/skel files and directories will be copied to the
                                    home directory.
                      lfs        : is the name of the user


then give lfs user a password

    #passwd lfs

grant user lfs ownership of $LFS/tools  and $LFS/sources directory

    #chown -v lfs $LFS/tools 
    #chown -v lfs $LFS/sources

then we login as user lfs

    #su - lfs

where:     su    :    switch user
                 -     :    start a login shell as opposed to only switch to user
               lfs    :    switch as user lfs

   
then we setup a clean working environment from which building the temporary lfs system is based.

while logged in as user create two startup files, .bash_profile and .bashrc, for the bash shell.

    lfs [~]$cat > ~/.bash_profile <<"EOF"
           exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' bin/bash
           EOF

where:    exec env -i.. /bin/bash - 


means replace the shell with a new one with an empty environment except the variables HOME,TERM and PS1
   

    lfs [~]$ cat > ~/.bashrc << "EOF"
             set +h
             umask 022
             LFS=/mnt/lfs
             LC_ALL=POSIX
             path=/tools/bin;/bin;/usr/bin
             export LFS LC_ALL PATH
             EOF


then source the just created user profile:

    lfs [~]$ source ~/.bash_profile



next: CHAPTER 5

Friday, June 26, 2015

My Journey to building Linux From Scratch (LFS) system PART2

cont. from part1


The book provides link for FAQ and some references. For FAQ, the link is
http://www.linuxfromscratch.org/faq/.

Since we will create our LFS system by-the-book, we are going to follow the
book chapter by chapter. Chapter 1 of the book just provides us with the
introduction, some information, references and prerequisites. The above
information are taken from chapter 1 of the book.


CHAPTER 2: Preparing the new partition.

In this chapter, it shows us the instruction in creating a partition for our
base system. In my case, I will be using the whole partition of my netbook onto which I will install my LFS system. BTW, in this journey I will be installing the system on an ACER Aspire One netbook. This netbook doesn't have a CD-ROM, hence the reason that I will be creating a bootable USB. The book states a primary partition and a swap partition is going to be created. It also states that a 1.3 GB partition (up to 2-3 GB) is enough as a primary partition.

To create a partition cfdisk or fdisk command is used, as per the book. This
means that we must be already inside our host system. For those that have a
CD-ROM drive just boot your computer using the liveCD. For those that don't
have, We need to create first our bootable USB.

At this time, I will be deviating first from the books' instruction to create my
bootable USB.

According to the live CD documentation, we should install first GRUB on our
flash drive. But no instruction is given on how to install GRUB on our flash
drive. Now the first stumbling block. But since we're here to learn, we will
going to find everything we need to know about GRUB. What is GRUB? GRUB means GRand Unified Bootloader. A bootloader is a software that first runs when the computer starts. According to GRUB's manual, there are two versions of grub, grub-legacy and grub2.

To install GRUB on our flash drive, we invoke the grub-install command. Now
this looks like we really need another linux system with grub already installed to install GRUB on our flash drive. In my case, I already have a working linux system and I use my present system, I use Kali Linux btw, to install GRUB in my flash drive. So to install GRUB:
   
    #grub-install --root-directory=/media/usb0 /dev/sdb

    where     /media/usb0 - is the mount point of my USB flash drive.
                   /dev/sdb - is the flash drive.
then create a grub.cfg file

    #grub-mkconfig  /media/usb0/boot/grub/grub.cfg

After installing grub, according to the liveCD documentation, we follow the
"BOOTING FROM ISO IMAGE" section of the documentation. It states that we copy the ISO image as a file into our drive and configure the boot loader to load "linux" as a kernel image and "initramfs_data.cpio.gz" as initrd.

"Store the ISO image of this CD as a file on a partition formatted with the
following filesystems: vfat, ntfs, ext2, ext3, ext4, jfs, reiserfs, reiserfs4,
xfs. Copy the /boot/isolinux/{linux,initramfs_data.cpio.gz} from your CD to the hard disk."

From the above instruction, we should format our flash drive with the above
mentioned filesystem and then copy the ISO image that we downloaded to the flash drive. Then after that we copy the
/boot/isolinux/{linux,initramfs_data.cpio.gz} files from the CD to our flash drive. The "hard disk" instruction above is applicable only if you want to boot from hard disk, since we are using our flash drive as a bootable device, we replace the hard disk with our flash drive.

Now to copy the files "linux, initramfs_data.cpio.gz" to our flash drive
we mount the ISO image. First we create a mount point and mount the ISO image to that mount point and then copy the aforementioned files.

 
#mkdir mount_here
#mount -o loop -t iso9660 lfslivecd.iso mount_here

where: mount_here is the mount point of our USB flash drive at the current working directory
then we can go the directory /boot/isolinux and copy the two aforementioned files to our flash drive.

After copying the ISO image and the two files, we configure the bootloader to load "linux" as the kernel image and "initramfs_data.cpio.gz" as initrd. 
From the same section above, we should pass the following as a kernel parameter.

rw root=iso:/dev/xxx:/path-to-livecd.iso rootfstype=fs_type rootdelay=20

where:     /dev/xxx - is the partition where we copy the lfslivecd.iso image
   
To configure our configuration file, we edit the created grub.cfg file to
something similar as below.

menuentry 'Linux From Scratch Live USB' {
    search --no-floppy --fs-uuid --set=root e0f3e26a-1d46-4478-9f1d- 635dd53ff488
    echo 'Loading Linux From Scratch...'
    linux     /linux rw root=iso:/dev/sdb1:/lfslivecd.iso rootfstype=ext2 rootdelay=20
    initrd    /initramfs_data.cpio.gz
}

where:    e0f3e26a-1d46-4478-9f1d-635dd53ff488 is the UUID of my USB flash                 drive.


Here is the screenshot when I boot my live USB LFS.






to be cont....