特殊:Badtitle/NS100:LiveCDCustomization

来自Ubuntu中文
Wikibot留言 | 贡献2009年5月12日 (二) 17:44的版本
跳到导航跳到搜索
可打印版本不再受到支持且可能有渲染错误。请更新您的浏览器书签并改用浏览器默认打印功能。

{{#ifexist: :LiveCDCustomization/zh | | {{#ifexist: LiveCDCustomization/zh | | {{#ifeq: {{#titleparts:LiveCDCustomization|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:LiveCDCustomization|1|-1|}} | zh | | }}

How to Customize the Ubuntu Desktop CD

You may wish to customize the Ubuntu Desktop (live) CD to:

  • make your own Linux / Ubuntu distribution
  • show off a particular application
  • localize to a certain language
  • remove software packages
  • add software packages
  • update software packages
  • change system defaults (theme, icons, desktop background, panels, browser homepage, etc)

IconsPage?action=AttachFile&do=get&target=warning.png This guide is for the Desktop/Live CD; there is another page referring to customization of the Alternative Install or Server Install CD.

System Requirements

  • At least 3-5 GB of free space
  • At least 512 MB RAM and 1 GB swap (recommended)
  • `squashfs-tools`
  • `genisoimage`, which provides `mkisofs`
  • An Ubuntu kernel with `squashfs` support (present in Ubuntu 6.06 and later)
  • QEMU/KVM, VirtualBox or VMware for testing (optional)

The Process

First, make sure that you have installed the needed tools

sudo aptitude install squashfs-tools genisoimage

Load the squashfs module

sudo modprobe squashfs

You need to download an official Desktop CD from http://releases.ubuntu.com/ Note: the example shown here uses the ubuntu-8.10-desktop-i386.iso Desktop CD Move or copy it into an empty directory

mkdir ~/live
mv ubuntu-8.10-desktop-i386.iso ~/live
cd ~/live

Extracting the CD contents

Mount the Desktop .iso

mkdir mnt
sudo mount -o loop ubuntu-8.10-desktop-i386.iso mnt

Extract .iso contents into dir 'extract-cd'

mkdir extract-cd
rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd

Extracting the Desktop system

Mount the squashfs filesystem

mkdir squashfs
sudo mount -t squashfs -o loop mnt/casper/filesystem.squashfs squashfs

Extract squashfs contents into dir 'edit'

mkdir edit
sudo cp -a squashfs/* edit/

Prepare and chroot

If you need the network connection within chroot

sudo cp /etc/resolv.conf edit/etc/

Depending on your configuration, you may also need to copy the hosts file

sudo cp /etc/hosts edit/etc/
sudo mount --bind /dev/ edit/dev
sudo chroot edit
mount -t proc none /proc
mount -t sysfs none /sys

(these mount important directories of your host system - if you later decide to delete the edit/ directory, then make sure to unmount before doing so, otherwise your host system will become unusable at least temporarily until reboot) To avoid locale issues and in order to import GPG keys

export HOME=/root
export LC_ALL=C

Customizations

Apt-get

To view installed packages by size

dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -nr | less

When you want to remove packages remember to use purge

aptitude purge package-name

Custom Background for GNOME

Generally background files are located in /usr/share/backgrounds. Copy your png file there, adjust owner and file access, and edit the files:

  1. /usr/share/gnome-background-properties/ubuntu-wallpapers.xml and
  2. /usr/share/gconf/defaults/16_ubuntu-artwork or other files in the same directory. by changing the string /usr/share/backgrounds/warty-final-ubuntu.png to point to your file

Eventually change or add attributes to other configuration files such as: /var/lib/gconf/debian.defaults/%gconf-tree.xml or /etc/gconf/gconf.xml.defaults/%gconf-tree.xml). Historical: More for Dapper...

Change gconf values (fonts, panels etc.)

To make any change on the gconf attributes you must add the value that you want in the file /etc/gconf/gconf.xml.defaults/%gconf-tree.xml. Adding a value in that file will change the default values of Gnome or other applications, so you can change fonts, backgrounds, themes, cursors etc. Instead of editing the file with gedit or another text editor, you can use the gconftool-2, under the chroot environment, running the following line:

gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set yourkey "yourvalue"

where string, yourkey and yourvalue must be the type, key and value that you want to change...

Making several gconf changes

Editing gconf by setting each value separately takes too much time. There is a better way: Make a test user and adjust the settings as you wish. Run

gconftool-2 --dump /the/settings/branch/you/need > ~/live/your-new-settings.xml
sudo chown root:root ~/live/your-new-settings.xml
sudo mv ~/live/your-new-settings.xml ~/live/edit/your-new-settings.xml

and then, in the chroot environment, run

gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --load /your-new-settings.xml
rm /your-new-settings.xml

This way you can import the whole branch, e.g. /apps/panel - all settings for Gnome's panels.

Change default language of gfxboot

This customization must be done outside the chroot.

sudo -s
aptitude install dpkg-dev
aptitude source gfxboot-theme-ubuntu gfxboot
cd gfxboot-theme-ubuntu*/
make DEFAULT_LANG=fi
sudo cp -af boot/* ../extract-cd/isolinux/
exit

Change "fi" to your preferred locale. Note that this does not change which languages are available in the F2 menu. For more info about gfxboot customization, see Ubuntu Customization Kit.

  • A other way to change the default language of gfxboot without rebuild the packages is to create a file name lang in the isolinux directory containing your locale's name.

Customization limits

After customization make sure that there are no users with an UID >= 1000. Otherwise your image won't boot because no initial user is available (see /usr/lib/user-setup/functions.sh and /usr/lib/user-setup/user-setup-apply). While in chroot:

grep '^[^:]*:[^:]*:[1-9][0-9][0-9][0-9]:' /etc/passwd
grep '^[^:]*:[^:]*:[12][0-9][0-9][0-9][0-9]:' /etc/passwd

If you get any hits, try changing the uid:

usermod -u 500 $hit

Miscellaneous Defaults

You may wish to edit the files in /etc/default to change system behavior at startup. You might also edit /etc/profile, /etc/bash.bashrc, and /etc/bash_completion to change login settings for all users on the system. You cannot directly edit defaults for the live cd user (e.g., casper, ubuntu, or user) since that account is created at boot time. You can directly edit root's default files (/root in the chroot environment). If you wish to change the default timezone used by the live cd, run:

dpkg-reconfigure tzdata

If you have added a locale and wish to make it the default, update /etc/default/locale. You may have to compile the locale:

locale-gen new_locale
update-locale LANG=new_locale LANGUAGE=new_locale LC_ALL=new_locale

These changes must be made as root in the chroot environment.

Advanced Customizations

Live CD Kernel

If you want to customize further the boot process, you can change the livecd kernel, by copying the vmlinuz and initrd you want in place of the ones you find in extract-cd/casper. i.e.

sudo cp edit/boot/vmlinuz-2.6.15-26-k7 extract-cd/casper/vmlinuz
sudo cp edit/boot/initrd.img-2.6.15-26-k7 extract-cd/casper/initrd.gz

Boot init

You have to edit the files in edit/usr/share/initramfs-tools/scripts/casper-bottom/* For example you can change the hostname or the livecd user. i.e.

sudo nano edit/usr/share/initramfs-tools/scripts/casper

and edit the username or hostname

sudo nano edit/usr/share/initramfs-tools/scripts/casper-bottom/10adduser

to edit even the livecd user's password. P.S. in order to obtain an encrypted password, you have to use the mkpasswd program that's shipped with whois package!

Rebuilding initrd

After you've modified the kernel, init scripts or added new kernel modules, you need to rebuild the initrd.gz file and substitute it into the casper directory.

sudo chroot edit
mkinitramfs -o /initrd.gz 2.6.15-26-k7

(replace the kernel version with the one that the CD will boot with - this can be found in edit/lib/modules) Exit from the chroot jail and move this file to extract-cd/casper:

exit
mv edit/initrd.gz extract-cd/casper/

Cleanup

Be sure to remove any temporary files which are no longer needed, as space on a CD is limited. A classic example is downloaded package files, which can be cleaned out using:

aptitude clean

Or delete temporary files

rm -rf /tmp/* ~/.bash_history

Or nameserver settings

rm /etc/resolv.conf

from within the chroot environment. now umount (unmount) special filesystems and exit chroot

umount /proc
umount /sys
exit
sudo umount edit/dev

Note: if "umount /proc" command fails try "umount -lf /proc"

Putting the CD together

Regenerate manifest

chmod +w extract-cd/casper/filesystem.manifest
sudo chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' > extract-cd/casper/filesystem.manifest
sudo cp extract-cd/casper/filesystem.manifest extract-cd/casper/filesystem.manifest-desktop
sudo sed -i '/ubiquity/d' extract-cd/casper/filesystem.manifest-desktop

Compress filesystem

sudo rm extract-cd/casper/filesystem.squashfs
sudo mksquashfs edit extract-cd/casper/filesystem.squashfs -nolzma

Note: The -nolzma option is only available from Hardy. Set an image name in extract-cd/README.diskdefines

sudo vim extract-cd/README.diskdefines

Remove old md5sum.txt and calculate new md5 sums

sudo -s
rm extract-cd/md5sum.txt
(cd extract-cd && find . -type f -print0 | xargs -0 md5sum > md5sum.txt)
exit

(check that the files "md5sum.txt" and "./isolinux/boot.cat" do NOT appear in md5sum.txt. If they do, delete their lines) Create Iso

cd extract-cd
sudo mkisofs -D -r -V "$IMAGE_NAME" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../ubuntu-8.04.1-desktop-i386-custom.iso .

Testing the CD

Test using qemu emulator

qemu -cdrom ubuntu-8.04.1-desktop-i386-custom.iso -boot d -m 512

Or if you have hardware acceleration for kvm

kvm -cdrom ubuntu-8.04.1-desktop-i386-custom.iso -boot d -m 512

You can also test with virtualbox-ose, which is free software and available in the Ubuntu universe repository.

Troubleshooting

Some experience problems virtualizing the iso after changing the livecd linux kernel. If you do, go click F6 when the boot screen is showing. Move the cursor between splash quite and -- and write: all_generic_ide

Burning the image to CD

Simple! Just do

cdrecord dev=/dev/cdrom ubuntu-8.04.1-desktop-i386-custom.iso

Additional uses for the image

Install|Ubuntu from a USB stick Installation|From Image Loaded On Hard Drive

Comments

If you have any comments or questions, please feel free to add them here.


I have created an small Customization Example (named Firebird Live CD) by adding an firebird2.1-superand flamerobin packages (this apply to ubuntu Hardy Heron also it was tested with xubuntu 8.04) http://flamerobin.blogspot.com/2008/08/creating-flamerobinfirebird-livecd-with.html


Warning: qemu did not work for me as given in the guide above. Even the normal 8.04 live cd would not boot correctly. Every time, I would get thrown into the ash shell (busybox, initramfs) and while there, a "cat /casper.log" would reveal that it was "Unable to find a medium containing a live filesystem". Just use virtualbox-ose. It actually works with virtualbox. However, after using apt-get to install virtualbox-ose, I had to run "sudo depmod" again in order for the vboxdrv module to be found by modprobe. Hope that helps! -rocketman768


Warning: Squashfs is currently in development and is thus not finalized as a format. This means you cannot assume a filesystem.squashfs created using the Ubuntu 8.10 version of makesquashfs will be compatible with the squashfs drive an older live CD. I was customizing an Ubuntu 7.10 LiveCD and when testing it always booted it an (initramfs) prompt--the squashfs was not getting mounted as /. I had to build from within an Ubuntu 7.10 chroot to get it to work. --Bob/Paul


I have created an small Customization Example (named Firebird Live CD) by adding an firebird-super-server and flamerobin packages (this apply to ubuntu dapper drake) http://flamerobin.blogspot.com/2006/05/creating-flamerobinfirebird-live-cd.html I created an updated guide with Ubuntu Festy Fawn also with an iso download for the Firebird/Flamerobin live cd http://flamerobin.blogspot.com/2007/09/creating-flamerobinfirebird-livecd-with.html


I have created tool for automatic remastering of live CD images. See http://uck.sourceforge.net/ . Features:

  • GUI for simple creation of localized CDs (including changing gfxboot and installing language packs)
  • Script for customization of ISO, SquashFS and initrd on live CD.

http://www.atworkonline.it/~bibe/ubuntu/custom-livecd.htm seems to have some nice info. no license that I can see so we would need to ask permission from the author to us its material.


If you want to make the CD boot faster, you might try sorting the files so that they are in the CD in the order that they are accessed: http://lichota.net/%7Ekrzysiek/projects/kubuntu/dapper-livecd-optimization/


Great How To. I am having one issue however. I would like to use custom xorg.conf and sources.list files. Any tips on doing this? Thanks.

  • Simply, copy the files to edit/etc/ in the same way (and at the same time) that you copy in the resolv.conf and hosts files.
  • I have found that copying xorg.conf doesn't work, as the boot-time scripts overwrite it. Besides, you can't guarantee that a particular xorg.conf will run on all hosts. I'm currently trying to get the binary NVIDIA drivers to work out of the box if an NVIDIA card is present. If I figure out how to fix the xorg.conf, I'll post it here. --JeremyVisser

I've managed to get Synaptic running from within the chroot environment, but it does hang when I try to apply packages. What you do is run "Xnest -ac :1" to get an Xnest server to run on display :1 without access control so anyone can connect to it. Then, in the chroot environment, run "export DISPLAY=:1" to get programs to use the display. Then, type "metacity &" to be able to move windows. Finally, run "synaptic". It works fine until you try to apply packages, where it hangs for me. --JeremyVisser


Shouldn't the mkinitramfs command use the casper scripts, like "mkinitramfs -o initrd.gz 2.6.15-23-386 -d /usr/share/initramfs-tools"?


There are tricks on how you can get to feel the GNOME system in your chroot environment. 1. Copy your xorg.conf in the chrooted "etc/X11/" directory.

cp /etc/X11/xorg.conf edit/etc/X11/

2. Create generic devices on your chroot system using MAKEDEV

cd /dev/
MAKEDEV generic

3. Start X or restart gdm

/etc/init.d/gdm start

Supposed you want to make modifications on the Desktop, that will be used by all the new users, just change your $HOME to /etc/skel/ and start gdm or X.

export HOME=/etc/skel/

If you want to load all the other stuff GNOME needs (i.e, dbus, avahi, network-manager), just boot as (single-user mode), and start dbus in your chrooted environment.

/etc/init.d/dbus start

An example of the whole procedure. (under single-user mode)

sudo /etc/init.d/networking restart
sudo cp /etc/resolv.conf edit/etc/
sudo cp /etc/X11/xorg.conf edit/etc/X11/
sudo chroot edit
mount -o none /proc
mount -o none /sys
export HOME=/etc/skel/
cd /dev/
MAKEDEV generic
/etc/init.d/dbus start
/etc/init.d/gdm start

--- joelbryan


Hello, I am about to build a new Livecd and have a question: When I change the username, hostname and the user's password the user login automatically during booting the livesystem. But this is not desired. Is it correct, that I have to enter a password under a Desktop LiveCD when I delet the encrypted password in /usr/share/initramfs-tools/scripts/casper-bottom/10adduser ? Thanks Changing username and password will not change login behaviour, because this is done in /usr/share/initramfs-tools/scripts/casper-bottom/15autologin --- Alexander Hosfeld


Having trouble starting a MySQL server from within the chroot jail. Any suggestions? - Dave Hey, I am trying to make a customized live cd of Kubuntu 6.06 that will be completly preconfigured, so that when the user clicks on the install icon on KDE the installer should do everything by itself, meaning that the installer should not ask any questions to the user. To do this I am trying to write a preseed file to tell the installer the information that it needs. The problem is that even with this preseed file I could only tell the installer what is the username that it should use, the rest of the information is simply ignored by the installer. I must be doing something wrong and would appreciate any and all help given me. Thanks, Komyg PS: Should I post my preseed file here?


If the livecd is not going to be used for the purposes of installing what files can be removed? Can the "pool" files containing the .debs be removed too? - Mike


If I want to put in my LiveCD applications that aren't in the sources.list (like ooffice 2.2 or perl audio converter), what cain I do? - Isoldanne When you're in the chroot you can install applications just like you would on a live system. If you install from source you can feel free to delete the source tarbal and make folders after you do 'make install'. - Bob/Paul


To get desired /etc/X11/xorg.conf one can modify the /usr/bin/dexconf. This script generates xorg.conf automatically in liveCD session according to the booted machine. For example:

# diff ~/bin/dexconf /usr/bin/dexconf
268,269c268
< 	Option		"XkbLayout"	"us,il"
< 	Option          "XkbOptions" "grp:alt_shift_toggle,grp_led:scroll"
---
> 	Option		"XkbLayout"	"$XKB_LAYOUT"

-- yotam


I cant do chroot. When i run it a get this error chroot: cannot run command `/bin/bash': No such file or directory Please help me out I had the same problem because the filesystem that I was working on was FAT32 instead of EXT2 or EXT3. Because of that, /bin/bash was not an executable I guess. If that is your case also, then please try again on a partition that is EXT2 or EXT3 (the Linux type of partition). Good luck, --vvim


Hi, I've created a simple script to ease remastering the Kubuntu Live CD. It uses aufs to avoid copying all the files back and forth. Maybe it will be usefull to others too. The script must be run as root.

#!/bin/bash
CD="${1:-kubuntu-8.10-desktop-i386.iso}" ; shift
# exit after any error:
set -e

which mkisofs mksquashfs tempfile sed

WDIR=`mktemp -d $PWD/kubuntu-remastered.XXXXXXXXXX`
ISO="$WDIR/${CD##*/}"
ISO="${ISO%.iso}-remastered-KDM.iso"
EXIT=""
function addExit {
    EXIT="$@ ; $EXIT"
    trap "$EXIT" EXIT HUP TERM INT QUIT
}
function mnt {
    local margs="$1" ; shift
    local mp="$WDIR/$1"
    for D in "$@" ; do
	mkdir -v -p "$WDIR/$D"
    done
    mount -v $margs "$mp"
    addExit "umount -v $mp"
}

# mount the CD image
mnt "-t auto $CD -o loop,ro" cd

# mount compressed filesystem
mnt "-t squashfs $WDIR/cd/casper/filesystem.squashfs -o ro,loop" sq

# create joined writable filesystem for the new CD
mnt "-t aufs -o br:$WDIR/cd-w=rw:$WDIR/cd=ro none" cd-u cd-w

# create joined writable filesystem for the new compressed squashfs filesystem
mnt "-t aufs -o br:$WDIR/sq-w=rw:$WDIR/sq=ro none" sq-u sq-w

echo ">>> Updating CD content"

(
    cd sq-u

    # DO YOUR CUSTOMIZATION STUFF HERE, CHROOT, MODIFY FILES, ETC.
    # ...
    # ...

)

echo ">>> Compressing filesystem"
mksquashfs $WDIR/sq-u/ $WDIR/cd-u/casper/filesystem.squashfs -noappend

echo ">>> Recomputing MD5 sums"
( cd $WDIR/cd-u && find . -type f -not -name md5sum.txt -not -path '*/isolinux/*' -print0 | xargs -0 -- md5sum > md5sum.txt )

echo ">>> Creating ISO image $ISO"
mkisofs \
    -V "Custom KUbuntu Live CD" \
    -r -cache-inodes -J -l \
    -b isolinux/isolinux.bin \
    -c isolinux/boot.cat \
    -no-emul-boot -boot-load-size 4 -boot-info-table \
    -o "$ISO" \
    $WDIR/cd-u

# The trap ... callbacks will unmount everything.

--- Petr Pudlak


I need to know how to configure the live cd so that it does not use SWAP! Please help me! -- iceman


Hi, I've been experiencing problems with aptitude and I'm pretty sure its because I'm doing all this stuff on NTFS partition (according to this thread http://ubuntuforums.org/showthread.php?t=521905). But I have no other choice,coz' I've got less then 1,7GB on my ext3 partition. Any suggestion ? THX Error messages I've been getting, when trying to install or update aptitude: "E: Couldn't make mmap of 25165824 bytes - mmap (19 No such device) W: Unable to munmap E: The package lists or status file could not be parsed or opened." -heethen (heethen at centrum dot cz)


I would suggest creating an ext3 filesystem within your NTFS partition. To create the file, type dd if=/dev/zero of=/mnt/hda1/workspace.img bs=1024 count=$((1024*1024*15)) Where I assumed your NTFS partition was on hda1, and you wanted to call the new filesystem workspace.img (it's really just a file within NTFS), and that you wanted 15Gb of room to work. (You don't need that much, but with 15Gb you should have plenty of room.) Then you format the new filesystem with the command sudo /sbin/mkfs.ext3 /mnt/hda1/workspace.img then create a mountpoint sudo mkdir /mnt/workspace then mount the new filesystem sudo mount -o loop /mnt/hda1/workspace.img /mnt/workspace You can then use as much space on the NTFS partition as you want, and have all the benefits of ext3 (like getting the *** thing to work). --Tom


Editing gconf by setting each value separately takes too much time. There is a better way: Make a test user and adjust the settings as you wish. Run

gconftool-2 --dump /the/settings/branch/you/need > ~/live/your-new-settings.xml
sudo chown root:root ~/live/your-new-settings.xml
sudo mv ~/live/your-new-settings.xml ~/live/edit/your-new-settings.xml

and then, in the chroot environment, run

gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --load /your-new-settings.xml
rm /your-new-settings.xml

This way you can import the whole branch, e.g. /apps/panel - all settings for Gnome's panels. ---Jacob Popov ubuntu-8.10-desktop-i386.iso


Is there no way to copy the user's gconf-values to the default gconf-values in the chrooted environment? This would be a lot easier than writing commands.


It took me a long time to find the details for configuring a static IP on the live CD without doing it in the root file system. This enables you to create a few boot options with different static details and a DHCP on but all from the same rootfs. There is a casper parameter which is in the form: ip=IFACE,ADDRESS,NETMASK,GATEWAYUbuntuHelp:IFACE,ADDRESS,NETMASK,GATEWAY* --silid



http://ubuntuforums.org/showthread.php?t=839670 I think I have discovered how to do this: 1) Edit accordingly /usr/share/initramfs-tools/scripts/casper-bottom/23networking 2) Run update-initramfs -u -k $version - Robert In order to get the livecd to boot from a static address found in the /etc/network/interfaces file. I edit the /etc/network/interfaces file and add a static address for the interface eth0.

auto eth0
iface eth0 inet static
address 10.xxx.xxx.xxx
netmask 255.255.255.0
gateway 10.xxx.xxx.1

edit somepath/isolinux/text.cfg add ip=frommedia after splash

label live
  menu label ^Try Ubuntu without any change to your computer
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.gz quiet splash ip=frommedia --

This was a little hard to find. Thanks Robert Nicholas A. Schembi Pittsburgh PA USA


I've tried installing adobe flash player but while it installs fine on chroot, and then shows as installed when booting from CD. Firefox thinks it is not installed and I need to install it manually. Anybody come upon a similar problem