系統要求:
- 超級管理員訪問權限
- 一個最新版本的live-build
- 符合POSIX標准的shell,如bash或dash
- debootstrap或cdebootstrap
- 內核2.6+
環境說明:
debian 8(jessie)
安裝live-build:
apt-get install live-build
創建默認鏡像:
mkdir live-system && cd live-system
lb config
lb build
刻錄ISO鏡像到光盤:
apt-get install xorriso
xorriso -as cdrecord -v dev=/dev/sr0 blank=as_needed live-image-i386.hybrid.iso
復制ISO鏡像到U盤:
cp live-image-i386.hybrid.iso ${USBSTICK}
sync
使用U盤的剩余空間:
分區:
gparted ${USBSTICK}
格式化:
mkfs.ext4 ${PARTITION}
注意:PARTITION為新創建的分區。
用qemu測試ISO鏡像:
apt-get install qemu-kvm qemu-utils
kvm -cdrom live-image-i386.hybrid.iso
創建HDD鏡像:
lb clean --binary
lb config -b hdd
lb build
最后會生成live-image-i386.img的文件。
安裝到USB驅動器:
lb clean --binary
lb config -b usb-hdd
lb build
dd if=binary.img of=/dev/sdb
使用自動配置腳本:
mkdir mylive && cd mylive && lb config
mkdir auto
cp /usr/share/doc/live-build/examples/auto/* auto/
創建auto/config配置文件,內容如下:
#!/bin/sh
lb config noauto \
--architectures i386 \
--linux-flavours 686-pae \
--binary-images hdd \
--mirror-bootstrap http://ftp.cn.debian.org/debian/ \
--mirror-binary http://ftp.cn.debian.org/debian/ \
"${@}"
注意:使用lb config命令會重置auto/config文件的配置。
配置選項說明:
指定版本:
--distribution jessie
--archive-areas "main contrib non-free"
用於鏡像創建時的安裝源:
--mirror-bootstrap http://ftp.cn.debian.org/debian/
--mirror-chroot-security http://ftp.cn.debian.org/debian-security/
用於鏡像運行時的安裝源:
--mirror-binary http://ftp.cn.debian.org/debian/
--mirror-binary-security http://ftp.cn.debian.org/debian-security/
--mirror-binary-backports http://ftp.cn.debian.org/debian-backports/
添加其他安裝源:
添加到config/archives/live.list.chroot文件內的安裝源在創建鏡像時被使用。
添加到config/archives/live.list.binary文件內的安裝源會被加入到系統/etc/apt/sources.list.d/目錄。
兩個文件內容格式如下:
deb http://debian-live.alioth.debian.org/ sid-snapshots main contrib non-free
選擇安裝的軟件:
配置文件目錄為:config/package-lists/,例如安裝桌面和瀏覽器,配置如下:
lb config
echo "task-lxde-desktop iceweasel" > config/package-lists/desktop.list.chroot
生成軟件列表:
lb config
echo '! Packages Priority standard' > config/package-lists/standard.list.chroot
配置可安裝的鏡像:
lb config --debian-installer live
echo debian-installer-launcher >> config/package-lists/installer.list.chroot
安裝第三方軟件包:(必須添加第三方安裝源)
直接復制軟件包列表文件到config/packages.chroot/目錄,在創建鏡像期間會被自動安裝。
調整APT節省空間:(可能會帶來一些問題)
# 禁用緩存軟件索引
--apt-indices false
# 禁用APT推薦功能
--apt-recommends false
自定義內容:
配置目錄為:config/includes.chroot,例如添加www目錄及文件:
mkdir -p config/includes.chroot/var/www
cp /path/to/my/index.html config/includes.chroot/var/www
Hooks
包含系統創建完后需要執行的腳本。
/usr/share/doc/live-build/examples/hooks
config/hooks/
*.hook.chroot
*.hook.binary
/lib/live/config/ --> config/includes.chroot/lib/live/config/
例子:創建hooks/auto_ssh.hook.chroot文件,內容如下。
#!/bin/sh
echo "HOOK: ssh server"
update-rc.d ssh defaults
passwd root <<EOF
admin
admin
EOF
修改執行權限:
chmod u+x auto_ssh.hook.chroot
自定義live用戶:
加入live用戶到fuse組:
config/includes.chroot/etc/live/config/user-setup.conf
LIVE_USER_DEFAULT_GROUPS="audio cdrom dip floppy video plugdev netdev powerdev scanner bluetooth fuse"
或者作為啟動的參數:
live-config.user-default-groups=audio,cdrom,dip,floppy,video,plugdev,netdev,powerdev,scanner,bluetooth,fuse
也可以配置中改變默認的用戶”user“和默認的密碼”live“:
$ lb config --bootappend-live "boot=live components username=live-user"
更改默認密碼方法:
passwd: /usr/share/doc/live-config/examples/hooks --> config/includes.chroot/lib/live/config/
自定義語言環境和語言:
lb config --bootappend-live "boot=live components locales=en_US.UTF-8"
egrep -i '(^!|german.*switzerland)' /usr/share/X11/xkb/rules/base.lst
lb config --bootappend-live "boot=live components locales=de_CH.UTF-8 keyboard-layouts=ch"
lb config --bootappend-live "boot=live components locales=fr_FR.UTF-8 keyboard-layouts=fr keyboard-variants=bepo keyboard-model=tm2030usb"
lb config --bootappend-live "boot=live components keyboard-layouts=us,us keyboard-variants=,dvorak"
持久存儲:
在硬盤的一個ext4分區或USB閃存盤創建:
mkfs.ext4 -L persistence /dev/sdb1
使用U盤的剩余空間創建:(注意指定正確的分區)
tune2fs -L persistence /dev/sdb1 # for ext2,3,4 filesystems
使用一個基於ext4的鏡像文件作為持久存儲:
dd if=/dev/null of=persistence bs=1 count=0 seek=1G # for a 1GB sized image file
/sbin/mkfs.ext4 -F persistence
cp persistence /
mount -t ext4 /persistence /mnt
創建配置文件並追加內容:
echo "/usr union" >> /mnt/persistence.conf
umount /mnt
現在,帶啟動參數”persistence“重啟你的live介質。
例子:將home目錄和apt緩存目錄持久存儲在/dev/sdb1分區上的一個ext4文件系統里面。
mkfs.ext4 -L persistence /dev/sdb1
mount -t ext4 /dev/sdb1 /mnt
echo "/home" >> /mnt/persistence.conf
echo "/var/cache/apt" >> /mnt/persistence.conf
umount /mnt
注意:persistence.conf文件列出的任何路徑不能包含空格或特殊目錄"."和"..",也不能包含/lib,/lib/live目錄及其子目錄和/,可以添加/ union實現完全持久存儲。
使用加密的持久存儲:
apt-get install cryptsetup
lb config
echo "cryptsetup" > config/package-lists/encryption.list.chroot
lb config --bootappend-live "boot=live components persistence persistence-encryption=luks"
使用U盤的一個分區:
ls -l /dev/disk/by-id
cryptsetup --verify-passphrase luksFormat /dev/sdc2
cryptsetup luksOpen /dev/sdc2 live
dd if=/dev/zero of=/dev/mapper/live
mkfs.ext4 -L persistence /dev/mapper/live
mount /dev/mapper/live /mnt
echo "/ union" > /mnt/persistence.conf
umount /mnt
cryptsetup luksClose live
Customizing the binary image
Bootloaders:
/usr/share/live/build/bootloaders --> config/bootloaders
config/bootloaders/*
config/bootloaders/isolinux
splash.svg --> splash.png
isolinux.cfg:
include menu.cfg
default vesamenu.c32
prompt 0
timeout 50
ISO metadata:
LB_ISO_APPLICATION/--iso-application NAME
LB_ISO_PREPARER/--iso-preparer NAME
LB_ISO_PUBLISHER/--iso-publisher NAME
LB_ISO_VOLUME/--iso-volume NAME
Customizing Debian Installer:
lb config --architectures i386 --linux-flavours 586 --debian-installer live
echo debian-installer-launcher >> config/package-lists/my.list.chroot
Customizing Debian Installer by preseeding:
echo "d-i debian-installer/locale string en_US" >> config/includes.installer/preseed.cfg
Customizing Debian Installer content:
config/packages.binary/
config/includes.installer/
Options
默認情況下,制作的 LiveCD 在開機引導時會出現引導畫面,需要用戶手動選擇。
如需跳過手動選擇畫面,直接進入系統需要使用 genisoimage 再次配置 LiveCD 的映像文件。
liveCD:
apt-get install genisoimage
cd
mount -o loop live/binary-hybrid.iso /mnt
mkdir live-cd
cp -r /mnt live-cd/iso
umount /mnt
cd live-cd/iso/isolinux
chmod u+w isolinux.cfg
創建isolinux.cfg文件,內容如下:
default live
label live
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live config quiet
cd ~/live-cd
chmod u+w iso/isolinux/isolinux.bin
genisoimage -r -V "debian Live session" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o debian-live-i386.iso iso
liveUSB:
1) Go to the root folder of your Live USB.
2) Enter the syslinux directory.
3) Make the syslinux.cfg file writeable.
4) Replace the contents of the file syslinux.cfg with:
default live
label live
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live config quiet
小結:
1.自動配置腳本目錄:auto/config
2.創建鏡像時安裝的軟件所在目錄:config/package-lists/
3.自定義鏡像內容目錄:config/includes.chroot/
4.創建系統后執行的腳本所在目錄:config/hooks/
5.自定義引導程序目錄:config/bootloaders/
6.自定義Debian Installer:使用--debian-installer live選項,安裝debian-installer-launcher包
7.自定義Debian Installer的內容:config/packages.binary/,config/includes.installer/