Eee PC 系統分區壓縮原理
April 15, 2008 – 10:02 pm這次實驗的動機:
1. 還原光碟大約只有 800 多 MB 的東西,但安裝到 Eee PC 上變成了 2.3 GB,4G的空間沒有了 60%。
2. 系統分區沒有經過任何處理,是直接把整個系統放上去的,有點浪費。
3. 以前看過很多 Live CD 都會使用 squashfs 這程壓縮的檔案系統,把幾 GB 的東西塞到 CD 光碟上,那同樣的原理應該可以用在 Eee PC 上吧。
4. 第一分區原本就是被第二分區所“覆蓋”著的,既然不會修改,用壓縮系統豈不更好?
所以就開始著手搞壓縮還原光碟了,我的作法如下(此動作需豐富Linux 經驗,請勿模仿~ ):
1. 把原來還原光碟的 P701L.img (或類似的檔案) 掛載起來,首先 losetup -f P701L.img 把影像檔自動設到某一沒用的 loop 設備, eg. /dev/loop0
2. kpartx -av /dev/loop0 把裡面的分區開啟,因為裡面有一個分區,所以會有 /dev/mapper/loop0p1 建立了
3. 掛載這個分區到某一目錄,例如 /mnt : mount /dev/mapper/loop0p1 /mnt
4. 因為原來的內核不支援 squashfs, 所以要找 squashfs 的驅動,可以到 eeeuser.com 找,或者自己找 Eee PC kernel 源碼編釋
5. 用 gunzip 跟 cpio 把 /mnt/boot/initramfs-eeepc.img 解開,把裡面的 init 腳本修改一下,在掛載 /dev/sda1 到某一暫時目錄之後,再在裡面掛載 root.sfs 到真正的 /mnt-system,然後在 chroot 時 chroot 到 root.sfs 的掛載點,例如:
mount -t ext2 -o ro $ROOT /mnt-system-stage
mount -t squashfs -o loop,ro /mnt-system-stage/root.sfs /mnt-system
6. 把 squashfs.ko 跟 zlib_inflate.ko 都放到 initramfs 的 modules 目錄下面,並在 init 中把它們載入:
/bin/insmod /modules/zlib_inflate.ko
/bin/insmod /modules/squashfs.ko
7. 用 cpio 跟 gzip 重新把 initramfs-eeepc.img 包起來,方法不詳細說了
8. 確認有安裝 squashfs-tools, 然後用 mksquashfs 建立壓縮檔: mksquashfs /mnt /tmp/root.sfs
9. 建立一個 1GB 的硬碟影像檔 (dd),然後用類似剛才 losetup, kpartx 的方法做一個 1GB 的分區,把 /mnt/boot 和 root.sfs 都拷進去
10. 換掉 /mnt/boot 中的 initramfs-eeepc.img
11. 寫好 GRUB 開機程式
12. 把所有的影像檔都 umount 掉,用 kpartx -d /dev/loop0 跟 losetup -d /dev/loop0 關掉 loop 設備
13. 最後把 P701L.img 換回原來的還原光碟上,成功
因為步驟是這樣的複雜,所以… 我們已經做好了,這幾天會放出來。 ![]()







