Saturday, November 8, 2014

Adding rules for MTP and getting your device to work on OpenSUSE

MTP is the Media transfer protocol. It allows files to be transferred to and from media devices. MTP does not allow operations such as editting and modifying the file. MTP  is different from USB mass storage. With MTP the device still has full control over the file system.

Of late Android devices only allow you to transfer data to/from them via MTP/PTP. New devices may or may not be detected.

In order to ensure that a device is detected on openSuse you will need to learn to add and manage udev rules.

We will take the example of a pretty new budget android phone called the Xaomi RedMi 1s. 
When we plug it into Suse and enable MTP nothing appears to happen. Though we expect to be able to access the internal storage and SD Card via MTP.

This is because there are no rules on how to handle the MTP device.

I found that guides are very sparse online when it comes to MTP. So I decided to make a small write up to guide people.  

First we will install a package called "mtp-tools" this provides a number of command line tools for MTP.

zypper in mtp-tools

Once installed we make sure our device has MTP enabled and then we type "mtp-detect" command as root.

Sample output is shown below.
>mtp-detect
Unable to open ~/.mtpz-data for reading, MTPZ disabled.libmtp version: 1.1.6

Listing raw device(s)
Device 0 (VID=2717 and PID=1260) is UNKNOWN.
Please report this VID/PID and the device model to the libmtp development team
   Found 1 device(s):
   2717:1260 @ bus 2, dev 52
Attempting to connect device(s)
ignoring libusb_claim_interface() = -6PTP_ERROR_IO: failed to open session, trying again after resetting USB interface
LIBMTP libusb: Attempt to reset device
Android device detected, assigning default bug flags

<----- Output Clipped ----->

What is most important here is the VID and the PID with this information rules can be formulated.

By adding an MTP rule we can get KDE to pickup the device.

MTP rules as of libMTP version 0.9 onward are stored in /usr/lib/udev/rules.d/69-libmtp.rules

The udev rules for MTP devices follow the below syntax typically.

ATTR{idVendor}=="<VID here>", ATTR{idProduct}=="<PID here>", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"

So in our case assuming VID of 27217 and PID of 1260 the udev rule becomes:

ATTR{idVendor}=="2717", ATTR{idProduct}=="1260", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"

There are more options which can be added here such as "mode" and "group" but these are rarely required. In most cases setting ENV{ID_MTP_DEVICE} and ENV{ID_MEDIA_PLAYER} to "1" should suffice.

After the rule line has been added along with the existing rule lines in /usr/lib/udev/rules.d/69-libmtp.rules you are almost set.

Now all that is left is to apply the new rules and restart the udev service with the below 2 commands.

udevadm control --reload-rules
service udev restart

These two commands are used to reload rules and restart the udev process with the new rules. Now disabling and enabling MTP on the device should allow you to connect to the device via MTP from OpenSuse.

Hope this short guide helps.

Troubleshooting:
Q 1) I have followed allt he above rules, the MTP device(s) do not show up on KDE still. What do I do ?
1) Test if mtp works from terminal.
 as user type the command mtp-filetree wait for the command to complete initially you will only see few string containing device info. Once the command finishes (may take a minute or more even) you should see a list of files on your device. If you do then that means MTP is working properly.

Sample output below:

Device 0 (VID=2717 and PID=1260) is UNKNOWN.
Please report this VID/PID and the device model to the libmtp development team
Attempting to connect device(s)
Android device detected, assigning default bug flags
Device: (NULL)
Storage: Internal storage
1 FolderFoo
  2 .data
    478 b697b2b6ae559e26f3fc90abb449faa2
    480 7c7320086a99708c28138fd086553e33
    481 eb0d265b69315673573eb5a47d4b8df4
    8534 58074bc9565a44d9c57b11394be867e0
    8535 230d3b2452c6b7e32b74b2beae943a49
    13204 ed38625755998a993a67dd1e93a5fac6
    13205 02fd4baa976f28991a35bfd05a5fa269

