Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, May 12, 2010

Mount qemu harddisk image in host system

Recently I got to copy a lot of files from a qemu guest, and I think using network is too slow, so I googled for solutions to mount qemu image in host system (when guest is shutdown). And it turns out that only raw images are supported, therefore the first step is to convert the image format:

qemu-img convert –f qcow2 origin.qcow –O raw temp.raw

Then I fount in archlinux wiki that I should mount with –loop,offset=32256 option, but I fail to figure out where 32256 comes. Luckily I remenbered how I delt with dd images. Just get the offset with fdisk:

fdisk –u –l temp.raw


Then I have the sector size (512 in my case) and the offset (2048, start sector of my partation), so the offset should be 512*2048=1048576. (btw, you can calculate with bc: echo ‘512*2048’ | bc)



mount –t ext4 –o loop,offset=1048576 temp.raw /mnt/some-path


That’s it :)

Thursday, April 8, 2010

Link for X, HAL & udev

It seems we could thank HAL for all these years of great work and say goodbye in a short period of time (source below).

To be honest I still feel confused now and then about what (fill this blank) is doing for me. My understanding is:

linux kernel ─>─ udev ─>─ HAL ─>─ X server
                   │                │
└────────>───────┘
libudev

So I just try to find more about X/Hal/udev thing, and keep some links here. (Remember the best source of information is always the official web sites and the mailing list).

(Not) blaming HAL by Keith Packard (explains what X.org X server needs from HAL before 1.8)

Manage Linux Hardware with udev by Carla Schroder (tells a little history of udev and HAL, and how /dev, /sys works.)

* source: Free X.org Server 1.8.0 with udev to replace HAL

Thursday, March 18, 2010

Linux Hibernation in short

In order to hibernate in Linux, you need a user space script and an backend. Two User space scirpts widely used are:

  • pm-utils : used in OpenSuse, Ubuntu, etc
  • hibernation-scirpt : used by gentoo, etc

The linux kernel comes with hibernate backend named swsusp but you can also try other tool, so your options are:

  • uswsusp : need to be installed
  • tuxonice : you got to patch the kernel
  • swsusp : comes without extra effords

My choise is pm-utils + uswsusp for I’m too lazy to patch and compile a kernel, and I’ve been using pm-utils for a long time.

And one more thing to mention, even hibernation-script comes with tuxonice, it can use uswsusp as backend.

Thursday, February 25, 2010

libpng12.so.0 missing problem in Archlinux

