2012年12月27日星期四

Speed up Fedora boot time

I bought a MacBook Air for my wife and she was surprised that it boots in seconds! So I think I should do something to my Favorite Fedora17 on Thinkpad as well. (Notice that I've no SSD attached)

Diagnostic

Generally the boot time of my Fedora17 is around 100 seconds and I even don't know what's wrong with it. So the first time is diagnostic.

The first tool is systemd-analyze that I found from the article "Fedora 17 Boot optimization from 15 to 3 seconds". You can get:

time spends in each phases (kernel, ramdisk and userspace):

$ sudo systemd-analyze

the time that each service takes via:

$ sudo systemd-analyze blame

A pretty sequence diagram of system boot time:

$ sudo systemd-analyze plot > ~/Desktop/boottime.svg

Follow up actions


  • disable ramdisk. where it will save u 5 seconds. see this article for details.
  • remove unused packages. You can use the following commands to list those orphan/leaves packages:
$ sudo package-cleanup --orphans
$ sudo package-cleanup --leaves
  • remove unused services. here's mine:
$ sudo systemctl disable bluetooth.service
$ sudo systemctl disable avahi-daemon.service
$ sudo systemctl disable cups.service
$ sudo systemctl disable nfs-lock.service
$ sudo systemctl disable abrtd.service
$ sudo systemctl disable abrt-oops.service
$ sudo systemctl disable udev-settle.service


After the above actions, the boot time reduced to 20 seconds:


$ sudo systemd-analyze
Startup finished in 3192ms (kernel) + 17428ms (userspace) = 20621ms


Runtime optimization


  • mount /tmp to tmpfs. Please edit your /etc/fstab file by appending this line (you can adjust the size on your own):

tmpfs  /tmp                    tmpfs   size=512m       0 0

Please comment if you had more!

2012年11月28日星期三

Construct Linux virtual Image in minutes by BoxGrinder and Guestfish

BoxGrinder and Guestfish are my favorite command line tools when I need to construct virtual images (Linux only,of course).

Note: all my bellow CLI samples verified on Fedora Linux only.

Installation

It's deadly simple to install the above 2 tools:

$ sudo yum install rubygem-boxgrinder-build
$ sudo yum install libguestfs-tools

That's all.

Scenario

Creating a virtual image with RHEL6.3 OS, and tweak several configuration files within it before deploying it into a virtual machine on KVM or other hypervisors.

Procedure

1. prepare yum repository URL. Either remote repository via HTTP or local mounted iso file. Assume it is file:///mnt/rhel63

2. prepare the appliance description file in yaml format. Here's a sample:

$ cat /data/jeos-rhel63.appl 
name: rhel63
summary: RHEL6.3
os:
  name: rhel
  version: 6
  password: ********
repos:
  - name: "base"
    baseurl: "file:///mnt/rhel63"
    ephemeral: true
hardware:
  cpus: 1
  memory: 512
  partitions:
    "/":
      size: 30
      type: ext4

Generally you will find I intend to install nothing except the OS itself, which is called "Just Enough OS". I like this way because the actual image file size can be controlled less than 800MB. Alternatively, if you want to add additional packages during the virtual image creation, use stanza "packages". Like:

packages:
  - mysql-server

You can find more samples and detailed reference here.

3. create the virtual image file by running the following command:
$ sudo boxgrinder-build jeos-rhel63.appl -p vmware -d local


There's many options that you can customize the image construction like disk format, container format, just simply perform this command to find the list of options:
$ sudo boxgrinder-build --help

Notice that it doesn't perform the actual installation procedure over any virtualizationt technology, so the construction goes very fast. Usually it takes 3~5 minutes to get the final virtual image file. The actual time cost depends on your disk write rate and/or the network bandwidth if using remote yum repository over HTTP/FTP.

4. After it completes, you will find the image file under directory ./build/appliances/x86_64/rhel/6/rhel63/1.0/

5. The final step is customize the file system inside this virtual image. Now you need to start using guestfish:
$ sudo guestfish --rw -i rhel63-sda.raw
> 

Then you can perform vi, rm, man and other commands to change the files. For example, I usually dumping the public key under the /root/.ssh/authorized_keys so that no need to use account password.

At the end, you can type quit to exit the guestfish shell environment and transfer the image file to OpenStack or your local KVM hypervisor directly. Notice that you must keep the sparse file or the transfer rate is pretty slow.

Further explore

guestfish-browser is a fancy GUI tool to browse the virtual image file system. you can install it via:
$ sudo yum install guestfish-browser

2012年10月15日星期一

Get redesigned message tray in 2 steps on Gnome 3.4

After reviewing the latest change from Gnome 3.6 release, I found the redesigned message tray is really a big improvement so that people like me can easily pick up contacts from the big icon!
Redesigned Message Tray from Gnome 3.6
If you're Gnome 3.4 users, you can get it by hacking 2 files:
Step 1: change the line #1203~#1208 of gnome-shell.css

$ sudo vi /usr/share/gnome-shell/theme/gnome-shell.css

#message-tray {
    background-gradient-direction: vertical;
    background-gradient-start: rgba(0,0,0,0.01);
    background-gradient-end: rgba(0,0,0,0.82);
    height: 50px;
}