Here you can see a folder called  "FolderFoo" and the contents of another sub-folder folder inside "FolderFoo" called  ".data" and its contents. If you see this kind of output that means MTP protocol level communication between your system and your device and your linux PC is working fine.

This indicates the problem is most likely a DE problem. For KDE you need to install a package called "kio_mtp" by using the code below.

zypper in kio_mtp

Note: the package may be called by a slightly different name if so just run

zypper se mtp

and look for a package with the 'kio' words in it and install.

Monday, August 4, 2014

Mounting disks as non root from the shell

The most popular method for mounting disks and the most traditional method is the "mount" command.

In most cases (with the exception of specifying before hand that unprivileged users can mount specific disk in /etc/fstab) the "mount" command requires root privileges.

Now often the question becomes "How come I can use a file manager to mount regular disks E.g. USB's, external HDD's without root and the mount command requires root ?"

The answer to this is to use the more traditional "Udisks1" or the newer "Udisks2" there has been a debate on why Udisks is better than Udisks2 but keeping the debate and arguments aside both tools serve the purpose.

For Udisk1 (the original) the command line  utility is "udisks". For Udisks2 (the rewrite) the command line utility is "udiskctl" both can coexist and normally do coexist on most linux distributions but are different. Both however are used for managing storage devices.

The original Udisks mounted all partitions in "/media/<partition-name> " E.g. /media/linux_data (Where linux_data is the partition name)

The new Udisks2 mounts storage devices  in /run/media/<username>/<partition-name> E.g. /run/media/lin-user/linux_data (WHere username is lin-user and partition is linux_data).

Note: /var/run is a symbolic link to /run so Udisks normally states that it has mountded the disks to
 /var/run/media/<username>/<partition-name> E.g. var/run/media/lin-user/linux_data (you can reference the same storage device as a directory using /run/media/ or /var/run/media/ it does not matter)

Now armed with basic info on the tools we will be using lets go ahead and try to use the tools mentioned above to mount and unmount storage devices.

Typical steps involved:

1) Plug in the storage device (if its an internal HDD and just an unmounted drive you can skip this step.)
2) type "lsblk" and look at the output to determine which drive/block-device you are interested in mounting E.g. /dev/sdb1 or /dev/sdc3 or /dev/sda2 etc.
3) Use Udisks or Udisks2 syntax to mount the specific drive automatically.

Udisks and Udisk2 syntax

Udisks syntax:

a) mounting a drive
udisks --mount /dev/sdX
E.g. udisks --mount /dev/sdb2

b) unmounting a drive
udisks --unmount /dev/sdX
E.g. udisks --unmount /dev/sdb2

The syntax is very clean and easy to use for udisks


Udisks2 syntax:
The syntax is for udisk2 is different.

a) mounting a drive
udisksctl mount -b /dev/sdX
E.g. udisksctl mount -b /dev/sdb2

b) unmounting a drive
udisksctl unmount -b /dev/sdX
E.g. udisksctl unmount -b /dev/sdb2

Note: there are no double dashes before the word "mount" and "unmount" also -b is a must so that udisks2 knows that you are giving it a block device to mount.

The advantage of udisks /udisks2 over the mount command is that you do not need to specify a mount location or create a special folder. Udisks/Udisks2 automatically exposes the device as a folder for you in the paths mentioned earlier on in the article.

Sunday, August 3, 2014

Fixing the problematic duplicate UUID issue

A UUID is a universally unique identifier. For disks UUIDS are used to uniquely identify a particular disk irrespective of in which order and when it is loaded. E.g. A UUID can be used to tell the system to always boot from the specific partition with a specific UUID irrespective of which order it is loaded in e.g. if there are 2 hard disk it may be loaded as /dev/sdb but another type as /dev/sda it would not matter.

Duplicate UUIDs occur only in rare cases. The most common cause is if you have cloned a disk using some utility. (E.g. dd). Duplicate UUIDs in general are not good and can cause progblems because the identifiers are no longer unique on the system.


The steps to solve this issue are:


