標籤:
原理
前文 闡述的方法脫離了廣大機械硬碟和 USB 2.0 群眾的實際情況,是不得人心的。下面介紹一種更加符合科學發展觀的定製方法。
啟動時,GRUB 或 extlinux 先引導運行 /live/vmlinuz 和 /live/initrd.img, initrd.img 初始化之後會尋找 /live 目錄下以 squashfs ext2 ext3 ext4 xfs jffs2 尾碼的檔案和以 dir 為尾碼的目錄,然後將它們 union mount 成根目錄。union filesystem,聯合檔案系統是將多個檔案夾聯合掛載在一個檔案夾下,對聯合目錄的讀寫作用在指定為 rw 的分支目錄上。
#initrd.img/bin/boot/9990-overlay.sh:69 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]70 then71 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir72 do73 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"74 do75 if [ -e "${IMAGE}" ]76 then77 image_string="${image_string} ${IMAGE}"78 fi79 done80 done81 fi
定製
這裡使用工具 unionfs-fuse,相對於 aufs,unionfs 支援在使用者層上,相容性較好。 Debian 下安裝方法: apt-get install unionfs-fuse,接著執行:
cd /tmpmkdir custommkdir unionmount /path/to/live/filesystem.squashfs /mnt unionfs-fuse -o cow,max_files=32768 -o allow_other,use_ino,suid,dev,nonempty /tmp/custom=RW:/mnt=RO /tmp/union/ #1cd unionmount -o bind /proc proc/ #2chroot . #3
- 1:將兩個目錄掛載至 /tmp/union, 對 /tmp/union 的寫操作會回溯到 /tmp/custom 上。
-o cow,max_files=32768 -o allow_other,use_ino,suid,dev,nonempty 是必需的,要不然檔案讀寫方面會出問題。
- 2:proc 安裝某些軟體可能需要這裡的資訊,比如 VMWare。
- 3:主機系統如果不是 Kali,可能需要設定額外的變數,比如 PATH。
進去了之後,我們就可以上下其手,為所欲為了。操作完成之後,刪除 /tmp/custom 內多餘的目錄和檔案,打包:
cd /tmpmksquashfs custom/ custom.squashfscp custom.squashfs /path/to/live/
重啟之後即可看到效果。
GRUB2 引導 extlinux
直接複製 Kali ISO 的內容到隨身碟的某一分區後,假設是 /dev/sdb2,目錄名是 kaliLive,安裝 extlinux
extlinux -i /path/to/kaliLive/
這時 /dev/sdb2 的首 512 位元組是 extlinux 的 bootloader。如果你在 /dev/sdb 安裝了 GRUB 2 可以以:
set root=(hd0,msdos2)chainloader +1boot
引導 extlinux。
其它
- 用
複製+手動安裝 bootloader 的方法會在 kali 1.0.1 下無法使用 persistence 功能。dd 的方法沒測試過。
- 對於需要頻繁修改的小檔案,比如 .bashrc,可以考慮放在 .dir 目錄下。
定製 Kali Linux Live USB 的另一種方法