From: Michael Tremer Date: Fri, 24 Sep 2010 21:53:04 +0000 (+0200) Subject: naoki: Change LiveCD to dm-squash (was aufs). X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3c7b47cf428a1a21a05cfb4df35aea24c2f1340;p=ipfire-3.x.git naoki: Change LiveCD to dm-squash (was aufs). --- diff --git a/naoki/generators.py b/naoki/generators.py index d6c73825d..b3f2f0160 100644 --- a/naoki/generators.py +++ b/naoki/generators.py @@ -27,8 +27,12 @@ class Generator(_Environment): deps = [ "basesystem", "dracut", + "e2fsprogs", + "kernel", "squashfs-tools", "syslinux", + "util-linux-ng", + "/sbin/dmsetup", "/usr/bin/mkisofs", ] for dep in deps: diff --git a/src/bootloader/installer.conf b/src/bootloader/installer.conf index 4e1ac98ae..bfb6735bf 100644 --- a/src/bootloader/installer.conf +++ b/src/bootloader/installer.conf @@ -22,12 +22,12 @@ MENU hiddenrow 5 LABEL install MENU label ^Install a new @NAME@ system MENU default - KERNEL vmlinuz - APPEND initrd=initrd root=CDLABEL=@NAME@_@VERSION@ rootfstype=iso9660 mode=install quiet ro + KERNEL vmlinuz0 + APPEND initrd=initrd0 root=live:CDLABEL=@NAME@_@VERSION@ rootfstype=auto liveimg mode=install quiet label rescue MENU label ^Rescue installed @NAME@ system - KERNEL vmlinuz - APPEND initrd=initrd root=CDLABEL=@NAME@_@VERSION@ rootfstype=iso9660 mode=rescue quiet ro + KERNEL vmlinuz0 + APPEND initrd=initrd0 root=live:CDLABEL=@NAME@_@VERSION@ rootfstype=auto liveimg mode=rescue quiet label local MENU label Boot from ^local drive LOCALBOOT 0xffff diff --git a/tools/generator b/tools/generator index 7f673ff67..bb2b289c2 100755 --- a/tools/generator +++ b/tools/generator @@ -1,8 +1,12 @@ -#!/bin/bash +#!/bin/bash -x BOOTLOADER_DIR=/usr/src/src/bootloader IMAGES_DIR=/usr/src/images +# Size of the ext filesystem in gigabytes +FSSIZE=2 +FSTYPE=ext4 + ISO_FILENAME=${DISTRO_SNAME}-${DISTRO_VERSION}-${TARGET}.iso . $(dirname ${0})/common-functions @@ -19,10 +23,143 @@ function find_latest_kernel_release() { KERNEL_RELEASE=$(find_latest_kernel_release) function installer_image() { + local target=${1} + local dir=${2} + + # Create target directory if not existant + mkdir -p ${target} 2>/dev/null + + # Create installer images: + # (1) osmin.img (minimal cow image) + # (2) squashfs.img (installer) + + local i + for i in dev proc sys; do + mkdir -p ${dir}/${i} 2>/dev/null + done + + cp -vfr /usr/src/src/install/* ${dir} + + _installer_image_ext3fs \ + ${target}/$(basename ${target})/ext3fs.img /installer + _installer_image_osmin \ + ${target}/osmin.img \ + ${target}/$(basename ${target})/ext3fs.img + + cd ${target} + mksquashfs * ${target}/squashfs.img -no-progress + rm -fr $(basename ${target}) +} + +function _installer_image_osmin() { + local file=${1} + local image=${2} + + local tmp=$(mktemp -d) + + local image_loop=$(losetup -f) + + # Setting up loop for image + losetup ${image_loop} ${image} + + # Setting up loop for an empty 64byte sparse file + sparse=${tmp}/osmin + sparse_loop=$(losetup -f) + + dd if=/dev/zero of=${sparse} bs=1 count=0 seek=64M + losetup ${sparse_loop} ${sparse} + + # Create a DM snapshot device... + local name="imgcreate-$$" + local size=$(stat --format="%s" ${image}) + size=$(( ${size} / 512 )) + + dmsetup create ${name} \ + --table "0 ${size} snapshot ${image_loop} ${sparse_loop} p 8" + + # ...and resize it to its minimal size + _ext3fs_resize /dev/mapper/${name} + + # Get size of the bytes used by the cow image + local cow_size=( $(dmsetup status | grep "^${name}") ) + cow_size=${cow_size[4]} + cow_size=$(awk -F"/" '{ print $1 }' <<<${cow_size}) + + sleep 2 + dmsetup remove ${name} + + # ... and truncate it to its minimal size + truncate -s ${cow_size} ${sparse} + + losetup -d ${sparse_loop} + losetup -d ${image_loop} + + rm -f ${file} + ( cd ${tmp} && \ + mksquashfs * ${file} -no-progress ) +} + +function _ext3fs_blocks() { + local device=${1} + + dumpe2fs -h ${device} 2>/dev/null | \ + grep "Block count" | awk '{ print $NF }' +} + +function _ext3fs_bytes() { + echo $(( $(_ext3fs_blocks $@) * 512 )) +} + +function _ext3fs_resize() { + local device=${1} + local size=${2} + + [ -z "${size}" ] && size="-M" + + e2fsck -f -y ${device} + resize2fs ${device} ${size} +} + +function _installer_image_ext3fs() { local file=${1} local dir=${2} - cd ${dir} && mksquashfs * ${file} -no-progress -e boot + local zero=$(mktemp) + + mkdir -p $(dirname ${file}) 2>/dev/null + + # Create a zeroed file + dd if=/dev/zero of=${file} bs=1 count=0 seek=${FSSIZE}G + + # Create a temporary directory + # and get a free loop device + local tmp_dir=$(mktemp -d) + local loop=$(losetup -f) + + # Set up the loop device + losetup ${loop} ${file} + + # Create filesystem + mkfs.${FSTYPE} \ + -L "$(basename ${file})" \ + -m 1 \ + ${loop} + + # Tune the FS + tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${loop} + + # Mount and copy all files to the FS + mount ${loop} ${tmp_dir} + cp -frp ${dir}/* ${tmp_dir} + umount ${tmp_dir} + + # Shrink FS to minimal size + _ext3fs_resize ${loop} + truncate -s $(_ext3fs_blocks ${loop}) ${loop} + + losetup -d ${loop} + + rm -rf ${tmp_dir} } function install_config() { @@ -60,9 +197,11 @@ function install_kernel() { mkdir -p ${dest} 2>/dev/null local file - for file in vmlinuz initrd; do - cp -f /boot/${file}-${KERNEL_RELEASE}* ${dest}/${file} + for file in vmlinuz; do + cp -f /boot/${file}-${KERNEL_RELEASE}* ${dest}/${file}0 done + + dracut -f ${dest}/initrd0 ${KERNEL_RELEASE} } case "${1}" in @@ -73,7 +212,7 @@ case "${1}" in ISO_FILE=$(mktemp) # Copy installer image to ISO - installer_image ${ISO_DIR}/installer.sfs /installer + installer_image ${ISO_DIR}/LiveOS /installer # Install bootloader install_isolinux ${ISO_DIR}/isolinux