Step 2: change the icon size on line #959 of messageTry.js

$ sudo /usr/share/gnome-shell/js/ui/messageTray.js
ICON_SIZE: 48,

Then reload the theme via input "r" in the prompt dialog by Alt+F2.

2012年3月4日星期日

Fw: How to connect to KVM guest (spice support) via Firefox

I found a good example from mailist of freedesktop.org:
http://lists.freedesktop.org/archives/spice-devel/2011-June/003959.html

It's pretty straight forward:
  1. install spice-xpi plugin to firefox: sudo yum install spice-xpi
  2. make a sample html file like this:

<!DOCTYPE html>
<html>
<head>
<title>SPICE Plugin Test</title>
<script type="text/javascript">
    function connectvm()
    {
        var ip = String("localhost");
        var port = String("5900");
        var passwd = String("pass at 321");
        var pluginobj = document.embeds[0];

        pluginobj.hostIP = ip;
        pluginobj.port = port;
        //pluginobj.Password = passwd;
        //pluginobj.fullScreen = true;
        pluginobj.UsbListenPort = 0;
        pluginobj.connect();
    }
</script>
</head>
<body>
        <p>
        <embed type="application/x-spice"></embed>
        <button onclick='connectvm()'>connect to VM</button>
        </p>
        <p>
            If the plugin is working correctly, a click on the button
should open spice client.
        </p>
</body>
</html>

then it will fork a spicec process connected to the VM where spice server listens to localhost:5900
--
朱可
http://shawnzhu.blogspot.com

2012年1月31日星期二

在Fedora 上启用 Gluster File System 分布式文件系统

最近在学习分布式文件系统,于是尝试了Gluster File System, 安装也比较简单:
# server
sudo yum install glusterfs-server
# client
sudo yum install glusterfs

之后使用systemctl 启动服务器端即可:
sudo service glusterd restart

注意:第一次启动 glusterd 的时候需要注意修改glusterd 在 sysconfig 下的配置文件:
vi /etc/sysconfig/glusterd

GLUSTERD_LOGFILE="/var/log/glusterfs/glusterd.log"
GLUSTERD_LOGLEVEL="INFO"

注意: Log level 在 glusterfs v3.2.x 使用 INFO, 没有沿用 glusterfs v.3.1.x 里的默认值 NORMAL

你还需要增加 iptables 规则来允许客户端连接 gluster 服务器:

sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 24007:24011 -j ACCEPT

比如你有机器 A (ip: 192.168.0.100) 和 B(ip: 192.168.0.101) 来做 glusterfs 服务器,在客户端上执行如下命令:
sudo gluster peer probe 192.168.0.100
sudo gluster peer probe 192.168.0.101

你可以使用 peer status 来查看状态:
sudo gluster peer status