1) type “blkid” on the main server and the other server as root. And identify the partitions and their corresponding numbers in /dev E.g. /dev/sda1, dev/sda2 .. /dev/sdX etc.. Now we
need to change only those partitions whose UUIDs match the UUIDs of partitions on the server.

2) generate as many random UUIDs as needed for the partitions. Using the “uuidgen” command. Running “uuidgen” in terminal will generate a random UUID e.g.
“4ae70274-5b0f-4384-a7fd-15fcbdbd0b58″ do this twice or thrice or as many times as needed.

4) Assign these randomly generate UUID’s to the partitions. This needs root privileges; the command is “tune2fs /dev/sdX -U New-UUID-Value”
E.g.: sudo tune2fs /dev/sda2 -U 73c6756e-aad2-41f6-8dff-597fe076cd07

Wednesday, July 16, 2014

Creating a live USB for openSUSE


               
There are multiple ways to create live USBs

In this article I will outline methods which I have tried and tested. Though this blog does have an OpenSUSE flavor, the advice mentioned below is appropriate for multiple distributions.

Things you will need :
  • A blank USB thumb drive with at least 2GB of capacity available. Please do not store any personal data on this, as all existing data will be wiped out by this process. 2GB is ideal you would not need any higher capacity than that. If you have an old one lying around that should do.
  • The OpenSuse ISO (disk image). This can  be downloaded from http://www.opensuse.org/en/ . Please note that the DVD version is not live, only the KDE/GNOME version.  

Creating a Live USB for first time users of Linux migrating from Windows:

I have tried and tested a wide variety of available options out there for creating live USBs for multiple distributions.

One very popular program that Windows users use is  Linux live usb creator (http://www.linuxliveusb.com/) . While this works well for most Linux distributions please do not use this for OpenSUSE.

On the other hand a much lesser known but open source utility which I have tested is universal-usb-installer .  It works like a charm.

The OpenSuse ISO (disk image) can  be downloaded from http://www.opensuse.org/en/  Please note that the DVD version is not live, only the KDE/Gnome version.

While both the 32 bit and the 64 bit ISO will work on a 64 bit system, it is better to get the 64 bit ISO for 64 bit systems. Most modern systems have the 64 bit architecture.

Also use the torrent download link if possible because that is more reliable than a direct download unless you have a really fast connection. ISOs are prone to corruption, being large files. But using a torrent solves that problem as error correction is performed by the protocol. (Always use the official torrent files they are trustworthy)

Once you have the ISO, install the universal-usb-installer and run through the wizard with your USB plugged in. Once it has finished you should have a bootable USB.

Creating a Live USB from linux:

This method is appropriate for people who:
1) Have already installed OpenSUSE/other linux distribution and want to create a live USB for emergencies
2) Want to switch distributions
3) Want to diagnose hardware/software issues and do troubleshooting.

In Linux I prefer to use methods which are non-distribution specific. I prefer to use utilities which are available in almost any Linux distribution.

One of the very powerful utilities available in linux is dd (disk-dump). This utility is a very powerful/dangerous utility and is to be used with great care. This utility could wipe out your whole internal disk if abused and therefore requires that you have root privileges.

Open a linux shell and type "lsblk" This is a command to list block devices. Below is sample output of the command


linux@linux:~> lsblk

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda          8:0    0 298.1G  0 disk
├─sda1   8:5    0     2G  0 part [SWAP]
├─sda2   8:6    0  15.4G  0 part /
└─sda3   8:7    0  282.6G  0 part /home
sdb          8:16   1   3.7G  0 disk
└─sdb1   8:17   1   3.7G  0 part


In general most internal hardisks are mounted at the sda location. Look at the size column of the output to identify which block device your USB is. In the above same output you can see "sdb" has a size of 3.7GB and is 4GB USB device plugged in to my PC. It is safer to have only the USB you want to make a live USB plugged in so that it is easily recognizable.

If you look at the naming scheme you can understand that sdb1 is the partition and sdb is the disk itself. We are more interested in the disk and not the partitions.

