unbuntu linux 系統安裝 與 make kernel
(1) unbuntu linux 系統安裝
已安裝Windows
在這裡我們以Windows XP 作例子。
所需準備材料
- Ubuntu光碟映像檔 官方網站:http://www.ubuntu-tw.org/(台灣官網)
- Grub4dos 官方網站:http://sarovar.org/projects/grub4dos/
步驟
- 下載Ubuntu光碟映像檔不用說,大家都知道,在這裡我們以 ubuntu-10.04-desktop-i386.iso作範例。
- 將光碟映像檔移到C:\
- 將光碟映像檔裡面的/casper/initrd.lz和/casper/vmlinuz兩個檔案複製到C:\
- 接著我們要下載Grub4dos,先到官網後,點選Downloads,然後選擇好一個版本後下載,我們以grub4dos-0.4.4.zip 作範例。
- 下載好後將此壓縮檔打開,將裡面其中一個檔名為「grldr.mbr」解壓縮到C:\
- 增加 boot.ini檔C:\boot.ini
[boot loader]
[operating systems]
C:\grldr.mbr="Start GRUB" - 於 c:\menu.lst 加入
title Install Ubuntu
root (hd0,0)
kernel /vmlinuz boot=casper iso-scan/filename=/ubuntu-10.04-desktop-i386.iso
initrd /initrd.lz - 在進入到LiveCD裡後,在點選桌面的安裝之前,必須先卸除isodevice,所以請到終端機下以下指令
sudo umount -l /isodevice - 重開機後, 於開機選單選擇 "Start GRUB" → "Install Ubuntu" 即可開始安裝
- 安裝完成 開機選單 /boot/grub/grub.cfg
(2) ubuntu make kernel
2-1 make kernel
Compile an Ubuntu 10.04 Kernel
Step #1: Download and install the necessary tools.
在Compile kernel前要先確定的就是有個gcc可以用啦,如果不確定就用apt-get build-dep gcc再安裝一次gcc吧,安裝完隨便寫個Hello Wrold測試一下就行啦。
# apt-get build-dep gcc ( 若權限問題加上 sudo ---> # sudo apt-get buile-dep gcc)
Download the necessary tools so that you have everything ready.
# apt-get install kernel-package libncurses5-dev fakeroot wget bzip2
You must have the source available to create a new kernel.
a.wget 方法(recommended)
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.33.7.tar.bz2
解壓縮Linux kernel,Create一個linux的soft link到linux-2.6.22.9。並切換到/usr/src/linux目錄。
# tar jxf linux-2.6.33.7.tar.bz2
# ln -s linux-2.6.33.7 linux
# cd /usr/src/linux
or b.傳統方法(skip)
# apt-get install linux-source
# cd /usr/src
# bzip2 -d linux-source-2.6.28.tar.bz2
# tar xvf linux-source-2.6.28.tar
Create a symbolic link to this source directory and name it linux.
# ln -s linux-source-2.6.28 linux
# cd linux
先把舊的.config copy來用吧,至少確定是可以work的Kernel設定,而且可以以舊的設定為基礎再去修改自己需要的Kernel功能,不用一切從頭來。
執行cp /boot/config-`uname -r' ./.config就會把目前用的Kernel的.config copy到現在目錄下囉。
# cp /boot/config-`uname -r` ./.config (` 符號在左上角)
Step #2: Now the fun begins….
You are ready to start menuconfig which will allow you to choose your kernel specifics.
make menuconfig
這時就可以選"Load an Alternate Configuration File"啦。
Here you see it detected the .config file.
Now work your way through the menus and make the selections that you want to add or subtract. For example, here KVM is changed from being a module to load to actually being made a part of the kernel. It has been unchecked so modular support will not be available, thus saving space in your kernel. The “*” indicates that it will be loaded into the kernel and an empty option means that no support for that option will be placed in the kernel.
If you know about your hardware you can increase your speed by making the kernel smaller by removing those modules that you do not need. It is important that you make changes slowly so that if you have problems you have fewer places to troubleshoot.
Once you have all of your modifications complete save the new .config file.
Run this command to clean up.
# make-kpkg clean
The next thing you want to do is create a kernel extension so that as you make kernels you are able to tell the versions apart. What I usually do is place my initials and a number so that I can keep track.
# fakeroot make-kpkg – -initrd – -append-to-version=-mw4 kernel_image kernel_headers
(or # fakeroot make-kpkg --initrd kernel_image kernel_headers)
After –append-to-version= you write a string that will help you keep track of your kernel changes, it must begin with a minus (-) and must not contain whitespace.
This will take awhile. This can take 3-6 hours depending on your CPU and memory.
Build完Kernel後切換到/usr/src目錄,會看到多了"linux-image-
2.6.22.9_2.6.22.9-10.00.Custom_i386.deb"和"linux-headers-
2.6.22.9_2.6.22.9-10.00.Custom_i386.deb"這兩個檔案。
執行dpkg -i linux-image-2.6.22.9_2.6.22.9-10.00.Custom_i386.deb。
After the successful kernel build, you can find two .deb packages in the directory you built the kernel in. If you were located in the linux directory, look in the directory above for the two .deb packages.
Now you can install and create .deb files so you can take your kernel to another machine with similar hardware. Run these commands as root in order to install them into the boot directory and modify your /boot/grub/menu.lst.
# dpkg -i linux-image-2.6.28.9mw4_2.6.28.9mw4-10.00.Custom_i386.deb
# dpkg -i linux-headers-2.6.28.9mw4_2.6.28.9mw4-10.00.Custom_i386.deb
2-2 準備 initrd img file
mkinitramfs -o /boot/initrd_2.6.33.7-custom.img /lib/modules/2.6.33.7-custom
mkinitramfs
大家都知道Ubuntu是由Debian衍生而來的!但是mkinitrd命令是RedHat專有的
早期Ubuntu有個工具包initrd-tools 內含這個指令
但由於Ubuntu工具包不斷更新,initrd-tools工具包已經被其他包所包含
其它Linux發行版或許有相應的命令
而在Ubuntu底下則有一個工具mkinitramfs可以達到此功能
語法:mkinitramfs [-d confdir] [-k] [-o outfile] [-r root] [version]
製作前要先在/etc/initramfs-tools/modules 新增要添加的模組
mkinitramfs -o /boot/initrd_xxx.img /lib/modules/2.6.22-14-generic
其中前面initrd_XXX.img就是自己隨便起的名字,後面的路徑,是你的内核所在的目錄, 完成後在/boot下會多出一個initrd_xxx.img文件,這是關鍵的一步。
最後要做的就是修改/boot/grub/menu.lst 即可
2-3 add initrd /boot/initrd_2.6.33.7-custom.img to grub.cfg
modify /boot/grub/grub.cfg
....
menuentry 'Ubuntu, with Linux 2.6.33.7-custom' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hdi1,3)'
search --no-floppy --fs-uuid --set 4765111b-00d9-44c9-9e60-92adc5d804f2
linux
/boot/vmlinuz-2.6.33.7-custom
root=UUID=4765111b-00d9-44c9-9e60-92adc5d804f2 ro quiet
splash
initrd /boot/initrd_2.6.33.7-custom.img
}
2-4 Reboot!
# uname -a
