[arch-releng] [RFC] [PATCH 1/3] [archiso] Implement own chroot functions in mkarchiso
* Remove devtools dependency. * Better control over what files are touched inside chroot (root-image). Now: NONE :) * Two new commands: + init: To install {base} group and other needed packages (syslinux for now) + run: If we want to run some command inside chroot (mkinitcpio, locale-gen, useradd, etc etc...) * Renamed command: "created" to "install", says much better what does. Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> --- archiso/mkarchiso | 103 +++++++++++++++++++++++++++++++++++++-------- configs/baseline/build.sh | 7 +-- configs/releng/build.sh | 19 ++++++--- 3 files changed, 102 insertions(+), 27 deletions(-) diff --git a/archiso/mkarchiso b/archiso/mkarchiso index b3aa5cd..df3d354 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -5,6 +5,7 @@ set -e -u app_name=${0##*/} arch=$(uname -m) pkg_list="" +run_cmd="" quiet="y" pacman_conf="/etc/pacman.conf" export iso_label="ARCH_$(date +%Y%m)" @@ -44,6 +45,44 @@ _show_space_usage () { _msg_info "Total: ${_total} MiB (100%) | Used: ${_used} MiB (${_pct_u}) | Avail: ${_avail} MiB ($((100 - ${_pct_u%\%}))%)" } +_chroot_mount () { + mount -t devtmpfs dev "${work_dir}/root-image/dev" + mount -t devpts devpts "${work_dir}/root-image/dev/pts" + mount -t tmpfs devshm "${work_dir}/root-image/dev/shm" + mount -t proc proc "${work_dir}/root-image/proc" + mount -t tmpfs run "${work_dir}/root-image/run" + mount -t sysfs sys "${work_dir}/root-image/sys" + mount -t tmpfs tmp "${work_dir}/root-image/tmp" + + trap '_chroot_umount' EXIT HUP INT TERM +} + +_chroot_umount () { + umount "${work_dir}/root-image/tmp" + umount "${work_dir}/root-image/sys" + umount "${work_dir}/root-image/run" + umount "${work_dir}/root-image/proc" + umount "${work_dir}/root-image/dev/shm" + umount "${work_dir}/root-image/dev/pts" + umount "${work_dir}/root-image/dev" + + trap - EXIT HUP INT TERM +} + +_chroot_init() { + if [[ ! -d ${work_dir}/root-image/var/cache/pacman ]]; then + mkdir -p ${work_dir}/root-image/{dev,proc,run,sys,tmp,var/lib/pacman} + _pacman "base" + _pacman "syslinux" + fi +} + +_chroot_run() { + _chroot_mount + eval chroot ${work_dir}/root-image "${run_cmd}" + _chroot_umount +} + # Mount a filesystem (trap signals in case of error for unmounting it # $1: source image # $2: mount-point @@ -99,6 +138,7 @@ _usage () echo "usage ${app_name} [options] command <command options>" echo " general options:" echo " -p PACKAGE(S) Package(s) to install, can be used multiple times" + echo " -r <command> Run <command> inside root-image" echo " -C <file> Config file for pacman. Default ${pacman_conf}" echo " -L <label> Set a label for the disk" echo " -P <publisher> Set a publisher for the disk" @@ -113,9 +153,12 @@ _usage () echo " -v Enable verbose output" echo " -h This message" echo " commands:" - echo " create" - echo " create a base directory layout to work with" - echo " includes all specified packages" + echo " init" + echo " Make base layout and install base group" + echo " install" + echo " Install all specified packages (-p)" + echo " run" + echo " run command specified by -r" echo " prepare" echo " build all images" echo " checksum" @@ -126,7 +169,7 @@ _usage () } # Shows configuration according to command mode. -# $1: create | prepare | iso +# $1: init | install | run | prepare | checksum | iso _show_config () { local _mode="$1" echo @@ -136,10 +179,16 @@ _show_config () { _msg_info " Working directory: ${work_dir}" _msg_info " Installation directory: ${install_dir}" case "${_mode}" in - create) + init) + _msg_info " Pacman config file: ${pacman_conf}" + ;; + install) _msg_info " Pacman config file: ${pacman_conf}" _msg_info " Packages: ${pkg_list}" ;; + run) + _msg_info " Run command: ${run_cmd}" + ;; prepare) ;; checksum) @@ -159,20 +208,23 @@ _pacman () { _msg_info "Installing packages to '${work_dir}/root-image/'..." + _chroot_mount + if [[ "${quiet}" = "y" ]]; then - mkarchroot -n -C "${pacman_conf}" -f "${work_dir}/root-image" $* &> /dev/null + pacman -Sy -r "${work_dir}/root-image" --config "${pacman_conf}" --needed --noconfirm $* &> /dev/null else - mkarchroot -n -C "${pacman_conf}" -f "${work_dir}/root-image" $* + pacman -Sy -r "${work_dir}/root-image" --config "${pacman_conf}" --needed --noconfirm $* fi - # Cleanup - find "${work_dir}" -name "*.pacnew" -name "*.pacsave" -name "*.pacorig" -delete + _chroot_umount + _msg_info "Packages installed successfully!" } # Cleanup root-image _cleanup () { _msg_info "Cleaning up what we can on root-image" + # remove the initcpio images that were generated for the host system if [[ -d "${work_dir}/root-image/boot" ]]; then find "${work_dir}/root-image/boot" -name '*.img' -delete @@ -201,6 +253,8 @@ _cleanup () { if [[ -d "${work_dir}/root-image/tmp" ]]; then find "${work_dir}/root-image/tmp" -mindepth 1 -delete fi + # Delete package pacman related files. + find "${work_dir}" -name "*.pacnew" -name "*.pacsave" -name "*.pacorig" -delete # Create etc/mtab if not is a symlink. if [[ ! -L "${work_dir}/root-image/etc/mtab" ]]; then ln -sf "/proc/self/mounts" "${work_dir}/root-image/etc/mtab" @@ -384,7 +438,7 @@ command_prepare () { # Install packages on root-image. # A basic check to avoid double execution/reinstallation is done via hashing package names. -command_create () { +command_install () { if [[ ! -f "${pacman_conf}" ]]; then _msg_error "Pacman config file '${pacman_conf}' does not exist" 1 fi @@ -397,27 +451,36 @@ command_create () { _usage 1 fi - _show_config create + _show_config install local _pkg_list_hash _pkg_list_hash=$(echo ${pkg_list} | sort -u | md5sum | cut -c1-32) - if [[ -f "${work_dir}/create.${_pkg_list_hash}" ]]; then + if [[ -f "${work_dir}/install.${_pkg_list_hash}" ]]; then _msg_info "These packages are already installed, skipping." else - mkdir -p "${work_dir}/root-image/" _pacman "${pkg_list}" - : > "${work_dir}/create.${_pkg_list_hash}" + : > "${work_dir}/install.${_pkg_list_hash}" fi } +command_init() { + _show_config init + _chroot_init +} + +command_run() { + _show_config run + _chroot_run +} if [[ ${EUID} -ne 0 ]]; then _msg_error "This script must be run as root." 1 fi -while getopts 'p:C:L:P:A:D:w:o:vh' arg; do +while getopts 'p:r:C:L:P:A:D:w:o:vh' arg; do case "${arg}" in p) pkg_list="${pkg_list} ${OPTARG}" ;; + r) run_cmd="${OPTARG}" ;; C) pacman_conf="${OPTARG}" ;; L) iso_label="${OPTARG}" ;; P) iso_publisher="${OPTARG}" ;; @@ -443,8 +506,14 @@ fi command_name="${1}" case "${command_name}" in - create) - command_create + init) + command_init + ;; + install) + command_install + ;; + run) + command_run ;; prepare) command_prepare diff --git a/configs/baseline/build.sh b/configs/baseline/build.sh index 1f2251d..f7f7abf 100755 --- a/configs/baseline/build.sh +++ b/configs/baseline/build.sh @@ -15,8 +15,7 @@ script_path=$(readlink -f ${0%/*}) # Base installation (root-image) make_basefs() { - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "base" create - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "syslinux" create + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" init } # Copy mkinitcpio archiso hooks (root-image) @@ -33,7 +32,9 @@ make_setup_mkinitcpio() { make_boot() { if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then mkdir -p ${work_dir}/iso/${install_dir}/boot/${arch} - mkarchroot -n -r "mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img" ${work_dir}/root-image + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" \ + -r 'mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img' \ + run cp ${work_dir}/root-image/boot/archiso.img ${work_dir}/iso/${install_dir}/boot/${arch}/archiso.img cp ${work_dir}/root-image/boot/vmlinuz-linux ${work_dir}/iso/${install_dir}/boot/${arch}/vmlinuz : > ${work_dir}/build.${FUNCNAME} diff --git a/configs/releng/build.sh b/configs/releng/build.sh index 42836a9..f206caf 100755 --- a/configs/releng/build.sh +++ b/configs/releng/build.sh @@ -15,13 +15,13 @@ script_path=$(readlink -f ${0%/*}) # Base installation (root-image) make_basefs() { - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "base" create - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "memtest86+ syslinux mkinitcpio-nfs-utils nbd curl" create + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" init + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "memtest86+ mkinitcpio-nfs-utils nbd curl" install } # Additional packages (root-image) make_packages() { - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "$(grep -v ^# ${script_path}/packages.${arch})" create + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "$(grep -v ^# ${script_path}/packages.${arch})" install } # Copy mkinitcpio archiso hooks (root-image) @@ -46,7 +46,9 @@ make_boot() { local _src=${work_dir}/root-image local _dst_boot=${work_dir}/iso/${install_dir}/boot mkdir -p ${_dst_boot}/${arch} - mkarchroot -n -r "mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img" ${_src} + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" \ + -r 'mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img' \ + run mv ${_src}/boot/archiso.img ${_dst_boot}/${arch}/archiso.img mv ${_src}/boot/vmlinuz-linux ${_dst_boot}/${arch}/vmlinuz cp ${_src}/boot/memtest86+/memtest.bin ${_dst_boot}/memtest @@ -90,7 +92,6 @@ make_isolinux() { } # Customize installation (root-image) -# NOTE: mkarchroot should not be executed after this function is executed, otherwise will overwrites some custom files. make_customize_root_image() { if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then cp -af ${script_path}/root-image ${work_dir} @@ -99,8 +100,12 @@ make_customize_root_image() { mkdir -p ${work_dir}/root-image/etc/pacman.d wget -O ${work_dir}/root-image/etc/pacman.d/mirrorlist http://www.archlinux.org/mirrorlist/all/ sed -i "s/#Server/Server/g" ${work_dir}/root-image/etc/pacman.d/mirrorlist - chroot ${work_dir}/root-image /usr/sbin/locale-gen - chroot ${work_dir}/root-image /usr/sbin/useradd -m -p "" -g users -G "audio,disk,optical,wheel" arch + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" \ + -r 'locale-gen' \ + run + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" \ + -r 'useradd -m -p "" -g users -G "audio,disk,optical,wheel" arch' \ + run : > ${work_dir}/build.${FUNCNAME} fi } -- 1.7.9.4
This allow to execute build.sh in 32-bit-compat without using a chroot and doing tricks. Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> --- configs/releng/build.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/configs/releng/build.sh b/configs/releng/build.sh index f206caf..5c010ef 100755 --- a/configs/releng/build.sh +++ b/configs/releng/build.sh @@ -132,11 +132,12 @@ make_core_repo() { local _url _urls _pkg_name _cached_pkg _dst _pkgs mkdir -p ${work_dir}/repo-core-any mkdir -p ${work_dir}/repo-core-${arch} - pacman -Sy - _pkgs=$(comm -2 -3 <(pacman -Sql core | sort | sed 's@^@core/@') \ + mkdir -p ${work_dir}/pacman.db/var/lib/pacman + pacman -Sy -r ${work_dir}/pacman.db + _pkgs=$(comm -2 -3 <(pacman -Sql -r ${work_dir}/pacman.db core | sort | sed 's@^@core/@') \ <(grep -v ^# ${script_path}/core.exclude.${arch} | sort | sed 's@^@core/@')) - _urls=$(pacman -Sddp ${_pkgs}) - pacman -Swdd --noprogressbar --noconfirm ${_pkgs} + _urls=$(pacman -Sddp -r ${work_dir}/pacman.db ${_pkgs}) + pacman -Swdd -r ${work_dir}/pacman.db --noprogressbar --noconfirm ${_pkgs} for _url in ${_urls}; do _pkg_name=${_url##*/} _cached_pkg=/var/cache/pacman/pkg/${_pkg_name} -- 1.7.9.4
Make build steps much more simply (remove chroot build is not really needed now). Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> --- README | 96 +++++++++++++++++----------------------------------------------- 1 file changed, 25 insertions(+), 71 deletions(-) diff --git a/README b/README index 4bab18d..9ee367e 100644 --- a/README +++ b/README @@ -150,7 +150,6 @@ if nothing is specified on command line. *** Build requirements ** For mkarchiso script needs these packages (build host): - + devtools for mkarchroot + squashfs-tools for mksquashfs + libisoburn for xorriso @@ -223,34 +222,15 @@ When make your custom boot-pendrive, you need to copy /arch directory to it. *** Building the most basic Arch Linux live media. (configs/baseline) -* Install devtools if needed, mkarchroot needs it - [host] # pacman -S devtools --needed +* Install needed packages. + # pacman -S git make squashfs-tools libisoburn --needed -* Create a base chroot to work on it. - (prefix with linux32 if you want to build a 32 bits enviroment under 64 bits) - [host] # mkarchroot /tmp/chroot base - -* Install archiso on chroot (needs git and make) - [host] # pacman -S git make --needed - [host] # git clone git://projects.archlinux.org/archiso.git - [host] # make -C archiso/archiso DESTDIR=/tmp/chroot install - -* Enter to chroot (prefix with linux32 if needed). - [host] # mkarchroot -d -r bash /tmp/chroot - -* Setup a mirror. - [chroot] # echo 'Server = MIRROR/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist - -* Install aditional packages needed for mkarchiso. - [chroot] # pacman -S devtools squashfs-tools libisoburn +* Install archiso. + # git clone git://projects.archlinux.org/archiso.git + # make -C archiso/archiso install * Build a basic iso. - [chroot] # cp -r /usr/share/archiso/configs/baseline /tmp - [chroot] # cd /tmp/baseline - [chroot] # ./build.sh - -* Exit from chroot. - [chroot] # exit + # /usr/share/archiso/configs/baseline/build.sh Note: If you want to customize, just see the configs/releng directory which is used to build official images with much more things. @@ -259,56 +239,30 @@ used to build official images with much more things. *** Building official Arch Linux live media. (configs/releng) -Note: These steps should be done with 64 bits support. - -* Prepare a 32 bit chroot enviroment. - - [host64] # linux32 mkarchroot /tmp/chroot32 base - [host64] # linux32 mkarchroot -r bash /tmp/chroot32 - [chroot32] # echo 'Server = MIRROR/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist - [chroot32] # pacman -S devtools squashfs-tools libisoburn - [chroot32] # exit - -* Prepare a 64 bits chroot enviroment. - - [host64] # mkarchroot /tmp/chroot64 base - [host64] # mkarchroot -r bash /tmp/chroot64 - [chroot64] # echo 'Server = MIRROR/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist - [chroot64] # pacman -S devtools squashfs-tools libisoburn - [chroot64] # exit - -* Install archiso on both chroots. - - [host64] # git clone git://projects.archlinux.org/archiso.git - [host64] # make -C archiso/archiso DESTDIR=/tmp/chroot32 install - [host64] # make -C archiso/archiso DESTDIR=/tmp/chroot64 install +Note: These steps should be done in 64-bit and build.sh should be executed +on the same build directory or use -w <work_dir> option. -* Create a shared /tmp directory between two chroots for working. +* Install needed packages. + # pacman -S git make squashfs-tools libisoburn --needed - [host64] # mkdir /tmp/shared - [host64] # chmod 1777 /tmp/shared - [host64] # mount --bind /tmp/shared /tmp/chroot32/tmp - [host64] # mount --bind /tmp/shared /tmp/chroot64/tmp +* Install archiso. + # git clone git://projects.archlinux.org/archiso.git + # make -C archiso/archiso install -* Enter 32 bits chroot enviroment then build core and netinstall single images. +* Build netinstall and core images (32-bit) + # linux32 /usr/share/archiso/configs/releng/build.sh build single all - [host32] # linux32 mkarchroot -d -r bash /tmp/chroot32 - [chroot32] # cp -r /usr/share/archiso/configs/releng /tmp - [chroot32] # cd /tmp/releng - [chroot32] # ./build.sh build single all - [chroot32] # ./build.sh purge single # optional step +* Delete uneeded files (32-bit) + # linux32 /usr/share/archiso/configs/releng/build.sh purge single -* Enter 64 bits chroot enviroment then build core and netinstall single images. +* Build netinstall and core images (64-bit) + # /usr/share/archiso/configs/releng/build.sh build single all - [host64] # mkarchroot -d -r bash /tmp/chroot64 - [chroot64] # cp -r /usr/share/archiso/configs/releng /tmp - [chroot64] # cd /tmp/releng - [chroot64] # ./build.sh build single all - [chroot64] # ./build.sh purge single # optional step +* Delete uneeded files (64-bit) + # /usr/share/archiso/configs/releng/build.sh purge single -* Build core and netinstall dual images from any of the chroot enviroments. +* Build netinstall and core images (dual 32/64 bit) + # /usr/share/archiso/configs/releng/build.sh build dual all - [host64] # mkarchroot -r bash /tmp/chroot64 - [chroot64] # cd /tmp/releng - [chroot64] # ./build.sh build dual all - [chroot64] # ./build.sh purge dual # optional step +* Delete uneeded files (dual 32/64 bit) + # /usr/share/archiso/configs/releng/build.sh purge dual -- 1.7.9.4
On Fri, 16 Mar 2012 02:26:36 -0300 Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> wrote:
This allow to execute build.sh in 32-bit-compat without using a chroot and doing tricks.
Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> --- configs/releng/build.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/configs/releng/build.sh b/configs/releng/build.sh index f206caf..5c010ef 100755 --- a/configs/releng/build.sh +++ b/configs/releng/build.sh @@ -132,11 +132,12 @@ make_core_repo() { local _url _urls _pkg_name _cached_pkg _dst _pkgs mkdir -p ${work_dir}/repo-core-any mkdir -p ${work_dir}/repo-core-${arch} - pacman -Sy - _pkgs=$(comm -2 -3 <(pacman -Sql core | sort | sed 's@^@core/@') \ + mkdir -p ${work_dir}/pacman.db/var/lib/pacman + pacman -Sy -r ${work_dir}/pacman.db + _pkgs=$(comm -2 -3 <(pacman -Sql -r ${work_dir}/pacman.db core | sort | sed 's@^@core/@') \ <(grep -v ^# ${script_path}/core.exclude.${arch} | sort | sed 's@^@core/@')) - _urls=$(pacman -Sddp ${_pkgs}) - pacman -Swdd --noprogressbar --noconfirm ${_pkgs} + _urls=$(pacman -Sddp -r ${work_dir}/pacman.db ${_pkgs}) + pacman -Swdd -r ${work_dir}/pacman.db --noprogressbar --noconfirm ${_pkgs} for _url in ${_urls}; do _pkg_name=${_url##*/} _cached_pkg=/var/cache/pacman/pkg/${_pkg_name}
some code comments seem helpful here. Dieter
On 03/16/2012 12:59 PM, Dieter Plaetinck wrote:
On Fri, 16 Mar 2012 02:26:36 -0300 Gerardo Exequiel Pozzi<vmlinuz386@yahoo.com.ar> wrote:
This allow to execute build.sh in 32-bit-compat without using a chroot and doing tricks.
Signed-off-by: Gerardo Exequiel Pozzi<vmlinuz386@yahoo.com.ar> --- configs/releng/build.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/configs/releng/build.sh b/configs/releng/build.sh index f206caf..5c010ef 100755 --- a/configs/releng/build.sh +++ b/configs/releng/build.sh @@ -132,11 +132,12 @@ make_core_repo() { local _url _urls _pkg_name _cached_pkg _dst _pkgs mkdir -p ${work_dir}/repo-core-any mkdir -p ${work_dir}/repo-core-${arch} - pacman -Sy - _pkgs=$(comm -2 -3<(pacman -Sql core | sort | sed 's@^@core/@') \ + mkdir -p ${work_dir}/pacman.db/var/lib/pacman + pacman -Sy -r ${work_dir}/pacman.db + _pkgs=$(comm -2 -3<(pacman -Sql -r ${work_dir}/pacman.db core | sort | sed 's@^@core/@') \ <(grep -v ^# ${script_path}/core.exclude.${arch} | sort | sed 's@^@core/@')) - _urls=$(pacman -Sddp ${_pkgs}) - pacman -Swdd --noprogressbar --noconfirm ${_pkgs} + _urls=$(pacman -Sddp -r ${work_dir}/pacman.db ${_pkgs}) + pacman -Swdd -r ${work_dir}/pacman.db --noprogressbar --noconfirm ${_pkgs} for _url in ${_urls}; do _pkg_name=${_url##*/} _cached_pkg=/var/cache/pacman/pkg/${_pkg_name} some code comments seem helpful here.
Dieter
1) Fetch pacman package sync database. (-Sy) 2) Build a list of [core] packages minus excluded packages. (-Sl) 3) Download packages (-Sw) -- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
On Fri, 16 Mar 2012 13:59:32 -0300 Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> wrote:
On 03/16/2012 12:59 PM, Dieter Plaetinck wrote:
On Fri, 16 Mar 2012 02:26:36 -0300 Gerardo Exequiel Pozzi<vmlinuz386@yahoo.com.ar> wrote:
This allow to execute build.sh in 32-bit-compat without using a chroot and doing tricks.
Signed-off-by: Gerardo Exequiel Pozzi<vmlinuz386@yahoo.com.ar> --- configs/releng/build.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/configs/releng/build.sh b/configs/releng/build.sh index f206caf..5c010ef 100755 --- a/configs/releng/build.sh +++ b/configs/releng/build.sh @@ -132,11 +132,12 @@ make_core_repo() { local _url _urls _pkg_name _cached_pkg _dst _pkgs mkdir -p ${work_dir}/repo-core-any mkdir -p ${work_dir}/repo-core-${arch} - pacman -Sy - _pkgs=$(comm -2 -3<(pacman -Sql core | sort | sed 's@^@core/@') \ + mkdir -p ${work_dir}/pacman.db/var/lib/pacman + pacman -Sy -r ${work_dir}/pacman.db + _pkgs=$(comm -2 -3<(pacman -Sql -r ${work_dir}/pacman.db core | sort | sed 's@^@core/@') \ <(grep -v ^# ${script_path}/core.exclude.${arch} | sort | sed 's@^@core/@')) - _urls=$(pacman -Sddp ${_pkgs}) - pacman -Swdd --noprogressbar --noconfirm ${_pkgs} + _urls=$(pacman -Sddp -r ${work_dir}/pacman.db ${_pkgs}) + pacman -Swdd -r ${work_dir}/pacman.db --noprogressbar --noconfirm ${_pkgs} for _url in ${_urls}; do _pkg_name=${_url##*/} _cached_pkg=/var/cache/pacman/pkg/${_pkg_name} some code comments seem helpful here.
Dieter
1) Fetch pacman package sync database. (-Sy) 2) Build a list of [core] packages minus excluded packages. (-Sl) 3) Download packages (-Sw)
I meant code comments in the code, those are more useful than code comments in an email. Dieter
On 03/16/2012 02:26 AM, Gerardo Exequiel Pozzi wrote:
* Remove devtools dependency. * Better control over what files are touched inside chroot (root-image). Now: NONE :) * Two new commands: + init: To install {base} group and other needed packages (syslinux for now) + run: If we want to run some command inside chroot (mkinitcpio, locale-gen, useradd, etc etc...) * Renamed command: "created" to "install", says much better what does.
Signed-off-by: Gerardo Exequiel Pozzi<vmlinuz386@yahoo.com.ar> --- archiso/mkarchiso | 103 +++++++++++++++++++++++++++++++++++++-------- configs/baseline/build.sh | 7 +-- configs/releng/build.sh | 19 ++++++--- 3 files changed, 102 insertions(+), 27 deletions(-)
diff --git a/archiso/mkarchiso b/archiso/mkarchiso index b3aa5cd..df3d354 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -5,6 +5,7 @@ set -e -u app_name=${0##*/} arch=$(uname -m) pkg_list="" +run_cmd="" quiet="y" pacman_conf="/etc/pacman.conf" export iso_label="ARCH_$(date +%Y%m)" @@ -44,6 +45,44 @@ _show_space_usage () { _msg_info "Total: ${_total} MiB (100%) | Used: ${_used} MiB (${_pct_u}) | Avail: ${_avail} MiB ($((100 - ${_pct_u%\%}))%)" }
+_chroot_mount () { + mount -t devtmpfs dev "${work_dir}/root-image/dev" + mount -t devpts devpts "${work_dir}/root-image/dev/pts" + mount -t tmpfs devshm "${work_dir}/root-image/dev/shm" + mount -t proc proc "${work_dir}/root-image/proc" + mount -t tmpfs run "${work_dir}/root-image/run" + mount -t sysfs sys "${work_dir}/root-image/sys" + mount -t tmpfs tmp "${work_dir}/root-image/tmp" + + trap '_chroot_umount' EXIT HUP INT TERM +} + +_chroot_umount () { + umount "${work_dir}/root-image/tmp" + umount "${work_dir}/root-image/sys" + umount "${work_dir}/root-image/run" + umount "${work_dir}/root-image/proc" + umount "${work_dir}/root-image/dev/shm" + umount "${work_dir}/root-image/dev/pts" + umount "${work_dir}/root-image/dev" + + trap - EXIT HUP INT TERM +} + +_chroot_init() { + if [[ ! -d ${work_dir}/root-image/var/cache/pacman ]]; then + mkdir -p ${work_dir}/root-image/{dev,proc,run,sys,tmp,var/lib/pacman} + _pacman "base" + _pacman "syslinux" + fi +} + +_chroot_run() { + _chroot_mount + eval chroot ${work_dir}/root-image "${run_cmd}" + _chroot_umount +} + # Mount a filesystem (trap signals in case of error for unmounting it # $1: source image # $2: mount-point @@ -99,6 +138,7 @@ _usage () echo "usage ${app_name} [options] command<command options>" echo " general options:" echo " -p PACKAGE(S) Package(s) to install, can be used multiple times" + echo " -r<command> Run<command> inside root-image" echo " -C<file> Config file for pacman. Default ${pacman_conf}" echo " -L<label> Set a label for the disk" echo " -P<publisher> Set a publisher for the disk" @@ -113,9 +153,12 @@ _usage () echo " -v Enable verbose output" echo " -h This message" echo " commands:" - echo " create" - echo " create a base directory layout to work with" - echo " includes all specified packages" + echo " init" + echo " Make base layout and install base group" + echo " install" + echo " Install all specified packages (-p)" + echo " run" + echo " run command specified by -r" echo " prepare" echo " build all images" echo " checksum" @@ -126,7 +169,7 @@ _usage () }
# Shows configuration according to command mode. -# $1: create | prepare | iso +# $1: init | install | run | prepare | checksum | iso _show_config () { local _mode="$1" echo @@ -136,10 +179,16 @@ _show_config () { _msg_info " Working directory: ${work_dir}" _msg_info " Installation directory: ${install_dir}" case "${_mode}" in - create) + init) + _msg_info " Pacman config file: ${pacman_conf}" + ;; + install) _msg_info " Pacman config file: ${pacman_conf}" _msg_info " Packages: ${pkg_list}" ;; + run) + _msg_info " Run command: ${run_cmd}" + ;; prepare) ;; checksum) @@ -159,20 +208,23 @@ _pacman () { _msg_info "Installing packages to '${work_dir}/root-image/'..."
+ _chroot_mount + if [[ "${quiet}" = "y" ]]; then - mkarchroot -n -C "${pacman_conf}" -f "${work_dir}/root-image" $*&> /dev/null + pacman -Sy -r "${work_dir}/root-image" --config "${pacman_conf}" --needed --noconfirm $*&> /dev/null else - mkarchroot -n -C "${pacman_conf}" -f "${work_dir}/root-image" $* + pacman -Sy -r "${work_dir}/root-image" --config "${pacman_conf}" --needed --noconfirm $* fi
- # Cleanup - find "${work_dir}" -name "*.pacnew" -name "*.pacsave" -name "*.pacorig" -delete + _chroot_umount + _msg_info "Packages installed successfully!" }
# Cleanup root-image _cleanup () { _msg_info "Cleaning up what we can on root-image" + # remove the initcpio images that were generated for the host system if [[ -d "${work_dir}/root-image/boot" ]]; then find "${work_dir}/root-image/boot" -name '*.img' -delete @@ -201,6 +253,8 @@ _cleanup () { if [[ -d "${work_dir}/root-image/tmp" ]]; then find "${work_dir}/root-image/tmp" -mindepth 1 -delete fi + # Delete package pacman related files. + find "${work_dir}" -name "*.pacnew" -name "*.pacsave" -name "*.pacorig" -delete # Create etc/mtab if not is a symlink. if [[ ! -L "${work_dir}/root-image/etc/mtab" ]]; then ln -sf "/proc/self/mounts" "${work_dir}/root-image/etc/mtab" @@ -384,7 +438,7 @@ command_prepare () {
# Install packages on root-image. # A basic check to avoid double execution/reinstallation is done via hashing package names. -command_create () { +command_install () { if [[ ! -f "${pacman_conf}" ]]; then _msg_error "Pacman config file '${pacman_conf}' does not exist" 1 fi @@ -397,27 +451,36 @@ command_create () { _usage 1 fi
- _show_config create + _show_config install
local _pkg_list_hash _pkg_list_hash=$(echo ${pkg_list} | sort -u | md5sum | cut -c1-32) - if [[ -f "${work_dir}/create.${_pkg_list_hash}" ]]; then + if [[ -f "${work_dir}/install.${_pkg_list_hash}" ]]; then _msg_info "These packages are already installed, skipping." else - mkdir -p "${work_dir}/root-image/" _pacman "${pkg_list}" - :> "${work_dir}/create.${_pkg_list_hash}" + :> "${work_dir}/install.${_pkg_list_hash}" fi }
+command_init() { + _show_config init + _chroot_init +} + +command_run() { + _show_config run + _chroot_run +}
if [[ ${EUID} -ne 0 ]]; then _msg_error "This script must be run as root." 1 fi
-while getopts 'p:C:L:P:A:D:w:o:vh' arg; do +while getopts 'p:r:C:L:P:A:D:w:o:vh' arg; do case "${arg}" in p) pkg_list="${pkg_list} ${OPTARG}" ;; + r) run_cmd="${OPTARG}" ;; C) pacman_conf="${OPTARG}" ;; L) iso_label="${OPTARG}" ;; P) iso_publisher="${OPTARG}" ;; @@ -443,8 +506,14 @@ fi command_name="${1}"
case "${command_name}" in - create) - command_create + init) + command_init + ;; + install) + command_install + ;; + run) + command_run ;; prepare) command_prepare diff --git a/configs/baseline/build.sh b/configs/baseline/build.sh index 1f2251d..f7f7abf 100755 --- a/configs/baseline/build.sh +++ b/configs/baseline/build.sh @@ -15,8 +15,7 @@ script_path=$(readlink -f ${0%/*})
# Base installation (root-image) make_basefs() { - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "base" create - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "syslinux" create + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" init }
# Copy mkinitcpio archiso hooks (root-image) @@ -33,7 +32,9 @@ make_setup_mkinitcpio() { make_boot() { if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then mkdir -p ${work_dir}/iso/${install_dir}/boot/${arch} - mkarchroot -n -r "mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img" ${work_dir}/root-image + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" \ + -r 'mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img' \ + run cp ${work_dir}/root-image/boot/archiso.img ${work_dir}/iso/${install_dir}/boot/${arch}/archiso.img cp ${work_dir}/root-image/boot/vmlinuz-linux ${work_dir}/iso/${install_dir}/boot/${arch}/vmlinuz :> ${work_dir}/build.${FUNCNAME} diff --git a/configs/releng/build.sh b/configs/releng/build.sh index 42836a9..f206caf 100755 --- a/configs/releng/build.sh +++ b/configs/releng/build.sh @@ -15,13 +15,13 @@ script_path=$(readlink -f ${0%/*})
# Base installation (root-image) make_basefs() { - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "base" create - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "memtest86+ syslinux mkinitcpio-nfs-utils nbd curl" create + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" init + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "memtest86+ mkinitcpio-nfs-utils nbd curl" install }
# Additional packages (root-image) make_packages() { - mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "$(grep -v ^# ${script_path}/packages.${arch})" create + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "$(grep -v ^# ${script_path}/packages.${arch})" install }
# Copy mkinitcpio archiso hooks (root-image) @@ -46,7 +46,9 @@ make_boot() { local _src=${work_dir}/root-image local _dst_boot=${work_dir}/iso/${install_dir}/boot mkdir -p ${_dst_boot}/${arch} - mkarchroot -n -r "mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img" ${_src} + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" \ + -r 'mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img' \ + run mv ${_src}/boot/archiso.img ${_dst_boot}/${arch}/archiso.img mv ${_src}/boot/vmlinuz-linux ${_dst_boot}/${arch}/vmlinuz cp ${_src}/boot/memtest86+/memtest.bin ${_dst_boot}/memtest @@ -90,7 +92,6 @@ make_isolinux() { }
# Customize installation (root-image) -# NOTE: mkarchroot should not be executed after this function is executed, otherwise will overwrites some custom files. make_customize_root_image() { if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then cp -af ${script_path}/root-image ${work_dir} @@ -99,8 +100,12 @@ make_customize_root_image() { mkdir -p ${work_dir}/root-image/etc/pacman.d wget -O ${work_dir}/root-image/etc/pacman.d/mirrorlist http://www.archlinux.org/mirrorlist/all/ sed -i "s/#Server/Server/g" ${work_dir}/root-image/etc/pacman.d/mirrorlist - chroot ${work_dir}/root-image /usr/sbin/locale-gen - chroot ${work_dir}/root-image /usr/sbin/useradd -m -p "" -g users -G "audio,disk,optical,wheel" arch + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" \ + -r 'locale-gen' \ + run + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" \ + -r 'useradd -m -p "" -g users -G "audio,disk,optical,wheel" arch' \ + run :> ${work_dir}/build.${FUNCNAME} fi } I will push this to master tomorrow plus other fixes. releng scripts should not be affected since there are no changes in "build.sh interface specifications (?)" ;)
-- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
participants (2)
-
Dieter Plaetinck
-
Gerardo Exequiel Pozzi