[gl-como] Customizzare Ubuntu/Kubuntu

fabio fabio@gl-como.net
Ven 8 Set 2006 14:29:05 CEST


 

Ecco due guide per la customizzazione di UBUNTU DAPPER e inoltre vi segnalo 
che e' ottimo il tool di balliano  Ubuntu Customization Kit ...
cercatelo su sourceforge e installate il pacchetto!! 


 ----- PRIMA GUIDA ---------- 

Customizing a (K)Ubuntu 6.04 Linux Live CD
This tutorial reflects a work I had to do in the last days: I had to build a 
modified Kubuntu live CD, using the latest "Kubuntu 6.04 Flight3" (to use a 
2.6.15 kernel). The system had to boot in console mode, defaulting to the 
Italian "Standard" keyboard layout, running an SSH server and having 
partimage (client and server).
I started this work using this tutorial by Prof. Dr. Reinhard Schiedermeier, 
who modified an older version of Ubuntu: the main difference was the use of 
cloop filesystem, instead of the squashfs used in 6.04 Flight3.
1 Copy the LiveCD
Export a shell variable (say, WORK) pointing to a working directory 
somewhere on your disk (say, ~/mylivecd), so you can use this page as a 
copy-and-paste howto. 

$ export WORK=~/mylivecd
$ mkdir -p $WORK 

Mount a (K)Ubuntu Linux Live CD 

$ mount -t iso9660 /dev/hdc /cdrom 

or the ISO image: 

$ sudo mount -t iso9660 -o loop /path/to/dapper-live-i386.iso /cdrom 

Then copy the content of the disk into a new directory, set the write 
permission on the new directory's content, and unmount the Live CD (or the 
ISO image): 

$ cd $WORK
$ mkdir ubuntu-livecd
$ cp -a /cdrom/. ubuntu-livecd
$ chmod -R u+w ubuntu-livecd
$ sudo umount /cdrom 

The directory contains about 580 MB. You need a copy, because it will be 
modified.
2 Free space (I)
The copy of the Live CD has various subdirectories. I removed one of them, 
containing some Windows applications. 

$ rm -rf $WORK/ubuntu-livecd/programs 

The Live CD works fine without these programs. That saves about 95 MB.
3 Mount the compressed filesystem
The visible content of the Live CD is mainly used for booting. (K)Ubuntu 
Linux itself is contained in a compressed filesystem image in 
$WORK/ubuntu-livecd/casper/filesystem.squashfs.
To decompress and read this file, you need the squashfs module. I built a 
custom kernel (on Debian) using the kernel-patch-squashfs package, but you 
can easily use any way to get the squashfs module.
Finally loopback mount the compressed filesystem on a new mount point, say 
$WORK/old: 

$ mkdir $WORK/old
$ sudo mount -t squashfs -o loop,ro 
$WORK/ubuntu-livecd/casper/filesystem.squashfs $WORK/old 

Have a look at $WORK/old. You should see the root of the (K)Ubuntu 
filesystem.
4 Create an image for the modified compressed filesystem
This requires abount 2 GB of disk space. Make an empty file of 2 GB size: 

$ sudo dd if=/dev/zero of=$WORK/ubuntu-fs.ext2 bs=1M count=2147 

Format the file with an Ext2 filesystem: 

$ sudo mke2fs $WORK/ubuntu-fs.ext2 

mke2fs will warn you that ubuntu-fs.ext2 a not a real device. This is ok, 
proceed.
Now loopback mount the freshly formatted filesystem on a new mount point, 
say $WORK/new: 

$ mkdir $WORK/new
$ sudo mount -o loop $WORK/ubuntu-fs.ext2 $WORK/new 

5 Copy the compressed filesystem
To modify the (K)Ubuntu filesystem, we need to decompress and copy it: 

$ sudo cp -a $WORK/old/. $WORK/new 

We can umount $WORK/old now, because we have copies of all the data we need: 

$ sudo umount $WORK/old 

6 Chroot and tweak the system
Now it's time to fine-tune the system to your needs, chrooting into the new 
system and using the standard Debian/Ubuntu tools.
First, prepare the /proc filesystem and the /etc/resolv.conf file for the 
copied filesystem and chroot into it: 

$ sudo cp /etc/resolv.conf $WORK/new/etc/
$ sudo mount -t proc -o bind /proc $WORK/new/proc
$ sudo chroot $WORK/new /bin/bash 

Now you are at the root of the (K)Ubuntu filesystem. Tweak the system as you 
like: 

# apt-get remove ttf-baekmuk \
   ttf-kochi-gothic \
   ttf-kochi-mincho
# vi /etc/apt/sources.list # (Enable universe repositories)
# apt-get update
# apt-get install partimage partimage-server ssh
# /etc/init.d/partimaged stop # (Stops extra processes and frees sockets)
# /etc/init.d/ssh stop # (Stops extra processes and frees sockets)
# update-rc.d -f partimaged remove
# update-rc.d -f kdm remove
# apt-get clean
# dpkg-reconfigure console-data # (Select Italian Standard keyboard) 