So now that we have clearly identified the name of our USB device as viewed by the system it is time to dd in the ISO.

dd will completely erase everything on the USB thumb drive so it is important that there be no personal information whatsoever stored on the disk. There is no need to reformat the disk because the dd utility will do that for you.

Note: Because of the nature and power of the dd this utility needs root privileges (for the operation we are about to perform) to operate so please type "su" and enter into the root shell before executing the dd command. Also make sure you have the right block device; otherwise you may accidentally overwrite your internal hard disk.

the syntax is:

dd if=/path/to/iso_file.iso of=/dev/sdX bs=4M

Where sdX (X can be a,b,c,d,e,f,g,h etc. E.g. sdb,sdc) is the USB block device. bs=4M is used to speed up the write process.

So assuming the ISO is downloaded in ~/Downloads and the block device (USB) is the same as  we discovered by running the command lsblk  (i.e. sdb) the command becomes the following:

dd if=~/Downloads/openSUSE-13.1-KDE-Live-x86_64.iso of=/dev/sdb bs=4M

Notes about dd:
1) There is no space between "if" and "=" it is "if=path/to/iso" not "if = path/to/iso" Same applies for "of" and "bs"
2) It is "/dev/sdX" not "/dev/sdX1" we are concerned about the USB as a whole and not any partition.
3) As noted earlier too root priviledges are a must otherwise you will be able to write to /dev/sdb1 but not the USB itself the data will be transferred to the USB drive but the USB will be useless as it wont be bootable.

WARNING: Please double check everything is correct before executing the dd command as root one error can be a costly mistake specially double check the block device at "of=/dev/sdX" it should point to your USB thumb drive and not your internal hard disk drive or some other storage location like an external HDD. Failing to cross check may result in an accidental wipe of your entire internal hard disk.

Once you have executed the dd command, please wait patiently. dd does not display any output until the whole process is completed. You will see only a blinking cursor once the command has completed. At the end of the entire process it will tell you  the number of blocks read, the number of blocks written and the total amount of data written.

Since dd clones the ISO image directly to the USB and makes the partitions and sets the bootable flag, no other action needs to be done other than setting boot priority in your BIOS so that the USB boots first at boot time.


Additional notes:

What is a live distribution ?

Earlier on I mentioned that the DVD version of Suse is not live only the KDE/GNOME version. Then it struck me that some of you may wonder what is the real difference between a live and non-live distro; as a Windows user the concept of a live distribution does not exist.

A "live" distribution is a distribution/OS which you can try and sample without installing it on your host system. Live KDE/GNOME can be run straight off your thumb drive which you have created and can be tried out before actually installing it.

This feature also becomes very handy for troubleshooting and system repair in the event that something happens to your host PC and you cannot run the installed OS. So it is always handy to have a live linux USB lying around and at hand as it can be used to rescue important data and files in the event of a disaster depending upon its severity.

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.

Tuesday, March 25, 2014

OpenSUSE for the graphics artist


Ever wanted to become a professional graphics artists ? Cannot afford to buy photoshop etc. or want a lighter solution.

Linux offers good quality software for the  graphics artists be it painting , 3D content generation and even video.

For this tutorial we will be using OpenSUSE 13.1 with KDE (K Desktop Environment):

I will show you how to convert a fresh install fo OpenSUSE 13.1 KDE into a full fledged studio with all the bells and whistles needed for a professional graphics artist.

Things to do after a fresh install of SUSE:


1. Add the Packman repository to you SUSE distribution so that you can get the  latest software packages.
  • Go to Yast -> Software Repositiories and add the repository  whose URL is posted below
    • http://packman.inode.at/suse/13.1/  and call it "Packman-FULL"
  • Or Add the repository directly from terminal using the commands below (please close Yast if it is open before doing so)  
    • zypper ar http://packman.inode.at/suse/13.1/ Packman-FULL
  • General Notes:  (1) if the links above do not work then it is likely that, that particular mirror is down please visit http://packman.links2linux.org/mirrors for additional mirrors. (2) the "http://ftp." is intentional here and not an error it seems to make repositories fetch a lot faster than if the pure "ftp." is used.  This is because these repos receive less traffic than the "ftp://ftp" ones.
  • Once you have added the repositories by either of the 2 methods. Go into terminal (konsole) type "su" and enter the root password to go into the root shell and type the command "zypper dup" to initiate a vendor change to packman. Then type "exit" to leave the root shell.