Archlinux has been offering libpng14 recently, however if some self-compiled packages are used in the system, it may turn out an disaster :(

I had cario, freetype2 & libxft compiled from abs so as to enable sort of cleartype effect in type rendering, however, after I updated libpng recently from version 12 to 14, I cannot boot into gdm correctly. I cannot even run vim in a console for it complains that libpng12.so.0 cannot be found.

So I have to:

  1. boot with run level 3 (adding 3 at the end of grub's kernel line);
  2. login as root and remove self-compiled packages that require libpng12, cario, freetype2 & libxft in my case (I found -d option useful since I will soon reinstall these packages);
  3. recompile new versions with libpng14;
  4. install those packages.

Wednesday, December 2, 2009

Bash environment memo: profile, bash_profile & bashrc

Abstract: I'm trying to explain the process of bash setup in this article.

Keywords:bash, shell, environment

It is usually hard to answer the question where this variable is set, because there is SO many different files involved. So let's start with some concepts:

interactive login shell
The shell started after a successful login, using /bin/login, by reading the /etc/passwd file.
interactive non-login shell
It is normally started at the command-line using a shell program (eg.$/bin/bash) or by the /bin/su command. It is also started with a terminal program within a graphical environment.
non-interactive shell
It's usually used to execute a shell script

An interactive login shell generally initializes with the following configuration files:

/etc/profile -> [~/.bash_profile] -> [~/.bash_login] -> [~/.profile]

In some systems, the /etc/profile script will look for additional settings in /etc/profile.d/*.sh, and the ~/.bash_profile usually sources ~/.bashrc.

When an interactive non-login shell starts, it first copies the environment of its parent shell and then reads its settings in the following order:

/etc/bash.bashrc -> [~/.bashrc]

Remember that only exported variables of its parent shell is copied, functions and aliases of its parent are NOT inherited.

A non-interactive shell simply copies environment from its parent, and does not read any configuration files.

Thursday, November 5, 2009

Mount internal filesystem without passwd with udisk (formerly devicekit-disk)

Abstract: Use policykit to avoid root password for mount an internal filesystem.

Last week, I updated my Arch Linux laptop, and got the new deviekit-disk. Then I found that the authorizations set with gnome interface, which actually sets theorg.freedesktop.hal.storage..., stops work. I have to give the root passwd when I try to mount an internal filesystem, which is really bothering:(

Luckly it is not hard to solve this problem with Policykit, though there dosen't seem to be a sweet GUI to help. All you have to do is simply create a text file named anything with suffix .pkla in /etc/polkit-1/localauthority/50-local.d/ and fill it with the content below:

[filesystems mount internal privs]
Identity=unix-group:disk
Action=org.freedesktop.devicekit.disks.filesystem-mount-system-internal
ResultAny=no
ResultInactive=no
ResultActive=yes

In case you have udisks2 instead of udisks, the action should written like this:

Action=org.freedesktop.udisks2.filesystem-mount-system;org.freedesktop.udisks2.filesystem-mount

Here I allow all users in group disk to mount internal filesystem without root password. disk is the default group of storage devices, you should add yourself to this group. Otherwise you can specify your login name:

Identity=unix-user:yourname

To see all possible actions, check /usr/share/polkit-1/actions directory.
You can always man pklocalauthority for more info:)


Update (May 22nd 2012)

Udisks2 uses different action name.


Update (Oct 25th, 2011)

Latest udev will set storage devices of group disk. So I specify group disk instead of storage now.

PS: I moved to a new blog.


Update (April 3rd 2010)

People from freedesktop.org are making a great progress - by renaming devicekit-disk as udisk (Sounds talking about flash disk, isn't it?)... So you got to change Action=org.freedesktop.devicekit.disks.filesystem-mount-system-internal to Action=org.freedesktop.udisks.filesystem-mount-system-internal.

Dear sirs/madams from freedesktop.org, will you please stop renaming things? It's not fun, at all :(


Update (April 16th, 2010)

It seems /etc/polkit-1/localauthority/50-local.d/ is a better place to apply your own settings.


Update (Nov 2nd, 2010)

The configuration file has to be named with suffix .pkla to be recognized, for more details you can man pklocalauthority. And lots of thanks goes to Awebb who kindly points this out :)

Thursday, July 30, 2009

Backup with Acronis and without CD

Abstract: Boot Acronis True Image from grub.

Acronis True Image features online backup, however sometimes you may still want to do a off-line one, then normally you have to either install Acronis to hard disk or use a rescue media CD. Since I have both Arch Linux and Windows installed, I do not want to install Acronis to hard disk because I want to have grub in MBR. But I cannot use rescue cd either, because my cd has already been dead for years.

I've tried to make a usb disk rescue media, but it simply does not boot :(

So here's what I did:

  • Generate a rescue ISO with Acronis;
  • Expand ISO file and copy all in Recovery Manager to a directory on hard disk;
  • Write in Grub's menu.lst:
    title Acronis
    root (hdX,Y)
    kernel /acronis/kernel.dat quiet vga=0x317
    initrd /acronis/ramdisk.dat

  • Reboot and select Acronis from grub

Now you see, Acronis Rescue CD is actually Linux :)

Tuesday, July 21, 2009

Firefox 3.5.1 (Shiretoko) fails to launch in Arch Linux

Abstract: Firefox 3.5.1 needs libjpeg.

After updating my Firefox (Shiretoki) to version 3.5.1 in Arch Linux, I cannot launch it. When I tried to start it from command line, it says:

$ firefox
Coundn't load XPCOM
$

Then I tried to run xulrunner directly, I got a Error message saying that libjpeg cannot be found. So I installed libjpeg-7-1, and Firefox is back again. Hopefully the Arch people can add libjpeg to Firefox's dependency.

Monday, July 20, 2009

Pm-hibernate with MX440

Abstract: Some tweaks to avoid black screen after resume from hibernation with old nVidia MX440 graphic card and Intel motherboard.

First edit the setting for pm-utils in /etc/pm/config.d/config(you can name this file whatever you like).

HIBERNATE_MODE="shutdown"
S2RAM_OPTS="-f"
DISPLAY_QUIRK_VBE_POST=false

Then I edit /etc/modprobe.d/modprobe.conf(the modprobe.conf is here for Arch Linux, but may lies in different place in other distros):

blacklist intel_agp

Then reboot the computer, and try hibernate again, everything goes well :)

Tuesday, July 7, 2009

"The greeter application appears to be crashing"

Abstract: Resolved "The greeter application appears to be crashing" problem after updating Linux system.

I don't know whether this could be called a solution... actually just a tip if you happened to come across a same problem. I updated my Arch Linux, and after reboot this dialog box jumps up and gdm could not start normally. I checked the system and found the problem was caused by a full filesystem. I cleaned up some old files and then everything goes right.

So I guess I should give more disk space to / in the future.

Tuesday, June 9, 2009

Get Chrome Work in Arch Linux

Abstract: several steps to get chrome working on Arch linux


  • Google only provides deb pkg officially, damn...

  • download the deb pkg from:
    http://www.google.com/chrome/intl/en/eula_dev.html?dl=unstable_i386_deb

  • unpack, copy everything in opt to /opt

  • mkdir lib32 in /opt/google/chrome, and make symbol links as:
    http://code.google.com/p/chromium/issues/detail?id=13425

  • enjoy chrome...though I can't input Chinese in its linux version...wtf...

Update Jun 13, 2010: Now chromium is in the official repo, and if you'd like to use Google Chrome(beta), it's in the AUR.

Tuesday, May 19, 2009

The problem of pm-hibernate solved

Abstract: Solve the problem of pm-hibernate restarts computer.

When I try to hibernate my laptop running Arch Linux with pm-hibernate which is also used by GNOME behind the scene, it restarts immediately after hibernate to disk. I checked Arch wiki and find a link to opensuse wiki Pm-Utils. After add a s2ram force option as instructed, the problem is solved. I added the following lins to /etc/pm/config.d/config

HIBERNATE_MODE="shutdown"
S2RAM_OPTS="-f -p -m"

The "-p" parameter was the key to a successful hibernate for me.

Sunday, May 10, 2009

Converting between WAV and MP3 with simple open source tools

Abstract

A short memo on converting between mp3 and wav files

Today I find some conf call audio records are so big for my little hard disk so I decided to convert them from WAV to MP3 format. I make use of a simple (more precisely, simple to use) tools to do the job -- lame.

Since all my wav files to convert sit in the same folder, I make use of a little bash:

$ for f in `ls -1 *.wav | sed s/\.wav$//` ; do lame $f.wav $f.mp3 ; rm -v $f.wav ; done

Easy, isn't it?

Converting mp3 files back is just as easy, though there should be some quarlity loss which I don't believe can be noticed for a conf call record;) The mpg123 is as simple as its name 123, you just have to give it the name of the file to convert

$ for f in `ls -1 *.mp3 | sed s/\.mp3$//` ; do mpg123 -w $f.wav $f.mp3 ; done

Tux Drawing

I'm not sure whether is a good idea to put it here, anyway, I think Tux is technique-related...

Done in OpenCavas(Maybe I should use Linux and GIMP to do this, but I really don't like GIMP)... This took me several minutes after a pencil sketch on real paper.

Saturday, May 9, 2009

How to use git-http-fetch with a proxy

Abstract

This post offers a tip on how to use git with a http proxy

I noticed a mail in the Chinese Google Summer of Code mail list today, which askes how to use git-http-fetch when a http proxy have to be used to access the git host. I don't believe there is any way to do so with GIT, but I don't think this should be a tough problem either. Remember git is only a common program, though it does many magic>. So it should work with http proxy just as other programs do.

Remember how we access the internet with a proxy in bash? All we have to do is to set the http_proxy environment variable.In bash we simply do:

export http_proxy=”http://<proxy-server-ip>:<port>”

Or you may:

http_proxy=”http://<proxy-server-ip>:<port>” git http-fetch <your-params>

And be aware that the name of the environment variable is in lower case.

Thursday, April 30, 2009

My Comments on Books about Shell Programming

Abastract
In this article I shall introduce several books about shell programming and hopefully it will help you to determine the right one for you.

I have to learn shell to carry out some of my experiments recently, and to be honest, I don’t feel like shell very much since there are so many modern script languages out there… Anyway, as shell is so widely used, it’s not too bad to spend some time on it.

  • A Practical Guide to Linux Commands, Editors, and Shell Programming is a nice book to start for newbies :)
  • Unix Shell Programming is the best book on shell programming I’ve found, which explains how shell works clearly
  • Classic Shell Scripting is not structured as well as the the previous one, but it has a chapter on security and explains some basic ideas in more details. If you get confused while reading the previous book, check this one.
  • Unix Shell by Example explains all popular shells, including sh, bash , csh and ksh, if you are going to script for different shells you may very likely find this book useful.

Monday, April 27, 2009

Finally get Xorg-1.6 work with nVidia MX440

Abstract

I describe a solution to the problem that Xorg 1.6 fails to work with Mx440 and kernel 2.6.29 in Arch Linux

I'm currently using an old PC in the lab, which features a MX440 video card, last week I updated my Arch Linux and got Xorg 1.6, and that was the start of a nightmare...

Xorg refuse to work with the legacy driver (nvidia-96xx), and won't start if the xorg.conf file exists, which is used to specify the screen resolution(though the pc is quite old, I got a big widescreen monitor…). I browsed the Arch user forum and tried all the solutions given, and finally get it work with add “nopat” option to the kernel in the grub munu.lst like this:

title Arch Linux
root (hd0,4)
kernel /vmlinuz26 root=/dev/disk/by-uuid/99b8f60e-c1eb-4482-a22f-6a49a5572401 ro vga=0x317 nopat
initrd /kernel26.img

Hopefully this can be useful ;)

Saturday, April 25, 2009

Linux is neither heaven nor hell (3)

前两天开始写这个系列,本来是打算先写天堂的,不过我刚刚写完天堂的信仰之后就发生了无法配置X的惨剧,所以我决定先写“地狱“……

在Linux下,一个十分重大的问题就是升级。因为我们总是希望Linux更加的好用,所以大家弄出了各种各样的新鲜东西,引诱你升级。而现实的另一面是可能过去遇到的一个一直没有解决的问题一直在折磨你,而据说新版本解决了这个问题,所以需要升级。

在Linux升级的时候,需要首先做好搞砸整个系统再也看不到可爱的GUI界面的心理准备,备份好自己的文件,向图灵、冯诺依曼等计算机史上的贤者祷告,祈求得到他们的祝福。然后毕恭毕敬小心翼翼的输入升级的命令,接着就是听天由命了……可惜这些神明并不好伺候,有的时候他们会莫名其妙的降罪于我。比如我今天在笔记本电脑和台式机上同时升级我的arch Linux,笔记本上的表现很好(尽管Root Terminal不能用了,我的触摸板却神奇的好了,经过我的配置还支持了连为windos都不曾支持过的双指触控-_-b),而台式机则直接出现了最恶心的xorg错误,目前连正确的分辨率都无法设置。

Linux像地狱,因为我总是生活在恐惧之中,常常因为一个小小的贪心,陷入系统无数细节的深深泥沼……如果幸运的话还可以抓住manual、wiki、google和bbs这些救命稻草,如果不幸的话常常会花去数个小时也没有挣脱出来。在Linux这个原始蛮荒的丛林里,只有熟悉环境经验丰富的家伙才能像山猫一样游刃有余的穿行,很可惜我至今还是一个时常掉进坑里头破血流还半天爬不出来的小白鼠……

在这片丛林中,你脚下的土地都不是坚实而值得信任的;很多问题和硬件有关的。我不知道这种现状应该归罪于什么人,毕竟对于硬件厂商来说,支持纷繁复杂变幻迅速的Linux比支持用一只手的指头都能数过来的微软Windows要困难多了。这个社区缺乏一个强大的力量,了解并统一大家的意见提出一个清晰的标准;而没有这样一个清晰的标准,社区和外界的交流就会有很多困难。自由和效率不仅仅是一个政治问题,在很多地方都能看到这种博弈的影子。

有人说没必要这么复杂,装一个Ubuntu就好了,可就像在树林边的草地上散步,终归会因为窥见的诱惑或是其他的原因走进这篇丛林……复杂的系统软件如参天巨树遮天蔽日让人难辨方向,依赖关系的藤蔓纵横交错将人包围,脚下的硬件支持如同泥沼不知道什么时候就会陷进去,这就是Linux的地狱印象。

不过着绝望的印象中还有一丝的希冀:当最终穿过这片林子时,当初因好奇而迷失其中的小白鼠应该已经变成主宰丛林的大象了吧。

[ to be continued... ]

Friday, April 24, 2009

Linux is neither heaven nor hell (2)

昨天说了我在Linux下混的短短历史,其实没什么值得参考的,今天说说我对于类Unix系统和GNU/Linux的感想。

说到学习Linux,我觉得这个说法本身就有一点问题,尤其是对于绝大多数从Windows过去的童鞋(按理说从mac过去的同学应该问题小很多)不是学习一个操作系统如何使用,更主要的是在Linux背后的一些逻辑。没有这些逻辑,就会觉得始终不得要领,而这些逻辑不是Linus自创出来的,而是来源于光辉伟大千秋万岁的Unix系统。

Unix的逻辑是简单的逻辑。(尽管Linux有时候会让人觉得很复杂,这只是因为nix系的操作系统对于消费用户来说暴露了太多的细节,没有做到所谓的傻瓜化隔离)

Unix系统里很多东西都是保存在纯文本文件里的,软件的源代码,软件的设置,甚至软件的本身也很少包括不是从源代码来的东西。比如windows程序多数都会内置一个图标,而Unix程序一般会使用一个外部的单独的图片文件。这种看似原始的方式其实还是蛮有好处的,你可以方便的使用你喜欢的工具编辑你的软件的设置;而且即使你搞砸了,也只是破坏了一个软件的设置,试想如果你把Windows的注册表搞砸了是什么后果……(我记得某文科女生说过她的一个师兄告诉她改注册表就会死机,呵呵……)

Linux继承了这种简单,和所有类Unix系统一样,计算机的文件组织方式是一棵树,这棵树只有一个根,不论你有多少个硬盘,多少个设备,都是这个根上的分支而已。(而Windows呢?我的文件夹还有C盘都是什么关系?正是因为搞不清楚我的文件夹实际上是C盘上若干文件夹内容的映射,多少小白再重装电脑之后痛失桌面上刚刚写好的作业啊……)更好的是所有的类Unix系统的磁盘都是可以挂载在任一文件夹的。如果你希望在Windows上把某软件的缓存设置到内存上,那么你只能祈祷该软件可以设置缓存地址,否则没戏。而在Unix上你可以把内存变成ramdisk挂载在任何你觉得合适的地方。逻辑简单,用法灵活。

很多人提到Linux相到的就是free,可惜理解的意思往往是“不要钱”。卓越上一份Windows也就是几百块,我还真不相信那些叫嚣着微软黑我屏我就跟盖茨拼命的家伙们拿不出来这个钱;把盗版微软觉得理所应当的人,几乎一定认为Linux社区应该把什么都给他免费准备好,生怕他不用……GNU/Linux的free更多的含义应该是自由,作为万灵之长了解并操作一个机器的自由。

有些人会说了,我们不是学计算机的,我就是一个OL,我搞不定C语言,弄不明白算法啦,我只想知道如何写报表怎么办呢?——这些都对,可是这不是褫夺自由和权力的理由。我们的自由和权力与生俱来,我们使用软件是委托其他人帮助我们实现我们的权利,而不是放弃我们的自由和权力。假如因为你扭了脚,要求我代你去超市买只菠萝,我说从此你的钱包就归我,你一定不会答应。所以拥有操作你的电脑的权利的人永远是你而不是某软。所以用某软的东西不是大问题,觉得电脑只有靠某软才能转就不对了。

某软的系统的逻辑也是简单——用户的头脑应该是简单的。于是某软私自做了很多的决定,既不告诉你为什么这么决定,也不说好处是什么,甚至不告诉你它做了决定。客观地说我不认为某软那些家伙们没能力做一个更好的系统出来,不过他们都忙着防范假象中的傻瓜用户把事情搞砸了。(这就和“为了防止你们把不靠谱的人选为xx代表,我熬夜把你们的选票上的圈都画好了,你们到时候拿过来直接扔到投票箱里就好了”是一个逻辑)微软的消费市场操作系统通过图形界面能干很多事情,但是没了图形界面基本干不了啥事情。

我认为Linux的桌面应用永远也不会成为主流,甚至可能在这个脑残和娱乐化的时代用户越来越少;但愿若干年后,还有一种叫做自由的精神香火不灭吧。

【 to be continued… 】