and leave the (K)Ubuntu filesystem: 

# exit
$ sudo umount $WORK/new/proc
$ sudo rm $WORK/new/etc/resolv.conf 

You are back at your own system.
7 Finish the modified filesystem
First, update the manifest file to reflect the modified packages: 

$ sudo chroot $WORK/new dpkg-query -W --showformat='${Package} ${Version}\n' 
\
   > $WORK/ubuntu-livecd/casper/filesystem.manifest 

Next, clear the free disk space. Even if some Debian packages were removed, 
the unused space on the modified filesystem still holds the content. Fill 
all free space on the modified filesystem with zeroes (this will eventually 
fail with "no space left"), then remove the zero file: 

$ sudo dd if=/dev/zero of=$WORK/new/dummyfile
$ sudo rm $WORK/new/dummyfile 

Now, all unused data blocks are filled with zeroes and compress to almost 
nothing.
8 Build the modified compressed filesystem
Re-generate the modified filesystem: 

$ sudo rm $WORK/ubuntu-livecd/casper/filesystem.squashfs
$ cd $WORK/new
$ sudo mksquashfs . $WORK/ubuntu-livecd/casper/filesystem.squashfs 

This is the most time-consuming step. Umount $WORK/new now, we are done: 

$ cd $WORK
$ sudo umount $WORK/new 

9 Create the new Live-CD
On the Live-CD there is a MD5 hash. Adjust it to the modified content of the 
CD: 

$ cd $WORK/ubuntu-livecd
$ sudo find . -type f -print0 |xargs -0 md5sum |sudo tee md5sum.txt 

Now build the ISO image file, ubuntu-new.iso: 

$ cd $WORK
$ mkisofs \
   -o ubuntu-new.iso \
   -b isolinux/isolinux.bin \
   -c isolinux/boot.cat \
   -no-emul-boot \
   -boot-load-size 4 \
   -boot-info-table \
   -r \
   -V "Custom Ubuntu Live CD" \
   -cache-inodes  \
   -J \
   -l \
   ubuntu-livecd 

Burn ubuntu-new.iso to a disk and you are done! For testing, a virtual PC 
like qemu is great. 


 ------------- SECONDA GUIDA ------------------------ 


UbuntuDapper/Remaster
1. Remastering Ubuntu Dapper Drake 

How do you make a local version of Ubuntu? There are three ways to proceed 

  1. 

     Install the system on a real computer, tinker with it,
         * 

           and then make an image snapshot of the disk.
  2. 

     Remaster the Install CD. This gives the most control,
         * 

           but takes a little more thought and understanding
  3. 

     Remaster the Live CD. Starting with the Dapper Drake,
         * 

           the live system has an installer program, which it is quite easy 
to influence 

For the sake of simplicity, I have experimented with the last of these 
methods, and explain my workings below. 

The Live CD installer works by copying the working system onto the target 
system, with some preparation and cleaning up.
1.1. Preparation 

Get yourself a large amount of disk. You'll need an ext2 partition to work 
in with 2.5 gbytes, space for several copies of the compressed file system 
(another couple of gbytes). You'll also need the squashfs package installed. 

First get a handle on the ISO image: 

mount -o loop dapper.iso /mnt 

now copy all of that to a working location with a 1Gb free. Lets call that 
$CD: 

rsync -ax /mnt/. $CD/ 

Edit $CD/isolinux/isolinux.cfg to add 

preseed/locale=en_GB kbd-chooser/method=gb DEBCONF_PRIORITY=critical 

to get language right and stop it asking too many questions, but thats about 
all that is needed in the main CD directory. You can kill programs and 
disctree to save space if needed. 

Now you can dismount the CD: 

umount /mnt 

Next we need to unpack the real working file system, which is inside a 
compressed filesystem on the CD setup. You can get at it with 

mount $CD/casper/filesystem.squashfs /mnt -t squashfs -o loop 

I find it easiest to copy this to a directory on disk. Make this on an ext2 
partition, however. Lets call that $Source; copy over the contents, and 
unmount the file system: 

rsync -av /mnt/. $Source/.
umount /mnt 

1.2. Setting up the new system 

Now you can start the real work, by doing chroot $Source and adding or 
deleting packages. You'll want to tinker with /etc/apt/sources.list to add 
local repositories, or enable eg Ubuntu multiverse. That's needed for Sun 
Java. 

If you do install Java, you'll need to change the setup to let it prompt you 
for license agreement. This is done with 

dpkg-reconfigure debconf 

and choosing dialog. Now you can get Java with 

apt-get install sun-java5-jdk 

but you'll also probably need to make it the default, with 

update-alternatives  --config java 

My changes are quite complex, as I want to install a web server, Tomcat, an 
XML database and a lot of TEI stuff. This is the script I run: 

echo update repository
apt-get update
dpkg-reconfigure debconf
echo First some adds
apt-get install  \
       openssh-server  \
       abcde   \
       apache2  \
       deborphan  \
       emacs21  \
       gnumeric  \
       libapache2-mod-php5  \
       php5  \
       php5-cli  \
       php5-common   \
       php5-xsl   \
       subversion \
       sun-java5-jdk  \
       tidy  \
       vpnc