你可以创建一个叫做 test-vol 的存储卷,在A 和 B 上各复制一份:
sudo gluster volume create test-vol replicate 2 192.168.0.100:/data 192.168.0.101:/data

启用并挂载即可使用 test-vol:
sudo gluster volume start test-vol
sudo mount.glusterfs 192.168.0.100:/test-vol /mnt/glusterfs




2012年1月7日星期六

RubyGems 的隐藏配置选项

RubyGems 是简单而强大的 ruby 软件包管理工具。但是其文档有些过于简洁而缺少了定制的部分。当你浏览 gem command reference 或者 gem 使用手册时,有些内容没有在正式文档里出现。

场景1:在内部网络里需要自己的 gem server, 避免每次从 http://rubygems.org 下载安装
这种场景在企业内部的应用场景非常常见,但是文档里没有提及如何配置实现。这里就有一个隐藏配置 sources.
  1. 在机器 example.com 上运行 ruby server 启动 rubygems 服务器,你可以从 http://example.com:8808/ 看到你安装在这台机器上的所有 gem
  2. 在需要安装 gem 的机器上创建 ~/.gemrc 配置文件,添加如下内容:

这时运行 gem sources 命令时就可以看到原来的 http://rubygems.org 被替换成为了你自己的 gem server

场景2:gem 安装错误时需要错误信息。
在 ~/.gemrc 里添加如下配置:
backtrace: true

你还可以指定输出信息的详尽程度:
verbose: true  # 还可以指定为 :load

参考:

--
朱可
http://www.netvibes.com/shawnzhu

2012年1月3日星期二

从 Grub2 切换到 NTLDR 实现引导 windows 和 Fedora 双系统

thinkpad 上运行 Ubuntu Fedora 的日子让人舒适而轻松:没有病毒,更新简单迅速,Gnome3.2, 集成的协作软件高效而简洁。但一旦需要在同一块硬盘上安装 windows, 生活立即发生改变。

众所周知 windows 一定要改写 MBR 采用 NTLDR 来引导系统。如果你已经采用 grub2 来引导 Linux 而又不想每次安装完 windows 重新恢复 MBR, 那么你就得依赖 NTLDR 了,详见参考文章 Using NTLDR to dual boot Windows and Ubuntu

由于我已经在硬盘上安装了 Ubuntu Fedora, 所以此次安装 windows 的主要目标是用 NTLDR 来同时引导 windows 和 已经存在的 Linux.

我的 Fedora 安装在 sda2 上,此次将 windows 7 windows 2008 分别安装在了 sda3sda1 上。

注意:安装之前一定要备份 /boot/grub2/grub.cfg

安装完基本的操作系统后,可以从 windows boot manager 看到两个 windows 操作系统,但是 Fedora 没有了。这时你需要修改 windows boot manager 以加入对 linux 操作系统的引导。

由于 windows 7 开始已经没有了 boot.ini, 所以之前各种通过修改 boot.ini 文件实现的多系统引导方法都不能用。我的方法是安装 EasyBCD, 可以通过这个软件来安装 Nero Grub, 你可以理解为以前在 windows 上安装的grub.

  1. 下载 EasyBCD 2.x

  2. 安装到 windows 7

  3. "Add New Entry" -"Nero Grub" -" Install", 选择 "configure"时可以修改 grub 的配置文件 menu.lst

注意:这里需要用到你之前备份的 grub.cfg 来从 nero grub 引导 Fedora 的内核和 ramdisk.

我的修改如下:

#Fedora 16

title Fedora 16 (Verne)

root (hd0,1) # 第一块硬盘的第二个分区,即 sda2, 但是这里grub 只能识别 hd0

kernel /boot/vmlinuz-3.1.6-1.fc16.x86_64 root=/dev/sda2 ro quiet splash

initrd /boot/initramfs-3.1.6-1.fc16.x86_64.img

保存之后重新启动,你就会在 windows boot manager 里发现新创建的启动项 "Nero Bootloader",点击就进入了 Nero grub 的启动项。

这里你可以增加其他的Linux 系统启动项。