- 论坛徽章:
- 0
|
實習這陣子常常接觸到 linux , 也讓我看到現在電子科技公司對 linux 人才的需求越來越高了。學習linux 已成大勢所趨。雖然現在有很多功能強大的 虛似機軟件 ( virtual machine ) , 如oricale virtualbox , VMware player 等 ... 但是一些linux 功能上的調試還是和真實機器有一定差距的 。一方面想擁有一台linux 機 , 另一方面又不想花太多 $$ 買 hard-disk / 在現有hard-disk 劃分區 , 那怎麼辦呢 ? 把linux 安裝到 U 盤便是一個好方法 。
以下是本人在 windows vista 筆記本下構建 Debian Lenny linux 系統到 U 盤的經歷 。
第一步 : 安裝虛似機軟件 ( virtual machine ) 及安裝 Debian linux 到虛似機
虛似機軟件用 Oricale VirtualBox 或 VMware Player 均可 ( 都是免費 ) 。但個人prefer VMWare Player 因為 USB 功能較強 。 Debian linux 則安裝最新的 distribution ! (免費 ! linux 的好處就是開源和免費 !) 至於具體安裝方法則略過不談 , 網上有很多教學 。
第二步 : 格式化 USB
有安裝過系統或"洗機" 的朋友都會有經驗 , 安裝作業系統之先必須進行硬盤格式化 (format) 。格式化 USB 在安裝了 Debian linux 的虛似機進行。
foo:~/# fdisk /dev/sdb
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1015, default 1):
Last cylinder or +size or +sizeK (1-1015, default 1015):
Using default value 1015
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sda: 1031 MB, 1031798784 bytes
32 heads, 62 sectors/track, 1015 cylinders
Units = cylinders of 1984 * 512 = 1015808 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1015 1006849 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
foo:~/# mkfs -t ext2 /dev/sdb1
注意 : /dev/sdb 是本人機內的 USB , 但隨著機器的不同 , 名字也會有差異 。 e.g. /dev/sdc , /dev/sdd .... etc
不確定USB的名字是什麼 , 將USB拔掉再插入吧 ~ 系統會自動顯示的。
OK , 現在USB 格式化成 單一分區的 EXT2 檔案系統 ~ 很易理解吧 ~
第三步 使用debootstrap指令安裝根文件系統
foo:~# mkdir -p /mnt/chroot/boot
解 : 在 /mnt 文件夾中建立 chroot 和 chroot/boot 文件夾 。
foo:~# mount /dev/sdb1 /mnt/chroot/
解 : 將格式化了的USB分區 sdb1 mount 到/mnt/chroot 文件夾中 。現在對文件夾 /mnt/chroot 進行任何修改將等於對 USB 的 分區進行修改 !
foo:~# debootstrap lenny /mnt/chroot
解 : 使用 debootstrap 命令從 debian 官網下載 lenny 版本 的根文件系統到USB分區 sdb1。
foo:~# chroot /mnt/chroot
解 : change root 到 USB分區 sdb1 , 以後下的指令將會由 USB 的根文件系統執行。
foo:/# apt-get update
解 : 下載及安裝更新 。
foo:/# apt-get dist-upgrade
第 4 步 : 安裝必須的 locales
foo:~# apt-get install locales
foo:~# dpkg-reconfigure locales
foo:~# apt-get install localepurge
foo:~# localepurge
就是安裝和設定 locales ....
第 5 步 : 安裝 linux 內核並生成鏡像文件
foo:~# apt-get install linux-image-2.6.26-2-486
foo:~# depmod 2.6.26-2-486
第 6 步 : 下載並安裝 載入程序 (bootloader) : grub2
foo:~# apt-get install grub2
第 7 步 : 系統設置
foo:~# vim /etc/network/interfaces
解 : 修改 /etc/network/interfaces 以設置網絡功能 , 設置如下 :
# Used by ifup( and ifdown(. See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
foo:~# vim /etc/hostname
解 : 修改 /etc/hostname 以設置喜歡的 host name 。
foo:~# vim /etc/hosts
解 : 修改 /etc/hosts ,設置 :
127.0.0.1 localhost
foo:~# vim /etc/fstab
解 : 修改以告訴系統如何mount 設備 !! 如下 :
proc /proc proc defaults 0 0
/dev/sda1 / ext2 rw 0 0
最後 : 安裝 GRUB !!!!
foo:~# exit
foo:~# grub-install --recheck --root-directory=/mnt/chroot /dev/sdb
foo:~# mount --bind /dev /mnt/chroot/dev
foo:~# chroot /mnt/chroot
foo:~# update-grub
修改 grub.cfg , 再 update-grub , 具體方法參考網上教學 !!!!
foo:~# exit
大功告成 !!!! 在 插入PC 試試吧 ! 拔出 USB 前緊記 umount /mnt/chroot/dev 和 umount /mnt/chroot 啊 =] good luck ! |
|