2. Now that your repository is up and running. Install codecs. OpenSUSE normally does not provide all the codecs (only open source ones) for several reasons. THe packman repositories that you added above provided these extra packages.

If you are using the GUI then go to Yast-> Software Management and install the following packages
"ffmpeg", "vlc-qt" "vlc-codecs" (if you don't like VLC then you can install "mplayer" and its graphical frontend "smplayer" )

Installing graphics drivers:

For the graphics artists depending upon application open source drivers which are provided by OpenSUSE may either be sufficient or insufficient. If you are doing things like painting and video editing open source drivers may suffice. However if you are going to use 3D applications such as blender etc. you may have trouble with open source drivers as they do not provide full shder support and may cause artifacts in the render.


General instructions"
  1. First find out details about your graphics card.
    • In the terminal type "/sbin/lspci |grep  VGA" and look at the output this will typically list the grpahics card as detected by the kernel and its model number. Sample output is shown below
        01:00.0 VGA compatible controller: NVIDIA Corporation GT216M [GeForce GT 330M] (rev a2)

Installing Nvidia drivers:
To install Nvidia drivers on OpenSUSE please visit this link. https://en.opensuse.org/SDB:NVIDIA_drivers

Installing ATI/AMD drivers:

To install ATI/AMD graphics drivers on OpenSUSE please visit this link. https://en.opensuse.org/SDB:AMD_fglrx

Congratulations ! You have now configured a solid base to put your graphics applications of choice on. Since the applications and needs will vary depending upon what your needs are I will group applications by category below and you can choose to install apps from a few categories or all. Mix and match as you please each artists has their own style and work-flow.

3D Content

For 3D content the most popular 3D Modelling application is Blender. (www.blender.org) SUSE does not provide blender in its repositories as a general guideline in all distributions it is best to download the blender tarball and extract it in your home folder and run it from there. When distributions do have blender it is often extremely outdated.

Apart from this there are several other open source 3D applications for the artists such as Makehuman (www,makehuman.org) , Seamless3d (http://www.seamless3d.com/) and so on. GO ahead and experiment and pick what suites your style.

Painting

For painting there are 2 fantastic open source alternatives. I would recommend using Krita (www.Krita.org) this application is a very high quality application designed for painters and digital artist it is much more focused on painting though so it has several brush engines and supports various sensors available for your graphics tablet. (E.g the tilt etc.)

For a more general purpose application "Gimp" is provided. It is installed by default in SUSE 13.1 KDE

If you are feeling adventurous since the Krita development branch is pretty stable and regressions are fixed quickly. You can build krita straight from sources and use the latest development release. Below is a guide which tells you how to build Krita or the whole Calligra suite(krita, kexi, karbon etc.).

http://community.kde.org/Calligra/Building

Vector Graphics

For vector graphics the best application available is Inkscape (http://www.inkscape.org/en/) the latest stable version is already available in the SUSE repositories and ready to install.

Photography

On and off the graphics artist needs to manipulate photographs from digital camera's. E.g to erxtract texture etc.  One of the most powerful formats for capturing data is the RAW format (E.g. .nef, .cr2 etc.) this is because raw unprocessed sensor data is being stored which is almost equivalent to a digital negative offering ability to process a lot more. E.g adjust exposure without banding etc.

There are many open source alternatives available for processing RAW data before it is used in gimp.

Examples of good software for RAW processing are darktable (www.darktable.org), RawTherapee for more advanced RAW editing. Though you can usually get away with using Digikam for basic raw editing.