26 Responses to “Eee PC 系統分區壓縮原理”
很期待啊 谢谢
By 02aaaa on Apr 16, 2008
謝謝您的分享,這世界才會變得更美好,期待您的創舉,感恩嗯!
By ken on Apr 16, 2008
ISO 檔都已經做好,也測試了,現在要跟華碩那邊協調一下,看看用什麼方法發佈會比較好。
By lazyfai on Apr 16, 2008
感謝,期待
By eeeuser on Apr 18, 2008
感謝你 Fai, you are not lazy but a genius.
By wycy2 on Apr 23, 2008
Great info, just have to make sure I know how to do Step 5 and Step 7 for the cpio/gzip part.
By Michael on Apr 25, 2008
Assuming you copied the intiramfs-eeepc.img to /tmp.
Make a working directory and enter that directory, then..
For extracting initramfs-eeepc.img:
zcat /tmp/initramfs-eeepc.img | cpio -i -dumv
For recompressing the extracted files:
find | cpio -o -Hnewc |gzip > /tmp/initramfs-eeepc.img
By lazyfai on Apr 25, 2008
Fai兄, 請問 xepc20080413.iso(905MB) 和L701_TW_1.04.19XEPC.iso 有何不同(961MB)? 是否eeepc 用英文介面要裝xepc20080413.iso(905MB),中文介面就裝L701_TW_1.04.19XEPC.iso?
By wycy2 on Apr 25, 2008
Re: wycy2
xepc-20080413.iso 是升級光碟,用途只是做升級的,即把原本華碩用的 OS 再加以修補升級用,要配合華碩原裝還原光碟使用。
L701 那個是壓縮版還原光碟,是華碩原來的 OS 加上這裡的修補和升級的還原光碟,即是代替買 Eee PC 時附送的光碟。
如果想硬碟有多 1.5 G 可用空間,又不介意開機速度變慢 2-3 秒的話,用後面的就可以。
By lazyfai on Apr 25, 2008
Is there a L701_EN_1.0.4.19XEPC.iso for English version with the SquashFS compression method?
By Michael on Apr 26, 2008
Also forgot to ask, does this version have 2GB RAM kernel support by default? Or do I still need to load the 2gb kernel onto /user manually?
By Michael on Apr 26, 2008
I went ahead with the upgrade and now have good and bad news.
Good News
I now have 2.6G out of 2.8G on my 4GB EeePC.
Bad News (depends how you define it)
1) I now have a Chinese OS interface, whereas I have English OS previously
2) My MMC-SD is not mounted by default, what do I have to do to fix/mount it?
3) Only 1GB RAM is recognized by default, will be nice if the default image has the 2GB RAM kernel support
4) Trying to create rescue mode fail, adding line (XANDROSBOOTDEBUG=y) gives “Error 27: Unrecognized command”. So, how do I modify the 2GB RAM kernel, put it in /usr?
5) There was some error during bootup on the very top, but it only last 1/2 sec. Where can I find a log of that?
Now, if I can only get an English version (since my kids can’t read the Chinese OSD interface)
By Michael on Apr 26, 2008
1. Language can be selected by running this command in terminal:
sudo /opt/xandros/bin/local_dialog
2. I dont have information about that yet…
3. 2GB kernel is unofficial, will it be compatible to all of drivers shipped in Eee PC?
If so, it will be considered.
4. To change kernel, you can use any live CD to boot the Eee PC, and then copy that file (probably called vmlinuz or bzImage something like that) to the first partition, to /boot/ directory.
5. That small warning is about DNS, it is safe to ignore that.
By lazyfai on Apr 26, 2008
Regarding the 2GB RAM kernel, I have been using this and no problem whatsoever so far:
http://www.eeewiki.org/howto:install2gigkernel
Will this to incorporate this into squashfs build this weekend.
I will re-test #2 (regarding MMC-SD)
By Michael on Apr 27, 2008
Yes, I can now change the language interface.
My MMC-SD is now also recognized.
Only problem left is to make my 2GB kernel into the squashfs
When using the LiveCD, I press (tab) to modify the ‘EEE PC’
I tried adding “XANDROSBOOTDEBUG=y” but I still cannot get to rescue console to modify the vmlinuz to become 2GB
By Michael on Apr 27, 2008
Re: Michael
Rescue mode is no need for changing the kernel alone.
Assuming you have downloaded the kernel in /home/user/ first.
Then to change the kernel, the steps are:
1. Adding XANDROSBOOTDEBUG=y to default boot parameters as shown in wiki page
2. After booting up, you will see a “#” prompt
3. mount /dev/sda1 /mnt-system
4. mount /dev/sda2 /mnt-user
5. Copy the kernel from /mnt-user/home/user/ to /mnt-system/boot/, cover the default kernel file.
6. umount /mnt-system
7. umount /mnt-user
8. Reboot the Eee PC.
By lazyfai on Apr 27, 2008
here is my problem, I cannot get into # prompt.
1) I run Easy Moode
2) Open terminal, modify /boot/grub/menu.lst
3) Add ‘XANDROSBOOTDEBUG=y’ to 2nd line in (Normal Boot)
4)Reboot
5)I don’t get # prompt, it gives back Easy mode
I think I miss something really simple
The wiki says get into rescue mode, but you said it’s no need.
Sorry to keep bothering you....
By Michael on Apr 27, 2008
Update:
I can now modify the kernel (replacing it), but the system gives kernel panic and died. Ended up having to restore the whole system from CD.
Guess I will stick with just 1gb ram for now
By Michael on Apr 27, 2008
Re: Michael
Since so many people requested for 2GB kernel in XEPC, and I found that Eee PC 900 does come with 2GB memory support, I will try to merge it into XEPC recovery disc in next release, probably in 1-2 weeks.
By lazyfai on Apr 27, 2008
Re: LazyFai
Thank you so much. If you need a tester for it, just let me know.
By Michael on Apr 28, 2008
Dear lazyfai:
想跟你請教一個問題喔~
在你上述說的 用dd做一個disk出來然後 再割一個partition,然後
把壓好的squashfs放進去和boot…
這整個都是在一個Virtual disk完成的.
因為此時的virtual disk 應該是mount成 loop device
我有辦法將 grub 裝到這個device上面去嗎?
使得我能直接將這個virtual disk 可以使用 dd 直接dump到/dev/sda1
且能開機
謝謝你
By chris on Apr 30, 2008
Re: chris
因為 grub 不能安裝在 virtual disk 上面,所以當我們要做這些動作時,先要用真實的硬碟,例如 USB disk 來做,再用 dd 變回一個映像檔才成。
By lazyfai on Apr 30, 2008
Dear lazyfai:
我剛剛把你做的Recovery解開其中P701L裡面含有開機用的boot和你做的squashfs, 這個檔案的產生就是找一個乾淨的usb隨身碟,割成一個ext2 virtual filesystem大小1003MB, 然後再將原本易pc的整個唯讀區域壓成唯讀的root.sys.
當還原光碟開機時就把整個partition dump到/dev/sda,就會產生/dev/sda1, 在從123 cynlinder的地方繼續分割成sda2,sda3,sda4
不知道我這樣描述有沒有誤
謝謝你.
By chris on May 1, 2008
Dear lazyfai:
這是fdisk -ul P701L.img 的輸出
Disk P701L.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0×0001d8b9
Device Boot Start End Blocks Id System
P701L.img1 63 1959929 979933+ 83 Linux
假設我現在usb 是mount 在/dev/sdc 且 grub 也是裝在/dev/sdc
且有一個分割區 /dev/sdc1
我如果要連同MBR輸出到sdc1是用
dd if=/dev/sdc of=./P701L.img bs=1959929*512
這樣就可以了嗎?
謝謝你
By chris on May 1, 2008
Re: chris
步驟大概就是這樣,不過我用 bs=32k,因為原來華碩的版本也是用 32k, 所以要用 count=x, x=1Gb/23kb .
還有 grub 要用 (hd0,0) 因為如果你用 usb 開機的話,這個 usb 磁碟就是 (hd0).
By lazyfai on May 1, 2008