Prebuilt distributions part 2

In part 1 I discussed how these days Linux Live CDs usually come with a prebuilt disk image of the distro which is simply copied over to the hard disk during installation. (The “old” method was to rpm/dpkg-install the packages which is much more time-consuming). However my first test wasn’t very successful because I was using the “cp” command to copy files.

Anaconda (the Fedora installer) is smarter than this. It “dd”s the prebuilt disk image to the hard disk and then uses an ext2/3/4 utility called resize2fs to expand it to the correct size.

I changed the previous guestfish script to take this approach.

The new/Anaconda approach is much faster. Our total time is down from over 18 minutes to 2½ minutes (approximately 2 minutes for the “dd”, 2 seconds for the resize2fs, and the rest of the time taken doing the partitioning and LVM creation).

Unfortunately we have to leave Ubuntu behind at this point. Ubuntu ships with a squashfs, and I’m not aware of any way to turn this into an ext3 partition efficiently (except to use “cp” which we showed in part 1 was very slow). The new script only works with Fedora Live CD ISOs.

The new script is after the cut.

#!/bin/bash -

function usage ()
{
    echo "virt-prebuilt.sh live.iso disk.img size"
    echo "  where 'live.iso' is a Fedora Live ISO"
    echo "        'disk.img' is the target disk image"
    echo "        'size' is the target size in Gigabytes"
    exit 1
}

if [ $# -ne 3 ]; then
    usage
fi

# Work out size of target LV.
target_boot_mb=200
target_lv_mb=$(($3 * 1024 - $target_boot_mb - 128))

# Run guestfish.
time \
guestfish -x -a "$1" <<EOF
# The source ISO will be /dev/sda.  The target drive will be /dev/sdb.
alloc "$2" "$3G"
run

# Get to the packed ext3 filesystem.
mkmountpoint /t
mount-ro /dev/sda /t
mkmountpoint /tt
mount-loop /t/LiveOS/squashfs.img /tt

# Make a separate /boot partition on the target disk.
sfdiskM /dev/sdb ",$target_boot_mb ,"
mkfs ext3 /dev/sdb1

# Make the root LV.
pvcreate /dev/sdb2
vgcreate vg_live /dev/sdb2
lvcreate lv_live vg_live $target_lv_mb

# Copy the packed filesystem to the root LV and resize.
time dd /tt/LiveOS/ext3fs.img /dev/vg_live/lv_live
time resize2fs /dev/vg_live/lv_live

# Mount the root filesystem and copy /boot to /dev/sdb1
mkmountpoint /root
mount /dev/vg_live/lv_live /root
mkmountpoint /boot
mount /dev/sdb1 /boot
glob cp-a /root/boot/* /boot
df-h

# Unmount everything and exit.
unmount /root
unmount /boot
unmount /tt
unmount /t

echo Done.
EOF

Anaconda doesn’t just do a straight copy, it also does a whole lot of munging of the filesystem afterwards, including replacing /etc/fstab and rebuilding the initramfs. The script above avoids that so you can only boot it in qemu using an external -kernel and -initrd.

I think this technique is promising. It certainly sounds wonderful to “stamp out” new distro installs in a minute or two. But …

  1. Distributions would all have to start shipping filesystem images.
  2. Distro-specific munging would have to be kept to an absolute minimum.
  3. Get rid of initramfs’s that contain hard-coded details about the specific platform on which they boot (a very good idea in general IMHO).

In part 3 I’m going to compare how this approach compares to others: virt-install, manual installation, kickstart, cobbler, debootstrap and ubuntu-vm-builder.

About these ads

1 Comment

Filed under Uncategorized

One response to “Prebuilt distributions part 2

  1. Pingback: Fedora 新闻周刊第 204 期 | Fuzzy! News - Fedora 新闻 | FZUG

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s