Mittwoch, 24. Juni 2015

Bash function to make an permanet Alias

If you regularly type the same lengthy command into the console, you could make your life easier by using aliases. And even easier if you have a bash function to do that:

e.g you regularly type:

ls -la

you can turn it into an alias just by typing
ali #nameOfAlias #command
ali l ls -la

Which is more convenient than the regular alias. To get the ali function modify your .bashrc file in your home directory (if it doesn't exist on linux mint just create it and it will be used automatically)

function ali() {
 echo "alias $1='${@:2}'" >> ~/.bashrc 
 #in ubuntu use ~/.bash_aliases
 echo "made alias:";
 echo "alias $1='${@:2}'";
 source ~/.bashrc;  #reload bashrc
}

this appends the new alias to .bashrc and it will be available immediately and permanently.




Freitag, 12. Juni 2015

Tackling the Acer Aspire TimelineX overheating problem




The Acer Aspire TimelineX model has two switchable graphic cards. Those laptops have a hidden BIOS menu to configure which card to use, but there are other useful settings as well. How to unlock the menu is described here: http://ubuntuforums.org/showthread.php?t=1787312

Cleaning the laptop did not solve the overheating problem. But changing the BIOS parameters did. So here is my BIOS configuration (as usual, be careful with BIOS settings):











Copying folders so that only the files change that are different (Syncing)

I had 9 GB folder, the Android Sdk, and a copy of it on my USB stick. Then I made changes to the folder by installing new target platforms. Instead of copying the whole folder again on my USB stick a faster way was to use rsync.

rsync -r sourceFolder destinationFolder


This copies only the files that were new or changed.


Linux repeat console command

Repeat inxi -s every second to show the temperature which automatically gets updated

watch --interval 1 --color inxi -s





Linux: getting the system configuration (inxi)

A nice command to list the system information

inxi -F



Mittwoch, 10. Juni 2015

Backups: cloning whole disks (easier and faster than dd)

Important: do not clone disks that are actively used (e.g. your system disk) because the contents on the disk might change while you copy them and the clone could end up corrupted. Therefore:

  • Start a Linux Live System (maybe from an USB Stick)
  • Check the disk names and sizes* carefully (e.g. with the program disk)
  • Start cloning

For cloning many people advise to use "dd", but if you do not use the right block size it is slow. A faster and easier option is to use

cat /dev/sdX > /dev/sdY

wich copies all bits from the device sdX to the device sdY, just like dd. You probabliy need to use sudo:

sudo sh -c 'cat /dev/sdX > /dev/sdY'

Get the progress in bytes like this: grep the pid of cat and then see where the output file descriptor is
top | grep cat
cat /proc/yourCatPid/fdinfo/1


* If the target device is bigger than the source device then you can use gparted to resize the partitions on the new disk after the cloning is finished.


Linux: Error deleting partition

If you want to delete a partition and get this:



then do this (in my case it was /dev/sdc where I deleted partition 1 and 2, d is for "delete" and w is for "write changes"):



initramfs boot error

Suddenly my Linux Mint system didn't boot anymore, showing me this:




The file system was corrupted as I found out later (the hard drive may had a malfunction). This is a solution that worked for me:


  • Boot up with a Linux live system (for me Linux Mint)


Then I tried to access the hard drive, but I received an error that it was unable to mount, similar to this one:




Running dmesg in the console then told me that there was an I/O error because of bad blocks, and that restoring them didn't work. Mounting in the console didn't work either (even with -o force)





Running fsck on the disk told me again that there were bad blocks and suggested to use e2fsck, like in this picture:





I Followed the advice which was in my case (be careful with this):
sudo e2fsck -b 32768 /dev/sda1

There were a lot of corrections necessary that had to be confirmed by pressing enter, some long matrix-like number rows and at the end I got told that the file system was corrected successfully.

Then I was able to access the contents of the disk, which made clicking noises, but I was able to recover my files and rebooting worked as well.

Cheers :)

Sonntag, 7. Juni 2015

Script to open console with tabs that execute commands (and stay open)


Replace "ifconfig" and "ping ..." with your own commands. The "exec bash" part is necessary so that the tab doesn't close when the command is finished.

#!/bin/sh
gnome-terminal \
--tab -e "bash -c \"ifconfig; exec bash\"" \
--tab -e "bash -c \"ping www.google.com; exec bash\""


Wireshark on Linux Mint and Ubuntu

Wireshark on Linux Mint didn't work out of the box on my system. Running it as root worked but since there are known exploits for wireshark (at least for older versions) this isn't a good idea.

Solution: Reconfiugure wireshark to create the wireshark group and then add your user to it

sudo dpkg-reconfigure wireshark-common
sudo usermod -a -G wireshark <your username>
then log out & log in

You will see this nice explanation:


Quickly generate self-signed SSL certificate and key

How to get an SSL certificate which you can use for e.g. local testing

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365

Generates key.pem and cert.pem.

For localhost testing enter for the server name (FQDN): localhost

Since this is a self-signed certificate the browser will show a warning. If you don't want warnings you can get a free certificate from e.g http://www.startssl.com/


Install package on offline machine (Linux Mint and Ubuntu)

Install a package with all its dependencies on an offline machine (Linux Mint or Ubuntu):

  • Open Synaptic Package Manager on offline machine and mark package for installation
  • File -> Generate package download script
  • Use the download script on an online-machine to download package and all dependencies
  • Transfer the downloaded files to the offline-machine
  • File -> Add downloaded packages