update-alternatives  --config java
echo Now some removes
apt-get remove  \
       evolution  \
       evolution-data-server  \
       gnome-games  \
       gnome-games-data  \
       irssi  \
       libgcj7  \
       sun-java5-demo  \
       ttf-arphic-ukai  \
       ttf-arphic-uming  \
       ttf-baekmuk  \
       festival \
       festlex-cmu \
       festlex-poslex \
       festvox-kallpc16k 

echo More adds preparatory to TEI
apt-get install jakarta-tomcat
apt-get install cocoon
apt-get install exist
echo Add TEI packages
apt-get install tei-emacs trang-java saxon xmlstarlet jing
apt-get install \
       tei-oxygen  \
       tei-p4-doc  \
       tei-p4-lite  \
       tei-p4-schema  \
       tei-p4-xsl  \
       tei-p5-doc  \
       tei-p5-exemplars  \
       tei-p5-schema  \
       tei-p5-source  \
       tei-p5-test  \
       tei-p5-xsl  \
       tei-roma  \
       tei-xsl-teic
echo Add TEI packages which need tomcat
mount -t proc none /proc
/etc/init.d/jakarta-tomcat start
apt-get install tei-p5-database
apt-get install tei-teaching
umount /proc
/etc/init.d/jakarta-tomcat stop 

If you do tricksy stuff like starting up Tomcat inside the chrootted system, 
you need to make sure it is closed down in the main system first, and 
properly stopped inside the chrooted system when you are done with your 
work. In the example above, I need to get it running to start up the eXist 
database so that I can add my data. 

Anything you put into /etc/skel gets copied into the new user space. So to 
set up defaults on the desktop, browser bookmarks, etc, boot up with the 
Live CD, and make things just the way you want them. Before you shut down, 
make a copy of the home directory on a USB key or another computer, and use 
that to people /etc/skel in your master system. 

Don't forget to set up a site for the web server, if you have provided that,
1.3. Preparing for the CD 

Finished fooling around? Now you can get out of the chrooted environment and 
make the CD image. 

There are some small but important steps to take first, however. The CD 
wants a list of the packages on your system, which you can get using 
dpkg-query, using this recipe: 

chroot $Source dpkg-query -W --showformat='${Package} ${Version}\n' \
       | grep -v deinstall > $CD/casper/filesystem.manifest 

When the Live installer runs, it copies everything to the target system, but 
then cleans up by removing packages which are not listed in a second 
manifest file. This stops the target system inheriting the installer, for 
example. 

I manage this by filtering the manifest we just created using a sed script: 

cat > /tmp/$$.control <<FOO
/casper/d
/libdebian-installer4/d
/os-prober/d
/ubiquity/d
/ubuntu-live/d
/user-setup/d
FOO
sed -f /tmp/$$.control < $CDROM/casper/filesystem.manifest > 
$CDROM/casper/filesystem.manifest-desktop
rm /tmp/$$.control 

1.4. Influencing the live installer 

When the user runs your remastered CD and does the install, how can you get 
the default choices changed? Surprisingly easily, because the install 
systems for Debian make use of a concept they call 'preseeding', which means 
supplying answers to the questions an install program asks. You can get the 
current answers to questions on a system by doing 

debconf-get-selections 

If you save that to a file, and edit it as needed, you can use the result to 
set up the system you are creating. I keep my answers in a file called 
preseed.cfg and get them on my new system as follows: 

chroot $Source debconf-set-selections <  preseed.cfg 

This preseed file is not trivial to understand. An older manual at [WWW] 
http://archive.ubuntulinux.org/ubuntu/dists/hoary/main/installer-i386/curren 
t/doc/manual/en/apcs01.html should help somewhat, but be prepared to do some 
head-scratching.
1.5. Compresssing the file system 

Time to take that tree in $Source we were working on, and squash it down. 
Easy: 

mksquashfs $Source/ $CD/filesystem.squashed 

This takes 15-20 minutes, so have a cup of tea now. 

Finally, update the md5sums on the CD system: 

(cd $CD && find . -type f -print0 | xargs -0 md5sum > md5sum.txt) 

1.6. Making the CD image 

This should be familar stuff if you are using to making CD images: 

mkisofs    \
 -r    \
 -V "Custom Ubuntu Live CD"    \
 -cache-inodes    \
 -J    \
 -l    \
 -b isolinux/isolinux.bin    \
 -c isolinux/boot.cat    \
 -no-emul-boot    \
 -boot-load-size 4    \
 -boot-info-table    \
 -o /tmp/MyCD.iso "$CD" 

The result in /tmp/MyCD.iso can be burnt to disk and tried. If you have 
VMWare, it is faster to test it up setting up a new VM and making the ISO 
image by the CD drive. 

Obviously, if the image is over 700 Mbytes, you'll need to burn the image to 
a DVD instead of a CD. That should just work, up to 2 gigabytes.


Maggiori informazioni sulla lista gl-como