免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1568 | 回复: 0
打印 上一主题 下一主题

Ubuntu Live CD Customization From The Scratch [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-10 23:55 |只看该作者 |倒序浏览

This procedure works and can create a bootable Ubuntu
LiveCd
(along with the
automatic hardware detection and configuration) from scratch. You do not need to
start from a pre-existing
LiveCd
.
You may wish to create an Ubuntu Remix and distribute it as a
LiveCd. Here is a way to do that without having to start from an existing Ubuntu
Desktop Cd.

Overview

There are three different areas to think about; the host
system, the disk image and the chroot.

The Host System

This refers to the Ubuntu desktop you are running, the one the
customised LiveCd is being built on. You will need to install the syslinux,
squashfs-tools and mkisofs packages to be able to build the LiveCd Remix using
the current system.

The Disk Image

The disk image is a folder that we will burn to Cd. Just create
a new folder to be the Disk-Image-Folder. The isolinux bootloader binary (taken
from the syslinux package) needs to be copied onto the disk image so it will go
into the disk image folder for now. The isolinux configuration file, which will
allow the Cd to show a boot-menu at boot time, needs to be copied into there
too. You will also copy the kernel from the chroot onto the disk image
(folder).
The disk image will be created in the host environment, outside
of the chroot.

The ChRoot Environment

This is the system that will eventually run from the disk. It
does not need a kernel, nor a boot-loader unless you are planning on installing
it back onto a hard disk (using Ubiquity). The Casper package needs to be
installed into the chroot. Casper is what allows the Live System to perform
hardware autoconfiguration and run from a live environment. Installing the
Casper package will update the kernel's initrd to perform these tasks. The
kernel that is installed into the chroot will be copied out from the chroot and
put into the disk image.
The chroot will end up inside the disk image in the form of a
squashed (compressed) file. For right now, it will be just another folder on
your host system.
The basic steps are to
  • Create a chroot and install your packages there.
  • Compress the chroot system into a file.
  • Create and configure the disk image which will have the bootloader
    (isolinux), the kernel, the compressed file-system image and some other stuff.
  • Burn the Cd and test it out.

    Make the ChRoot Environment

    From a
    command-line

    install

    debootstrap on the host system. Then make a new folder "work" and inside that
    make another directory "chroot". Then run debootstrap
    Note: The version of Debootstrap for a release of ubuntu does
    not contain the files to bootstrap the next Ubuntu release. For example, you
    cannot bootstrap Karmic on an Intrepid system without intalling Karmic's
    debootstrap package. Find the version of debootstrap you need
    here

    and install it using dpkg. The debootstrap package doesn't depend on any other
    packages and so installing it "by hand" will not cause any problems on your
    system.

    sudo apt-get install debootstrap
    #alternatively, download the package and run sudo dpkg -i debootstrap_1.0.20_all.deb
    mkdir -p work/chroot
    cd work
    sudo debootstrap --arch=i386 karmic chroot

    Note that in the last line "karmic" may need to be replaced
    with your host system; "hardy", "jaunty", "gutsy" or whatever. Those 4 lines
    should create a directory with a chroot directory within it - then installs a
    bare ubuntu system in there. It is important to install custom applications such
    as MySQL after linux-generic is installed because such applications require
    kernel modules for post-install configurations.

    sudo cp /etc/resolv.conf chroot/etc/resolv.conf
    sudo cp /etc/apt/sources.list chroot/etc/apt/sources.list

    You may edit the sources.list in the chroot to add a line from
    a PPA, if you need. You will need to add the PPA's key to your chroot's package
    manager. On the PPA's overview page you'll see the PPA's OpenPGP key id. It'll
    look something like this: 1024/12345678. Copy it, or make a note of, the portion
    after the slash, e.g: 12345678. This key will be added once we enter the
    chroot.

    sudo chroot chroot
    mount -t proc none /proc
    mount -t sysfs none /sys
    mount -t devpts none /dev/pts
    export HOME=/root
    export LC_ALL=C
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 12345678  #Substitute "12345678" with the PPA's OpenPGP ID.
    apt-get update

    There is a current (Karmic, 9.10) issue with services running
    in a chroot:
    https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/430224
    A workaround is to link /sbin/initctl to /bin/true

    dpkg-divert --local --rename --add /sbin/initctl
    ln -s /bin/true /sbin/initctl

    Install packages needed for Live System:
    apt-get install --yes ubuntu-standard casper lupin-casper
    apt-get install --yes discover1 laptop-detect os-prober
    apt-get install --yes linux-generic

    Jaunty Jackalope (9.04) seems to hang on the configuration of
    the network interfaces unless network-manager is installed. This is no longer a
    problem in Karmic 9.10.

    apt-get install --no-install-recommends network-manager

    Next, you may install more packages as you like, assuming you
    have the legal rights to redistribute the packages. This is where you build your
    custom system using packages from the Ubuntu archives.

    Graphical installer, optional
    step

    The customised system can be set-up to allow it to be installed
    onto machines rather than only ever being a
    LiveCd
    . Simply install the
    Ubiquity packages and an appropriate desktop environment with a window manager.
    This step is optional and only needed if you want to allow your customised
    Ubuntu system to be installed on other computers.

    For the Gtk front-end - Gnome
    & Xfce


    apt-get install ubiquity-frontend-gtk


    For the Qt front-end - KDE


    apt-get install ubiquity-frontend-kde

    Before exiting the chroot, remove the diversion:

    rm /sbin/initctl
    dpkg-divert --rename --remove /sbin/initctl

    Then just clean up.

    apt-get clean
    rm -rf /tmp/*
    rm /etc/resolv.conf
    umount -lf /proc
    umount -lf /sys
    umount -lf /dev/pts
    exit

    So far, you have entered the chroot and installed packages,
    then cleaned up and left.

    Create the Cd Image
    Directory and Populate it

    There are 4 packages that need to be installed on the Host
    System which provide the tools to make the Cd image. Syslinux contains
    isolinux which makes the Cd bootable. Squashfs-tools will compress the image.
    SBM is a tool which is useful to have on the Cd if you cannot get it to boot.
    Genisoimage provides mkisofs tool to turn a directory into a CD image. So
    install

    syslinux, squashfs-tools, mkisofs and sbm.
    sudo apt-get install syslinux squashfs-tools genisoimage sbm

    This next command makes the image directory and the 3 required
    subdirectories.
    mkdir -p image/{casper,isolinux,install}
    # Same as 'mkdir image image/casper image/isolinux image/install'

    You will need a kernel and an initrd that was built with the
    Casper scripts. Grab them from your chroot. Use the current version. Note that
    as of 9.10, the initrd is in lz not gz format... This may cause problems with
    GRUB2.
    cp chroot/boot/vmlinuz-2.6.**-**-generic image/casper/vmlinuz
    cp chroot/boot/initrd.img-2.6.**-**-generic image/casper/initrd.gz

    You need the isolinux binary and the sbm binary.

    cp /usr/lib/syslinux/isolinux.bin image/isolinux/
    cp /boot/memtest86+.bin image/install/memtest
    cp /boot/sbm.img image/install/


    Boot Instructions for the Remix
    User

    To give some boot-time instructions to the user create an
    isolinux.txt file in image/isolinux, for example:
    splash.rle
    ************************************************************************
    This is an Ubuntu Remix Live CD.
    For the default live system, enter "live".  To run memtest86+, enter "memtest"
    ************************************************************************


    Splash Screen

    A graphic can be displayed at boot time, but it is optional.
    The example text above contains a special character along with the file name of
    the splash image (splash.rle). To create that character, do one of the
    following:
    A. Cut and copy the text above and use any text editor to
    modify the text.
    or
    B. Use the following command
    printf "\x18" >emptyfile

    and then edit the emptyfile with any text editor. Add the file
    name just next to the first character and add the text you want to display at
    boot time beneath it and save the file as "isolinux.txt"
    or
    C. Use vi to edit a text file and press CTRL-V and then CTRL-X
    to create that special character. This doesn't work for other text editors such
    as nano or gedit.
    To create the splash.rle file, create an image 480 pixels wide.
    Convert it to 15 colours, indexed (perhaps using TheGIMP) and "Save As" to
    change the ending to .bmp which converts the image to a bitmap format. Then
    install
    the
    "netpbm" package and run
    bmptoppm splash.bmp > splash.ppm
    ppmtolss16 '#ffffff=7'  splash.rle

    If you want to use an animated splash screen such as
    USplash
    or
    for a higher resolution console mode please make sure you add 'vga=rrr' after
    the keyword splash in the append line in the configuration
    file (see item below). Replace the rrr with the console resolution
    value.

    Boot-loader Configuration

    Create an isolinux.cfg file in image/isolinux/ to provide
    configuration settings for the boot-loader. Please read
    syslinux.doc
    which should be on the host machine in
    /usr/share/doc/syslinux to find out about the configuration options available on
    the current set-up. Here is an example of what could be in the file:
    DEFAULT live
    LABEL live
      menu label ^Start or install Ubuntu
      kernel /casper/vmlinuz
      append  file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.gz quiet splash --
    LABEL check
      menu label ^Check CD for defects
      kernel /casper/vmlinuz
      append  boot=casper integrity-check initrd=/casper/initrd.gz quiet splash --
    LABEL memtest
      menu label ^Memory test
      kernel /install/memtest
      append -
    LABEL hd
      menu label ^Boot from first hard disk
      localboot 0x80
      append -
    DISPLAY isolinux.txt
    TIMEOUT 300
    PROMPT 1
    #prompt flag_val
    #
    # If flag_val is 0, display the "boot:" prompt
    # only if the Shift or Alt key is pressed,
    # or Caps Lock or Scroll lock is set (this is the default).
    # If  flag_val is 1, always display the "boot:" prompt.
    #  http://linux.die.net/man/1/syslinux   syslinux manpage

    Don't forget to pick the correct extension for your initrd
    (initrd.gz or initrd.lz). Now the Cd should be able to boot, at least it will be
    after the image is burned


    Create manifest:


    sudo chroot chroot dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee image/casper/filesystem.manifest
    sudo cp -v image/casper/filesystem.manifest image/casper/filesystem.manifest-desktop
    REMOVE='ubiquity casper live-initramfs user-setup discover1 xresprobe os-prober libdebian-installer4'
    for i in $REMOVE
    do
            sudo sed -i "/${i}/d" image/casper/filesystem.manifest-desktop
    done


    Compress the chroot

    If this Customised Remix is to potentially be installed on some
    systems then the /boot folder will be needed. To allow the Customised Cd to be
    an installer Cd, compress the entire chroot folder with this command:
    sudo mksquashfs chroot image/casper/filesystem.squashfs

    However, if it is not going to be installed and is 'only' meant
    as a
    LiveCd
    then the
    /boot folder can be excluded to save space on your iso image. The live system
    boots from outside the chroot and so the /boot folder is not used.
    sudo mksquashfs chroot image/casper/filesystem.squashfs -e boot

    It is important to note that if you are building a Karmic
    LiveCd
    on an earlier system,
    you will need the squashfs-tools package
    from Karmic or the
    LiveCd
    will not boot.

    Create diskdefines


    nano image/README.diskdefines

    example:
    #define DISKNAME  Ubuntu 9.10 "Karmic Koala" - Release i386 **Remix**
    #define TYPE  binary
    #define TYPEbinary  1
    #define ARCH  i386
    #define ARCHi386  1
    #define DISKNUM  1
    #define DISKNUM1  1
    #define TOTALNUM  0
    #define TOTALNUM0  1


    Recognition as an Ubuntu Remix

    Create an empty file named "ubuntu" and a hidden ".disk"
    folder. This is needed to make the USB Creator work with this custom iso image.
    Without this the image will still boot but the USB creator will not recognize
    the image as an Ubuntu Cd and refuse to use it. Also, create the following files
    with the pertinent information:
    touch image/ubuntu
    mkdir image/.disk
    cd image/.disk
    touch base_installable
    echo "full_cd/single" > cd_type
    echo 'Ubuntu 9.10 "Karmic Koala Remix" - i386 (20090429)' > info
    echo "http//ubuntu-rescue-remix.org" > release_notes_url
    cd ../..


    Calculate MD5


    sudo -s
    (cd image && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)
    exit

    This calculates the md5sum of everything in the image folder,
    except the file named md5sum.txt.

    Create ISO Image for a LiveCd

    Create iso from the image directory using the command-line
    cd image
    sudo mkisofs -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-remix.iso .
    cd ..

    The boot.cat file will be automatically created. You may test
    your image through virtualbox-ose instead of rebooting your real system if you
    wish.

    Make a bootable Usb image

    The USB-Creator works properly with the iso image that has been
    created so long as the hidden ".disk" folder and its contents are present. If
    you prefer to do it "by hand", you can put your live system onto a USB drive
    yourself. Follow these six steps to do so. You can use these steps to put an
    existing
    LiveCd
    onto a
    Usb bootable device.

    FAT16 file-system (Windows)

    1. Prepare your work area:
    mkdir ../liveusb ../liveusb/mnt
    cd ../liveusb
    touch loop

    2. Create a loop device with a fat16 file-system. Use whatever
    size you need to fit your image; in this case it's a 200Mb sparse file. A sparse
    file is a file that is bigger than the actual number of bytes it takes up on the
    disk.
    dd if=/dev/zero of=loop bs=1 count=1 seek=200M
    mkdosfs -F 16 -n rescue loop

    3. Two options here;
    3a Mount the Cd-Rom iso image and your new file-system:
    mkdir tmp
    sudo mount -o loop ../rescue-remix-804Alpha.iso tmp
    sudo mount -o loop loop mnt

    3b Just use the "image" folder instead of mounting the iso
    image. This is useful if you don't want to make anything other than a Usb image
    from scratch (You don't have to make a Cd iso image if you don't need it)
    ln -s ../image tmp
    sudo mount -o loop loop mnt

    4. Copy the files
    sudo cp -a tmp/* mnt/

    5. Change the location of the boot-loader and its configuration
    file and make it bootable (For fat16 file-system (default))
    cd mnt
    sudo mv isolinux/* .
    sudo rmdir isolinux/
    sudo mv isolinux.bin syslinux.bin
    sudo mv isolinux.cfg syslinux.cfg
    cd ..
    sudo umount mnt
    sudo umount tmp
    syslinux loop

    6. Pack it up
    gzip -c loop > remixusb.gz

    To install onto a usb drive. Insert the drive and identify it's
    mount-point, for example /dev/sdc. Ensure that the device has a partition table
    on it and run
    zcat remixusb.gz | sudo tee /dev/sdc1 >/dev/null


    Ext2 file-system (proper Linux)

    An ext2 file-system is useful in that it can hold larger files
    and the boot-loader can support relative symlinks. Follow the same steps as
    above, but substitute the instructions in steps 2 & 5
    2. Create an ext2 file-system instead of FAT16, obviously.
    dd if=/dev/zero of=loop bs=1 count=1 seek=200M
    mkfs.ext2 -L rescue -m 0 loop

    5. It needs to be made bootable *before* unmounting.
    cd mnt
    sudo mkdir boot
    sudo mv isolinux boot/extlinux
    sudo mv boot/extlinux/isolinux.cfg boot/extlinux/extlinux.conf
    sudo extlinux --install boot/extlinux/
    cd ..
    sudo umount mnt
    sudo umount tmp


    Partitioning your Usb device

    A persistent home can be included within a file instead of a
    partition. If you want to use a whole partition, do the following.
    The Usb image can be installed to any
    partition
    on the
    device. Just make sure that partition is the only one that is marked as
    bootable. You can partition your Usb storage device to contain the
    LiveUsb

    image as well as a storage partition. You can use the storage partition to:
    - keep a small amount of recovered files.
    - create a persistent home.
    - or you can use it as swap space.
    To partition your device, see
    HowtoPartition
    .
    If the storage partition is located after the LiveUsb image
    partition then Windows wont be able to see it. This is not a problem since you
    can create the storage partition first and put the live image at the end of the
    drive. Just make the LiveUsb image partition the only partition flagged as
    bootable.
    When the drive boots the bootable partition will be used and
    you are good to go. The
    LiveUsb
    image's partition
    won't be seen by Windows.

    Troubleshooting

    If the device does not boot, you may need to install an MBR
    onto the device.
    sudo apt-get install mbr
    sudo install-mbr /dev/sdc

    and try again.

    Persistent Data

    Create an ext2, ext3 or ext4 partition named "casper-rw" as a
    separate partition and append the word "persistent" to your "append" line
    configuration and all your session data will be stored there. You will be able
    to keep your changes between boots.
    LABEL live
      menu label ^Start or install Ubuntu
      kernel /casper/vmlinuz
      append  file=/cdrom/preseed/ubuntu.seed boot=casper persistent initrd=/casper/initrd.gz quiet splash --
                   
                   
                   
                   

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8059/showart_2145132.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP