kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

grubby edit centos grub args

In Debian/Ubuntu, grub.cfg is fully generated by scripts and any manual changes made to it will be clobbered. In RHEL/CentOS however, grub.cfg is modified by scripts but manual changes are persisted, and is actually the canonical location for certain settings.

The tool which manages grub.cfg is grubby, which is called by /sbin/new-kernel-pkg when kernels are installed or removed. The –copy-default parameter is passed to grubby when a new kernel is installed, which causes it to copy the kernel parameters from the current default kernel. Setting the default kernel parameters for future-installed kernels is therefore done by editing the entry for the default kernel in grub.cfg.

If you weren’t automating this you could simply edit grub.cfg manually and change all the current kernel entries. However, you can use grubby to modify grub.cfg in order to avoid parsing it or writing regular expressions. For example, this will remove the rhgb and quiet parameters from the specified kernel version.

1
$ grubby --update-kernel=/boot/vmlinuz-2.6.32-220.13.1.el6.x86_64 --remove-args="rhgb quiet"

There doesn’t seem to be an option to list the currently configured kernels however, so you’ll have to discover these another way. One option is to just look for vmlinuz files in /boot/:

1
2
3
4
#!/bin/sh
for KERNEL in /boot/vmlinuz-*; do
	grubby --update-kernel="$KERNEL" --remove-args="rhgb quiet"
done

grub

在命令行状态,可以根据需要加载或移除相应模块,也可用来启动在菜单没有显现的的系统。 比如,在第一硬盘的第一分区上装有windows xp系统,但在菜单上没显示出来,我们可以命令行状态下输入命令启动:

1
2
3
grub>set root=(hd0,1)
grub>chainloader +1
grub>boot

又比如启动第二硬盘第一逻辑分区上的ubuntu系统:

1
2
3
4
grub>set root=(hd1,5)
grub>linux /boot/vmlinuz-xxx-xxx root=/dev/sdb5
grub>initrd /boot/initrd.img-xxx-xxx
grub>boot

其中内核vmlinuz和initrd.img的版本号可用按Tab键自动查看。

\r\n,\n,\r简介

‘\r'是回车,前者使光标到行首,(carriage return)
’\n'是换行,后者使光标下移一格,(line feed)

\r 是回车,return
\n 是换行,newline

^M 是ascii中的'\r', 回车符,是16进制的0x0D,八进制的015,十进制的13
^M在vi编辑器中可以使用Ctrl+ v + m三个键打出来

对于换行这个动作,unix下一般只有一个0x0A表示换行(“\n”),windows下一般都是0x0D和0x0A两个字符(“\r\n”),苹果机(MAC OS系统)则采用回车符CR表示下一行(\r)

Unix系统里,每行结尾只有“<换行>”,即“\n”;
Windows系统里面,每行结尾是“<回车><换行>”,即“\r\n”;
Mac系统里,每行结尾是“<回车>”,即“\r”。

一个直接后果是,Unix/Mac系统下的文件在Windows里打开的话,所有文字会变成一行;而Windows里的文件在Unix下打开的话,在每行的结尾会多车一个M字符。 Dos和windows采用回车+换行CR/LF表示下一行,即M$($不是换行符的表示,换行符没有表示出来,$是文本结束EOF的表示) 而UNIX/Linux采用换行符LF表示下一行,即\n
苹果机(MAC OS系统)则采用回车符CR表示下一行,即\r

CR用符号'\r'表示, 十进制ASCII代码是13, 十六进制代码为0x0D;
LF使用'\n'符号表示, ASCII代码是10, 十六制为0x0A. 所以Windows平台上换行在文本文件中是使用 0d 0a 两个字节表示, 而UNIX和苹果平台上换行则是使用0a或0d一个字节表示.

由于dos风格的换行使用\r\n,把这样的文件上传到unix,有些版本的vi不能识别\r,所以vi显示时在行尾会出现M出来,但是有些就能识别\r\n,正常显示回车换行。

dos to unix,去掉M

1
2
tr -d "\015" <myfile.txt > myfile_new.txt
tr -d "\r" <myfile.txt > myfile_new.txt