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