Friday, January 22, 2016

How to install Ubuntu Core and work with it

Ubuntu is the most popular Linux distro which handled by canonicals. It offers several installations which is customized such as gnome-ubuntu, ubuntu-core. Ubuntu core is a light version of ubuntu which is not a installation iso but its a file system to work with linux in minimal resources.

After you setup the Ubuntu core you get only the file system with Ubuntu repos, shell, grub and other initial items for linux. It is very good to try this out because this gives you a good knowledge of the linux file system how format the disk, how to install grub, how make the disk bootable, how will kernel interact with grub and so on.

Firstly you have to download the Ubuntu-core rootfs (root file system). You can download the ubuntu 14.04.3-core root file system in this link http://cdimage.ubuntu.com/ubuntu-core/releases/14.04/release/



Download the tar ball.Then you need a ubuntu live cd to boot the machine. Boot the machine using live CD and select try Ubuntu. Get the shell and type sudo gparted. Using gparted you can create, delete, format partitions and select which one should be the boot partition, which one is the swap and so on. Same thing can be done using fdisk also in terminal. To learn how to use fdisk follow this link. In this case using any preferred tool that you familiar create one partition including the whole size of the disk. After you create the partition the sdx will change to sdx1(x is the disk. may be a/ b/ c). And after that make it the boot partition. This can be done easily using gparted, right click on the partition create a flag. To do this in fdisk type 'a' after you created the partition and then type '1' . And make sure that the partition you've created is formated with ext4 format. Because other wise you would not be able install grub. You can easily format to ext4 in gparted but if you used fdisk to create the partition you can format the partition to ext4 format using the mkfs tool. Type the following command to do that.

mkfs.ext4 /dev/sda1

Now you have a partition to make you core file system and it's fs is ext4. So firstly you have to mount this partition to a folder in live boot cd. Because when  we are boot from live cd it's showing us the file system on that live cd. In order to access to the hard drive that you have you should mount that disk into some where in this live cd file system. We are going to mount our disk into /mnt directory. Type the following command to mount

sudo mount /dev/sda1 /mnt

Then your partition have mounted to the /mnt directory. Now go to your /mnt directory using cd /mnt . Now you are in your partition. Now we are going to extract the ubuntu core root file system in to our disk (/mnt). Firstly copy the ubuntu-core-rootfs tar file in to /tmp directory. Then execute the following command.

sudo tar -zxvf /tmp/ubuntucore-rootfilesystem.tar.gz

No error should be raised. Then go to /mnt directory and check whether there are files. You can see a file system in /mnt.

Now we have to copy the resolv.conf file because else the system cannot resolve dns. to  do this type

sudo cp /etc/resolv.conf /mnt/etc/resolv.conf

Now we should run the following command

for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i;  done

what this command does ? Before you execute this command check the /mnt/dev , /mnt/proc and /mnt/sys. Check after the command executed. You will see new files are there which was not before executing the command. This will mount the sub trees of the given directories(this case /dev /dev/pts /proc /sys) in to a mentioned directory (this case /mnt) which makes source directory content available in both destination and source directories. So the files inside live cd /dev /dev/pts /proc /sys are also available in /mnt/dev/ mnt/dev/pts /mnt/proc /mnt/sys.

Now we should chroot in /mnt inorder to execute commands in our new file system. What is chroot? In normal case you are root in live cd file system ( / ). But in this case we need to be the root file system is /mnt/ directory. Then only the changes that we are executing are affects to our new file system. Other wise our changes affects to live cd file system which will erased after reboot. So we should make chroot to /mnt directory. Type the following command

sudo chroot /mnt

If command worked now terminal should like root@ubuntu:~ 

Now we should install our linux kernel. To install kernel type the following command

apt-get update && apt-get install linux-{headers,image}-generic

If "failed to fetch" like error is on terminal try following.
edit the /etc/resolv.conf (actually in /mnt directory, /mnt/etc/resolv.conf) and at the end at the following
nameserver 8.8.8.8

Some times during the installation you may prompt to install grub. This is very important. Grub must be installed in order to boot in to kernel. When It's prompt to install grub using tab select the ok and press enter. Then you will ask to which disk you should install. You will see two or more options there make sure you are selected sda ('a' may change as to your setup.) and not sda1. You should select the device not the partition. After you highlight it using arrow keys press space bar to select it. then * mark will apear infront of it. Then using tab go to ok and press enter. Grub will install.

To make sure Grub installed correctly go to  /mnt/boot/ directory and see is there files like vmlinuz (kernel image), initrd and go to /mnt/boot/grub directory and check is there file called grub.cfg . If it's not there that means grub has not installed correctly. You have to reinstall it.

do apt-get update   # ***
note : *** is  necessary to retrieve grub packages.
 and
apt-get purge grub grub-pc grub-common

in any of above apt-get install or apt-get purge case if get an error saying use apt-get -f insatll to install the package type in the terminal

apt-get -f install

It will install, remove and upgrade relevant packages.

If you get an error in updating or apt-get install ing saying cannot resolve try ping internet host. Try to make the internet connection.

If every thing is ok you should have a file system in /mnt directory, grub.cfg file in /mnt/boot/grub, vmlinuz in /mnt/boot, initrd in /mnt/boot , resolv.conf in /mnt/etc

Now we should create a user and we should make the user to have root privileges.

type commands

useradd user_name
passwd user_name
when it's prompt to type a password type the preferred password

nano /etc/sudoers
we are editing this file to make our user to be root privileges.
the file content is as follows,
# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

This is the part we are going to change. Change it as follows
# User privilege specification
root    ALL=(ALL:ALL) ALL
user_name ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

now reboot and enjoy Ubuntu core


     

Monday, January 18, 2016

How to recover files in Linux

Recovery is necessary thing  todays computer world because of the value of the computer data is higher. I have explained how a file can be recovered if it has been deleted and I have explain how it happen in a previous post. So in this post I'm going to discus a technique/ tool to recover files in Linux systems because there are lots of tools to achieve this on windows.

There are many command line tools to recover files in Linux systems which are working in different way. Here I will mention about the Testdisk tool which is very use full tool when recovering damaged hard disks also. In this article we are focusing only how to recover a file which has been deleted from the linux file system.

Installing Testdisk