[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#579645: base-installer: Should be usable to install base system somewhere else than /target



Package: base-installer
Version: 1.106
Severity: wishlist
Tags: patch

I have a custom udeb for a debian derivative that installs supplementary
debian base systems and configures them as virtual machines or chroots.
However I want to install those in /target/srv/<something> and not in
/target directly.

Due to this I can't easily reuse base-installer's library.sh but I have to
provide my own copy of most functions. It would be nice if library.sh
would respect the $TARGET environment variable.

Please find attached a patch that should implement this.

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable'), (150, 'experimental')
Architecture: i386 (x86_64)

Kernel: Linux 2.6.32-4-amd64 (SMP w/2 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

-- 
Raphaël Hertzog

Like what I do? Sponsor me: http://ouaza.com/wp/2010/01/05/5-years-of-freexian/
My Debian goals: http://ouaza.com/wp/2010/01/09/debian-related-goals-for-2010/
Index: debian/changelog
===================================================================
--- debian/changelog	(révision 63032)
+++ debian/changelog	(copie de travail)
@@ -1,8 +1,13 @@
 base-installer (1.107) UNRELEASED; urgency=low
 
+  [ Frans Pop ]
   * Fix install_extra() to actually display the return code from apt-install
     in case of an error.
 
+  [ Raphaël Hertzog ]
+  * Change base-installer/library.sh to install the base system in the
+    directory pointed by $TARGET (and defaults to /target if not defined).
+
  -- Frans Pop <fjp@debian.org>  Sun, 14 Mar 2010 08:20:20 +0100
 
 base-installer (1.106) unstable; urgency=low
Index: library.sh
===================================================================
--- library.sh	(révision 63032)
+++ library.sh	(copie de travail)
@@ -25,9 +25,10 @@
 CPUINFO=/proc/cpuinfo
 
 # files and directories
-APT_SOURCES=/target/etc/apt/sources.list
-APT_CONFDIR=/target/etc/apt/apt.conf.d
-IT_CONFDIR=/target/etc/initramfs-tools/conf.d
+TARGET=${TARGET:-/target}
+APT_SOURCES=$TARGET/etc/apt/sources.list
+APT_CONFDIR=$TARGET/etc/apt/apt.conf.d
+IT_CONFDIR=$TARGET/etc/initramfs-tools/conf.d
 
 IFS_ORIG="$IFS"
 NL="
@@ -83,13 +84,13 @@
 check_target () {
 	# Make sure something is mounted on the target.
 	# Partconf causes the latter format.
-	if ! grep -q '/target ' /proc/mounts && \
-	   ! grep -q '/target/ ' /proc/mounts; then
+	if ! grep -q "$TARGET " /proc/mounts && \
+	   ! grep -q "$TARGET/ " /proc/mounts; then
 		exit_error base-installer/no_target_mounted
 	fi
 
 	# Warn about installation over an existing unix.
-	if [ -e /target/bin/sh -o -L /target/bin/sh ]; then
+	if [ -e $TARGET/bin/sh -o -L $TARGET/bin/sh ]; then
 		warning "attempting to install to unclean target"
 		db_capb ""
 		db_input high base-installer/use_unclean_target || true
@@ -104,13 +105,13 @@
 	fi
 
 	# Undo dev bind mounts for idempotency.
-	if grep -qE '^[^ ]+ /target/dev' /proc/mounts; then
-		umount /target/dev
+	if grep -qE "^[^ ]+ $TARGET/dev" /proc/mounts; then
+		umount $TARGET/dev
 	fi
-	# Unmount /dev/.static/dev if mounted on same device as /target
+	# Unmount /dev/.static/dev if mounted on same device as $TARGET
 	mp_stdev=$(grep -E '^[^ ]+ /dev/\.static/dev' /proc/mounts | \
 		   cut -d" " -f1)
-	if [ "$mp_stdev" ] && grep -q "^$mp_stdev /target " /proc/mounts; then
+	if [ "$mp_stdev" ] && grep -q "^$mp_stdev $TARGET " /proc/mounts; then
 		umount /dev/.static/dev
 	fi
 }
@@ -120,9 +121,9 @@
 	# Tests in MAKEDEV require this is done in the D-I environment
 	mkdir -p /dev/.static/dev
 	chmod 700 /dev/.static/
-	mount --bind /target/dev /dev/.static/dev
+	mount --bind $TARGET/dev /dev/.static/dev
 	# Mirror device nodes in D-I environment to target
-	mount --bind /dev /target/dev/
+	mount --bind /dev $TARGET/dev/
 }
 
 configure_apt_preferences () {
@@ -163,7 +164,7 @@
 }
 
 apt_update () {
-	log-output -t base-installer chroot /target apt-get update \
+	log-output -t base-installer chroot $TARGET apt-get update \
 		|| apt_update_failed=$?
 
 	if [ "$apt_update_failed" ]; then
@@ -173,7 +174,7 @@
 
 install_extra () {
 	local IFS
-	info "Installing queued packages into /target/."
+	info "Installing queued packages into $TARGET/."
 
 	if [ -f /var/lib/apt-install/queue ]; then
 		# We need to install these one by one in case one fails.
@@ -188,7 +189,7 @@
 			db_progress INFO base-installer/section/install_extra_package
 
 			log-output -t base-installer apt-install $OPTS $PKG || \
-				warning "Failed to install $PKG into /target/: $?"
+				warning "Failed to install $PKG into $TARGET/: $?"
 
 			# Advance progress bar within space allocated for install_extra
 			CURR_PKG=$(($CURR_PKG + 1))
@@ -307,7 +308,7 @@
 
 kernel_update_list () {
 	# Use 'uniq' to avoid listing the same kernel more then once
-	chroot /target apt-cache search '^(kernel|linux)-image' | \
+	chroot $TARGET apt-cache search '^(kernel|linux)-image' | \
 	cut -d" " -f1 | uniq > "$KERNEL_LIST.unfiltered"
 	kernels=`sort -r "$KERNEL_LIST.unfiltered" | tr '\n' ' ' | sed -e 's/ $//'`
 	for candidate in $kernels; do
@@ -477,14 +478,14 @@
 	fi
 
 	# Create configuration file for kernel-package
-	if [ -f /target/etc/kernel-img.conf ]; then
+	if [ -f $TARGET/etc/kernel-img.conf ]; then
 		# Backup old kernel-img.conf
-		mv /target/etc/kernel-img.conf /target/etc/kernel-img.conf.$$
+		mv $TARGET/etc/kernel-img.conf $TARGET/etc/kernel-img.conf.$$
 	fi
 
 	info "Setting do_initrd='$do_initrd'."
 	info "Setting link_in_boot='$link_in_boot'."
-	cat > /target/etc/kernel-img.conf <<EOF
+	cat > $TARGET/etc/kernel-img.conf <<EOF
 # Kernel image management overrides
 # See kernel-img.conf(5) for details
 do_symlinks = yes
@@ -624,7 +625,7 @@
 		if [ "$ARCH" = powerpc ] && [ "$SUBARCH" = prep ] && \
 		   [ "$rd_generator" = initramfs-tools ]; then
 			prepconf=$IT_CONFDIR/prep-root
-			rootpart_devfs=$(mount | grep "on /target " | cut -d' ' -f1)
+			rootpart_devfs=$(mount | grep "on $TARGET " | cut -d' ' -f1)
 			rootpart=$(mapdevfs $rootpart_devfs)
 			if [ -f $prepconf ] && grep -q "^#* *ROOT=" $prepconf; then
 				sed -e "s@^#* *ROOT=.*@ROOT=$rootpart@" < $prepconf > $prepconf.new &&
@@ -646,9 +647,9 @@
 	# Advance progress bar to 90% of allocated space for install_linux
 	update_progress 90 100
 
-	if [ -f /target/etc/kernel-img.conf.$$ ]; then
+	if [ -f $TARGET/etc/kernel-img.conf.$$ ]; then
 		# Revert old kernel-img.conf
-		mv /target/etc/kernel-img.conf.$$ /target/etc/kernel-img.conf
+		mv $TARGET/etc/kernel-img.conf.$$ $TARGET/etc/kernel-img.conf
 	fi
 
 	if [ "$kernel_install_failed" ]; then
@@ -683,7 +684,7 @@
 	db_get base-installer/kernel/linux/initramfs-generators || return 1
 
 	for irf in $RET; do
-		if LANG=C chroot /target apt-cache policy $irf 2>&1 | \
+		if LANG=C chroot $TARGET apt-cache policy $irf 2>&1 | \
 			grep "Candidate:" | grep -v "(none)" >/dev/null 2>&1; then
 			if [ "$irf_list" ]; then
 				irf_list="$irf_list $irf"
@@ -725,12 +726,12 @@
 }
 
 addmodule_initramfs_tools () {
-	CFILE='/target/etc/initramfs-tools/modules'
+	CFILE="$TARGET/etc/initramfs-tools/modules"
 	addmodule_easy "$1" "$2"
 }
 
 addmodule_yaird () {
-	CFILE='/target/etc/yaird/Default.cfg'
+	CFILE="$TARGET/etc/yaird/Default.cfg"
 	if [ -f "$CFILE" ]; then
 		if [ "$2" = 1 ]; then
 			sed -i "/END GOALS/s/^/\n\t\t#\n\t\t# Added by Debian Installer\n/" $CFILE
@@ -742,7 +743,7 @@
 # Assumes the file protocol is only used for CD (image) installs
 configure_apt () {
 	if [ "$PROTOCOL" = file ]; then
-		local tdir=/target/media$DIRECTORY
+		local tdir=$TARGET/media$DIRECTORY
 		rm -f /var/lib/install-cd.id
 
 		# Let apt inside the chroot see the cdrom
@@ -783,7 +784,7 @@
 		# Prevent apt-cdrom from prompting
 		: > $APT_SOURCES
 		if ! log-output -t base-installer \
-		     chroot /target apt-cdrom add </dev/null; then
+		     chroot $TARGET apt-cdrom add </dev/null; then
 			error "error while running apt-cdrom"
 		fi
 	else

Reply to: