如何在Linux下挂载带分区的镜像文件

之前一直有折腾ChromeOS,一位叫hexxeh的朋友一直有提供nightly build的镜像,所以免去了自己编译的烦恼。下载下来后,我打算修改一些东西后,再写入到U盘上,因为ChromeOS的映像文件是带有GPT分区的镜像,所以不能直接mount,需要在mount的时候的提供offset参数,即提供需要挂载的这个分区是从哪里开始的。像这样:

# sudo mount -o offset=xxx xxx.img /MOUNT/TO/DIR/

那么,如何得到这个offset的参数呢?我们可以用fdisk等工具来列出相关信息得到。不过,还有一个更NB的工具叫parted,一般可以在源里面找到。
继续阅读如何在Linux下挂载带分区的镜像文件

Debian VPS 在更新内核报错的问题

今天在Debian VPS上更新内核时碰到了问题,报错为

Setting up linux-image-2.6.32-5-686-bigmem (2.6.32-31) ...
Running depmod.
Running update-initramfs.
update-initramfs: Generating /boot/initrd.img-2.6.32-5-686-bigmem
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 2.6.32-5-686-bigmem /boot/vmlinuz-2.6.32-5-686-bigmem
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 2.6.32-5-686-bigmem /boot/vmlinuz-2.6.32-5-686-bigmem
Searching for GRUB installation directory ... found: /boot/grub
warning: grub-probe can't find drive for /dev/xvda1.
grub-probe: error: cannot find a GRUB drive for /dev/xvda1. Check your device.map.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-2.6.32-5-686-bigmem.postinst line 799,  line 2.
dpkg: error processing linux-image-2.6.32-5-686-bigmem (--configure):
subprocess installed post-installation script returned error exit status 2

之前在给公司的VPS作配置的时候也遇到了一样的问题,都是Xen的VPS,装的是Debian的系统,当时就只是把kernel的更新给keep了。今天自己碰到了一样的问题就细细琢磨了一下。看报错的情况是在更新Kernel的时候,没有找到装有GRUB的设备。下面是我解决的步骤:
继续阅读Debian VPS 在更新内核报错的问题

open_basedir restriction in effect: eAccelerator与open_basedir

今天在查阅apache的错误日志时发现有很多的warning,都跟open_basedir有关,如:

2011/09/25 21:27:54 [error] 3927#0: *146 FastCGI sent in stderr: “PHP Warning: require(): open_basedir restriction in effect. File() is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in /srv/http/xxx.php on line 913” while reading upstream, client: x.x.x.x, server: example.com, request: “GET / HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php-fpm/php-fpm-kelltan.sock:”, host: “example.com”, referrer: “http://example.com/”

检查php.ini的配置也没发现什么问题,google一番也没有有用的信息,只好自己动手找原因。重新查看了日志,发现这个警告出现在我安装eAccelerator之后,所以觉得这个错误应该跟eAccelerator有关。

在阅读了eAccelerator的wiki,然后又做了一番研究后发现,默认的eAccelerator编译选项跟open_basedir是不相容的,根据wiki上介绍,只要在编译的时候加上参数“ –without-eaccelerator-use-inode”,便可解决这个问题:

$ cd /PATH/TO/eaccelerator-0.9.6.1
$ make clean
$ ./configure --without-eaccelerator-use-inode
$ make
# make install

好了,重新编译完后,记得删掉eAccelerator之前产生的文件,然后重新启动apache:

# rm -rf /var/cache/eaccelerator/*
# /etc/rc.d/httpd restart

好了,一切重归宁静。

用TestDisk找回丢失的分区表

TestDisk

本来想把一ISO镜像dd写入到U盘里的,结果忘记我把移动硬盘也插在电脑上,直接”dd if=xx.iso of=/dev/sdb”了,而这个sdb正好是移动硬盘,于是iso全部被写入到了移动硬盘上@.@。好在移动硬盘上的分区都还挂载着,先把重要的数据都转移后,拨下移动硬盘,果然一个分区也认不出来了,应该是分区表已经被损坏,崩溃。

决定试着找回一下分区表,在网上找到了这篇:介绍一个 GPL 的分区表修复工具 TestDisk,Arch的源也面也正好有testdisk,下载安装,并看了一遍TestDisk的WIKI

之前在windows下也用过一些数据恢复的软件,而这个testdisk并不像那些软件有华丽丽的图形界面,只在终端下面提供一个向导,扫描后显示扫描结果,及有可能的分区情况,选择原先正确的分区情况后写入到硬盘,总算找回了所有分区。只是第一个分区似乎真的损坏了,好在这个分区无关紧要,我只在上面装了个移动作业系统,重新格式化这个分区后,一切安好。

继续阅读用TestDisk找回丢失的分区表