Archive

Archive for October, 2012

Restore Grub 2 Using LiveCD

October 21st, 2012 No comments

Restore Grub 2 Using LiveCD
Grub 2 typically gets overridden when you install Windows or another operating system. To make Grub 2 control the boot process, you need to reinstall (repair/restore) Grub 2 using a Ubuntu live CD.

Boot the computer using live CD. Open the Terminal. Using the following commands to mount the partition your Ubuntu Installation is on. If you are not sure which it is, launch GParted (included in the Live CD) and find out. Replace the XY in the command with your drive letter and partition number.

sudo mount /dev/sdXY /mnt
sudo mount --bind /proc /mnt/proc
sudo mount --bind /dev /mnt/dev
sudo mount --bind /sys /mnt/sys

Now you need to change root using chroot command.

sudo chroot /mnt

Now install and Grub 2. This time you only need to add the partition letter (no number) to replace X.

grub-install /dev/sdX
grub-install --recheck /dev/sdX

Now you can exit you mounted hard disk and unmount.

exit
sudo umount /mnt/sys
sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt

Shut down and turn your computer back on, and you will be met with the default Grub2 screen. You may want to update or re-configure Grub 2 using the method mentioned in Grub 2 Configuration to the way you like it.

Reference
How to Repair/Restore/Reinstall Grub 2 with a Ubuntu Live CD.

Categories: Linux Tags:

Grub 2 Configuration

October 14th, 2012 No comments

Grub 2 Configuration
Grub 2 的配置文件是位于 /boot/grub/ 目录下的 grub.cfg。与 Grub Legacy 不同的是,这个 grub.cfg 文件是不建议手动修改的。它是在安装或者更新 Grub 2 的时候自动生成的。如果要修改或者定制 grub.cfg 文件,则需要在两个地方进行修改,然后重新运行 grubmkconfig 的命令来生成新的 grub.cfg 文件。

两处需要修改的地方分别是: 1) /etc/default/ 目录下的 grub 文件和 2) /etc/grub.d/ 目录下的若干文件。

/etc/default/grub
先说一下 /etc/default/grub 文件。用文本编辑器打开这个文件,会看到如下相似的内容:

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
 
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_LINUX_RECOVERY="true"

# Uncomment to get a beep at grub start
# GRUB_INIT_TUNE="480 440 1"

在这里解释一下该文件里几个常用的命令。

GRUB_DEFAULT=0

这个命令指定缺省的可引导的操作系统。数字“0”表示在操作系统列表中的第一个操作系统将是缺省引导的操作系统。如果你想要把列表中的第四个操作系统作为缺省引导的系统,就把“0”改成“3”。剩下的以此类推。

#GRUB_HIDDEN_TIMEOUT=0

这个命令控制是否在计算机启动时显示操作系统列表。如果把“#”号去掉的话,在计算机启动的时候就不会显示可引导操作系统的列表。

GRUB_TIMEOUT=10

这个命令设置在计算机启动时 Grub2 在引导缺省操作系统前等待的时间(以秒为单位)。在这个时间里用户可以用键盘方向键选择不同的操作系统来进行引导。

GRUB_HIDDEN_TIMEOUT_QUIET=true

这个命令控制是否在计算机启动是显示时间倒计时(即用户还有多少时间进行选择)。如果设置为“true”则不会显示时间倒计时,如果设置为“false”则会显示时间倒计时。

/etc/grub.d/ 目录下的文件
再说一下 /etc/grub.d/ 目录下的几个文件。这些文件都是可执行文件,它们的命名方式为: nn_xxxxxx,其中 nn 是两位数的整数,xxxxxx 是任意字母、数字和有效字符的组合,如下所示:

00_header
05_debian_theme
10_linux
20_memtest
30_os-prober
40_custom

在更新 Grub 2 的时候,这些文件会按照 nn 从小到大的顺序被先后执行,执行的结果被写入 grub.cfg 文件。需要说明的一点就是 grub.cfg 里的可引导操作系统是按照这些文件被执行的先后顺序来写入文件的。如果你想把自己常用的操作系统放在列表最上面的话就需要自己建一个文件,文件名和上面提到的文件名类似,不过 nn 需要介于 “05” 和 “10” 之间,比如说可以命名为 06_custom。然后我们就可以编辑这个 06_custom 文件来让 Grub 2 加入我们自己的操作系统。

下面以加入引导 Windows 7 为例来说明如何编辑 06_custom 文件。Windows 7 用的是 chainloader type boot entry。下面的代码会在更新 Grub 2 的时候在列表最上面加入一个 “Windows 7” 的引导项。

#! /bin/sh -e
echo "Adding custom boot entry(s)" >&2
cat << EOF
menuentry "Windows 7" {
    set root=(hd0,1)
    chainloader +1   
}
EOF

需要注意的是下面这个命令:

set root=(hd0,1)

(hd0,1) 指的是安装了 Windows 7 的硬盘和分区。这个信息一定要正确,不然的话 Grub 2 引导 Windows 7 的时候会出错。这个信息可以在 Linux 下面用 fdisk -l 命令找出来。

编辑完 06_custom 文件后还需要把它变成可执行文件:

chmod 755 06_custom

如果需要删除 Grub 2 引导列表中的项目,则只需要简单地把 nn_xxxxxx 文件的可执行属性去掉。例如我们不想生成 memtest 项目,用下面的命令把 20_memtest 变成不可执行就行了:

chmod -x 20_memtest

生成新的 /boot/grub/grub.cfg 文件
在修改完上面提到的 /etc/default/grub 文件和 /etc/grub.d/ 下面的文件后,可以用下面这个命令来生成新的 grub.cfg 文件:

grub-mkconfig -o /boot/grub/grub.cfg

Reference
GRUB2 Configuration.

Categories: Linux Tags:

Embed Video in PowerPoint with Relative Path

October 5th, 2012 No comments

A very useful tip that I found in this post. Here is the quote:

Seems like relative paths are supported, they are just not straightforward to implement. For example if your Powerpoint presentation is in the MyFiles folder, and the MyMovie.avi is in the Media folder inside MyFiles. The trick is to edit the xml files inside the Powerpoint file:

  • Make a copy of your presentation as Presentation.pptx (just to keep the original safe).
  • Rename your Presentation.pptx file into Presentation.pptx.zip.
  • Open the resulting zip file by clicking on it. It will open as a folder. Inside it, go to ppt, then slides, then _rels. You will see files called slide1.xml.rels etc.
  • Copy (drag and drop) all those to another place, outside the archive. Now open the file corresponding to the number of your slide with video with some editor (for example, Notepad). Look for the line that says something like: Target=”file:///C:\MyFiles\Media\MyMovie.avi”. If your Powerpoint presentation is in the MyFiles folder, and the MyMovie.avi is in the Media folder inside MyFiles, then change the above line to: Target=”Media\MyMovie.avi”.
  • Save the slide1.xml.rels file (or whatever number it was), then drag it back to that archive (that is actually a Powerpoint file), and then rename the archive back to Presentation.pptx.

This is it. Now you should be able to carry around the folder MyFiles with the presentation and with the Media folder inside it that contains your video.

Works for me on Windows 7.

Categories: Tips and Tricks Tags: