2006年10月11日星期三

彩色命令行

又一次读到关于Console Color的文章,决定把以前的积累合在一起贴出来。

今天看见这个: http://www.linuxjournal.com/article/8603

以前,还有些积累:

[ANSI颜色的表示]
可以参考color文件夹下的程序和两个网页文件。

[改变ls的颜色]
偶然发现了ls命令中目录的颜色和链接的颜色相同,都变成了浅蓝色。
在/etc/DIR_COLORS文件中对ls命令显示结果中不同类型的对象定义了颜色。
另外,在每个帐户$HOME目录下,还可以定义自己的 .dir_colors文件替代使用系统默认文件。

[RGB色彩]
在/usr/lib/X11/rgb.txt文件中有详细定义。运行xcolor命令显示颜色名称。

[字体]
通过xlsfonts命令查看全部字体。通过xfontsel选择字体。

#!/bin/bash
# Show all ANSI colors
#
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white

esc="33["
echo -n " _ _ _ _40 _ _ _ 41_ _ _ _42 _ _ _ 43"
echo "_ _ _ 44_ _ _ _45 _ _ _ 46_ _ _ _47 _"
for fore in 30 31 32 33 34 35 36 37; do
line1="$fore "
line2=" "
line3=" "
line4=" "
for back in 40 41 42 43 44 45 46 47; do
line1="${line1}${esc}${back};${fore}m Normal ${esc}0m"
line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m"
line3="${line3}${esc}${back};${fore};4m Unsc ${esc}0m"
line4="${line4}${esc}${back};${fore};5m Blnk ${esc}0m"
done
echo -e "$line1n$line2n$line3n$line4n"
done

找回丢失的GRUB

很久前写的,存过来。


问题描述

  • 双系统(Linux + Windows)使用GRUB引导的情况,当重新安装Windows后,由于MBR被重写,造成GRUB丢失。

  • 以下分别列出两种解决方法。

使用安装光盘或者linux启动盘:

  1. 用安装光盘或者linux启动盘启动,然后在启动的提示符输入:linux rescue

  2. 按照提示进入一个Shell状态,/mnt/sysimage/目录挂载了已存在的linux的/分区.

  3. 将根分区变为当前目录的根分区:chroot /mnt/sysimage

  4. 使用fdisk -l 显示当前分区情况,然后使用#grub-install /dev/hdx(x为安装硬盘,如hda)

  5. 使用exit推出chroot,再使用exit退出linux rescue模式,系统将重新启动!取出光盘,应该可以看到grub安装好了。在具体的环境中,编辑/boot/grub/grub.conf文件和menu.lst文件

使用grub启动盘:

  1. 用grub启动盘启动,按c键进入grub命令行模式。

    • grub> find /boot/vmlinuz       (查找系统中的内核文件的位置)
      (hd0,0)
      grub> find /vmlinuz (如果你采用了单独的 boot 分区, 那么需要用来查找。假定找到的结果是)
      (hd0,1)
      grub> find /sbin/init (再查找系统中有哪些根分区)
      (hd0,0)
      grub>cat (hd0,0) /root/grub/grub.conf (不一定要做,仅仅为了看启动参数)
      grub>root (hd0,1)
      grub>kernel (hd0,0) /boot/vmlinuz-2.4.18-11 ro root=/dev/hda2 (启动内核)
      grub>initrd (hd0,0) /boot/initrd-2.4.18-11.img
      grub>boot

      (!) 在grub命令行中可以使用Tab键

  2. 由此可以引导进入已装的linux系统,进入系统后,在shell行中输入命令grub,进入grub命令行模式

    • grub> boot
      grub>root (hdX,Y)
      grub>setup (hd0)

      这里的X,如果是一个盘,就是0,如果你所安装的linux的根分区在第二个硬盘上,那X就是1了;Y,就是装有linux系统所在的根分区。常用setup (hd0)GRUB写到硬盘的MBR上。

      如果成功会有一个successful......