Sunday, April 13, 2014

Repairing GRUB2 on OpenSUSE

Hi today I will make a short tutorial on how to repair grub2 when you have broken it due to some reason or the other.

This tutorial assumes that you have booted into SUSE in Live mode either using a bootable USB or live DVD. If you haven’t already booted into a Live version of SUSE please do so now.

I normally go with a reinstall but there is nothing like trying to save your system first with these steps.

First we identify which partition is our root partition.

Normally hard disk partitions follow the naming convention /dev/sdXY where (X is a,b,c depending upon where the disk is mounted in most systems the internal harddisk is /dev/sda and Y corresponds to the partition number). E.g. /dev/sda6 would mean the 6'th partition of the disk device located at /dev/sda.

In order to find out what the root partition of your SUSE install from  is type "lsblk" and look at the output.

>lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 298.1G  0 disk
├─sda1   8:1    0   400M  0 part
├─sda2   8:2    0 149.4G  0 part
├─sda3   8:3    0 108.3G  0 part
├─sda4   8:4    0     1K  0 part
├─sda5   8:5    0     2G  0 part [SWAP]
├─sda6   8:6    0  15.4G  0 part /
└─sda7   8:7    0  22.6G  0 part /home
sr0     11:0    1  1024M  0 rom 

Note this is the output of a working system. What is most important is the SIZE attribute. By looking at the SIZE you probably will be able to guess which partition is your root partition. If you find it hard to identify which is your root partition by size alone you can try mounting each partition and inspecting its contents and then unmounting the partition keep trying this till you identify a partition that is your root partition. Once you know which partition it is unmount it too. (The use of the mount command to mount and unmount the partitions is out of scope of this tutorial please use "man mount" to have a look at the mount commands manual page or look online)

Then follow the steps below. Here sdXY (e.g. /dev/sda6) refers to your root partition of Suse and sdX refers to the hard disk itself (/dev/sda)
  1. su
  2. mount /dev/sdXY /mnt
  3. mount --bind /dev /mnt/dev && mount --bind /dev/pts /mnt/dev/pts && mount --bind /proc /mnt/proc && mount --bind /sys /mnt/sys
  4. chroot /mnt
  5. grub2-install /dev/sdX
  6. grub2-mkconfig -o /boot/grub2/grub.cfg

Let me briefly explain what we are doing above here.
  1. In the 1'st command we are entering into the root shell from the live distribution. 
  2. In the 2'nd command we mount the root partition of the system to /mnt of the live distro. 
  3. In the 3'rd command we bind mount certain folders from the live distribution which will be used later to repair grub. 
  4. In the 4'th command we change the root from the root of the live distribution to the root of the installed distribution. So now we are no longer running as root in the live Suse but as root in the installed Suse OS. 
  5. In the 5'th command we reinstall grub2
  6. in the 6'th we run a command to remake grub2's configuration so that it searches for installed OSes etc. and makes the configuration files 

Saturday, April 5, 2014

How to find out which packages are taken from which repository in OpenSUSE/SUSE ?


Normally we often add repositories for specific applications for which we want the latest. Sometimes we get stuck in a soup where the whole repo suddenly goes down and we want to find what packages were in the repo.

Well if you are stuck in the same soup as I was then the following steps below might help.

1) Identify the names of the repositories. Go to yast -> Software repositories. Lets assumed we named a repository "xyz" (Note: this can be the repository alias/URI) 

Scenario 1: The repository is up and I want to know which packages where obtained from that alias/URI

zypper se -sir xyz  

Scenario 2: The repository is down and I want to know which packages where obtained from that alias/URI. In this case we must force a no refresh otherwise we won't get valid/useful output
zypper --no-refresh se -sir xyz

 
That's it. Now to show you some sample output of a real command.

zypper --no-refresh se -sir KDE:Extra
Loading repository data...
Reading installed packages...

S | Name                | Type    | Version   | Arch   | Repository
--+---------------------+---------+-----------+--------+-----------
i | dropbox             | package | 1.6.0-4.4 | x86_64 | KDE:Extra
i | kcm_tablet          | package | 2.0-1.6   | x86_64 | KDE:Extra
i | kcm_tablet-lang     | package | 2.0-1.6   | noarch | KDE:Extra
i | lensfun-devel       | package | 0.2.7-5.3 | x86_64 | KDE:Extra
i | lensfun-doc         | package | 0.2.7-5.3 | x86_64 | KDE:Extra 

Now assuming that the KDE:Extra repository which I have is now defunct I can see what packages were installed from there and either remove them or find another repo which has them and take appropriate action.

Go ahead and feel free to try it out.

AN IRC buddy had suggested a way to isolate and display only package names intead of the entire table.

His command syntax was:

zypper se -sir 12 | awk '$1 ~ /^i/{print $3}'


Feel free to try it out.