partman-auto-loop/0000755000000000000000000000000011712402446011324 5ustar partman-auto-loop/autopartition-loop0000755000000000000000000002075411712402446015133 0ustar #! /bin/sh . /lib/partman/lib/base.sh . /lib/partman/lib/resize.sh . /lib/partman/lib/recipes.sh # busybox wants mount -o move; util-linux wants mount --move. Sigh. if [ -d /lib/debian-installer ]; then mount_move='-o move' else mount_move='--move' fi modprobe loop >/dev/null 2>&1 || true # Set up working directory. if type mktemp >/dev/null 2>&1; then recipe_dir="$(mktemp -d /tmp/partman-auto-loop.XXXXXX)" trap "rm -rf $recipe_dir" EXIT HUP INT QUIT TERM else recipe_dir=/tmp fi # Fetch parameters. disk="$1" cd $disk if ! db_get partman-auto-loop/partition || [ -z "$RET" ]; then logger -t partman-auto-loop "Error: No partition number specified in partman-auto-loop/partition" exit 1 fi partition="$RET" if ! db_get partman-auto-loop/recipe || [ -z "$RET" ]; then logger -t partman-auto-loop "Error: No recipe specified in partman-auto-loop/recipe" exit 1 fi recipe="$RET" echo "$recipe" >"$recipe_dir/loop_recipe" # Find the requested partition. db_progress START 0 5 partman-auto/text/automatically_partition db_progress INFO partman-auto/progress/info partition_id= partition_fs= open_dialog PARTITIONS while { read_line num id size type fs path name; [ "$id" ]; }; do if [ "$num" = "$partition" ]; then partition_id="$id" partition_fs="$fs" # go ahead and read all remaining input fi done close_dialog if [ -z "$partition_id" ]; then logger -t partman-auto-loop "Error: Partition number $partition not found in $disk" exit 1 fi # Set up the requested partition in partman. existing=no for j in $( for i in /lib/partman/valid_filesystems/*; do [ -x $i ] || continue $i $disk $partition_id existing done ); do if [ "$j" = "$partition_fs" ]; then existing=yes fi done if [ "$existing" = no ]; then logger -t partman-auto-loop "Error: No filesystem on $disk/$partition_id" exit 1 fi echo keep >$partition_id/method rm -f $partition_id/format >$partition_id/use_filesystem echo $partition_fs >$partition_id/filesystem mkdir -p $partition_id/options echo / >$partition_id/mountpoint update_partition $disk $partition_id # Is there enough space to perform the recipe? dev="$disk" oldid="$partition_id" recipe_new= firstword= imagepaths= for word in $(cat "$recipe_dir/loop_recipe"); do case $word in .) recipe_new="${recipe_new:+$recipe_new }\$imagepath{ $firstword } $word" firstword= ;; *) if [ "$firstword" ]; then recipe_new="${recipe_new:+$recipe_new }$word" else firstword="$word" imagepaths="${imagepaths:+$imagepaths }$word" fi ;; esac done echo "$recipe_new" >"$recipe_dir/loop_recipe_new" decode_recipe "$recipe_dir/loop_recipe_new" loop db_progress STEP 1 fstab="$( for i in /lib/partman/fstab.d/*; do [ -x "$i" ] || continue $i done | while read fs mp type options dump pass; do case $mp in (/) echo $fs $mp $type $options $dump $pass ;; esac done )" if [ -z "$fstab" ]; then logger -t partman-auto-loop "Error: No fstab output for $disk/$partition_id" exit 1 fi mkdir -p /target mountpoint="$(grep "^${fstab%% *} [^ ]* [^ ]* [^ ]*rw" /proc/mounts | cut -d ' ' -f2 | head -n1)" || mountpoint= if [ "$mountpoint" = /target ]; then # nothing to do : elif [ "$mountpoint" ]; then if ! mount $mount_move "$mountpoint" /target; then logger -t partman-auto-loop "Error: Failed to move $mountpoint to /target" exit 1 fi unmount_cmd='umount /target' else for m in /lib/partman/mount.d/*; do [ -x "$m" ] || continue unmount_cmd="$($m "$fstab")" if [ "$?" = 0 ]; then break fi done fi if [ -d /run ]; then mkdir -p /run/sendsigs.omit.d pidof mount.ntfs >> /run/sendsigs.omit.d/ntfs-3g pidof mount.ntfs-3g >> /run/sendsigs.omit.d/ntfs-3g fi # TODO: handle errors if no mount succeeded mkdir -p /host mount $mount_move /target /host # TODO error handling # Don't try to mount this again later. rm -f $partition_id/mountpoint # Ensure there is enough free space. check_free_space=false requires_disk_space(){ [ "$1" != 0 ] || return path="$(echo "$*" | sed 's/.*\$imagepath{ *\([^ }]*\) *}.*/\1/')" [ "$path" != "$*" ] || return case $path in /*) ;; *) path="/$path" ;; esac [ -f "/host$path" ] && return check_free_space=true } foreach_partition 'requires_disk_space $*' # Skip resize_range check if images are already created. if [ $check_free_space = true ]; then case $partition_fs in linux-swap|fat16|fat32|hfs|hfs+|hfsx) get_resize_range ;; ext2|ext3|ext4) if ! search-path tune2fs; then logger -t partman-auto-loop "Error: tune2fs not found" exit 1 fi if ! search-path resize2fs; then logger -t partman-auto-loop "Error: resize2fs not found" exit 1 fi if ! get_ext2_resize_range; then logger -t partman-auto-loop "Error: Failed to get ext2 resize range for $disk/$partition_id" exit 1 fi ;; ntfs) if ! search-path ntfsresize; then logger -t partman-auto-loop "Error: ntfsresize not found" exit 1 fi if ! get_ntfs_resize_range; then db_input critical partman-auto-loop/unclean_ntfs || true db_go || true logger -t partman-auto-loop "Error: Failed to get NTFS resize range for $disk/$partition_id" reboot exit 1 fi ;; *) logger -t partman-auto-loop "Cannot calculate free space on filesystems of type $partition_fs" exit 1 ;; esac free_size="$(expr \( "$cursize" - "$minsize" \) \* 9 / 10)" # convert to megabytes free_size="$(expr 0000000"$free_size" : '0*\(..*\)......$')" if [ $(min_size) -gt $free_size ]; then logger -t partman-auto-loop "Error: partman-auto-loop/recipe too large ($(min_size) > $free_size)" exit 1 fi fi # Ensure that no old loop images are present and mountable. found_images= mkdir -p /tmpmountpoint for path in $imagepaths; do case $path in /*) ;; *) path="/$path" ;; esac if [ -e "/host$path" ]; then if mount -t auto -o loop,ro /host$path /tmpmountpoint 2>/dev/null 3>&-; then found_images="${found_images:+$found_images }$path" umount /tmpmountpoint || true rmdir /tmpmountpoint || true fi fi done if [ "$found_images" ]; then db_progress STOP db_subst partman-auto-loop/unclean_host PARTITION "$partition" db_subst partman-auto-loop/unclean_host DISK "$disk" db_subst partman-auto-loop/unclean_host IMAGES "$found_images" db_input critical partman-auto-loop/unclean_host || true db_capb db_go || true db_capb backup umount /host || true exit 1 fi db_progress STEP 1 expand_scheme db_progress STEP 1 clean_method db_progress STEP 1 setup_loop () { [ "$1" != 0 ] || return path="$(echo "$*" | sed 's/.*\$imagepath{ *\([^ }]*\) *}.*/\1/')" [ "$path" != "$*" ] || return case $path in /*) ;; *) path="/$path" ;; esac if [ ! -f "/host$path" ]; then mkdir -p "/host${path%/*}" if [ "$4" = "linux-swap" ]; then # swap requires a file with no holes dd if=/dev/zero of="/host$path" bs="1000000" count="$1" else dd if=/dev/zero of="/host$path" bs="1000000" seek="$1" count=0 fi fi if ! losetup -f "/host$path"; then shift continue fi if [ "$4" = linux-swap ]; then loops="/host$path" else loops="$(echo /dev/loop* /dev/loop/*)" fi for loop in $loops; do [ -e "$loop" ] || continue case $loop in /dev/loop*) loopfile="$(losetup "$loop")" || continue # The following works with both busybox's # losetup and util-linux's losetup. Yes, # this is ugly. loopfile="$(echo "$loopfile" | sed 's,.*\(/host/[^)]*\).*,\1,')" ;; *) loopfile="$loop" ;; esac [ "$loopfile" = "/host$path" ] || continue dirname="$(echo "$loop" | sed 's:/:=:g')" dev="$DEVICES/$dirname" rm -rf "$dev" mkdir "$dev" || autopartitioning_failed printf "%s" "$loop" >"$dev/device" printf "%s" "$1" >"$dev/size" echo "Loopback on $loopfile" >"$dev/model" echo "$loopfile" >"$dev/loop" cd "$dev" open_dialog OPEN "$(cat "$dev/device")" read_line response close_dialog if [ "$response" = failed ]; then cd / rm -rf "$dev" autopartitioning_failed fi open_dialog NEW_LABEL loop close_dialog # find the free space open_dialog PARTITIONS free_space= while { read_line num id size type fs path name; [ "$id" ]; }; do if [ "$fs" = free ]; then free_space=$id free_size=$size fi done close_dialog # create partition in the free space [ "$free_space" ] || autopartitioning_failed open_dialog NEW_PARTITION primary $4 $free_space full ${1}000001 read_line num id size type fs path name close_dialog shift; shift; shift; shift setup_partition $id $* break done } foreach_partition 'setup_loop $*' db_progress STEP 1 update_all apt-install lupin-support db_progress STOP exit 0 partman-auto-loop/finish.d/0000755000000000000000000000000011260454034013024 5ustar partman-auto-loop/finish.d/create_host_mountpoint0000755000000000000000000000013511260454034017545 0ustar #! /bin/sh if [ -d /host ]; then mkdir -p /target/host mount --bind /host /target/host fi partman-auto-loop/finish.d/_numbers0000644000000000000000000000003210653413417014561 0ustar 25 create_host_mountpoint partman-auto-loop/README0000644000000000000000000000603310653350615012211 0ustar Using partman-auto-loop ----------------------- This allows preseeding of a number of filesystems loop-mounted from images on a pre-existing filesystem. (At present, there is no way to create the host filesystem in the same installation run; the primary use case is installing on filesystem images hosted on a Windows filesystem, in order to avoid repartitioning the disk.) The preseedable question partman-auto/disk should be set to the device name for the host disk (the disk on which filesystem images should be created), partman-auto/method should be set to "loop", and partman-auto-loop/partition should be set to the number of the host partition. On modern Linux kernels, the disk will typically be /dev/sda and the partition number will be 1 for the first partition on the first hard disk; the disk might be /dev/hda instead if the kernel still uses the old drivers/ide/ tree for your disk, or /dev/sdb etc. for subsequent disks. The preseedable question partman-auto-loop/recipe should consist of space-separated recipes, each of which are of the form: . This is deliberately analogous to the regular partman recipe format as documented in installer/doc/devel/partman-auto-recipe.txt, so a valid recipe might look like this (without the line breaks, which have been added for readability): /disks/root.disk 500 10000 5000 ext3 method{ format } format{ } use_filesystem{ } filesystem{ ext3 } mountpoint{ / } . /disks/swap.disk 96 512 300% linux-swap method{ swap } format{ } . Internal specifiers such as $primary{ } and $bootable{ } may be used as in normal recipes, but are currently ignored. Image paths may not contain spaces. Future work ----------- partman-auto-loop is in many ways a temporary workaround. It would be possible to integrate much of this into partman proper, and some of the steps along the way would be valuable elsewhere. * Add multi-device support to partman-auto, in order that one can specify partitions on more than one disk in a single recipe. (Note that loop-mounted filesystem images are considered, more or less, as "disks".) Ensure that recipes are processed in order to the extent that one recipe line may depend for its underlying device on a previous recipe line having been processed. This naturally has some complications in terms of things like calculating desired partition sizes up-front. * Make it possible for recipes to specify existing partitions to be located (by device path or perhaps by other more stable means), modified, and mounted. This would make it possible to specify the host filesystem in a more stable way. * Add recipe syntax to instruct partman to create loop-mounted filesystem images on which other filesystems can be created. This should be done with consideration for other complex devices such as LVM, RAID, and encrypted devices. * Potentially add UI for loop-mounting. See also partman-crypto. -- Colin Watson , for Canonical Ltd. partman-auto-loop/mount.d/0000755000000000000000000000000011260452171012706 5ustar partman-auto-loop/mount.d/_numbers0000644000000000000000000000001011000074455014427 0ustar 70 bind partman-auto-loop/mount.d/bind0000755000000000000000000000033211000074455013543 0ustar #!/bin/sh set -- $1 fs=$1 mp=$2 type=$3 options=$4 dump=$5 pass=$6 case "$options" in *bind*) mount -o "$options" $fs /target$mp || exit 1 echo "umount /target$mp" exit 0 ;; esac exit 1 partman-auto-loop/debian/0000755000000000000000000000000011726361203012546 5ustar partman-auto-loop/debian/source.lintian-overrides0000644000000000000000000000003310653351436017427 0ustar no-standards-version-field partman-auto-loop/debian/changelog0000644000000000000000000001252011726361203014420 0ustar partman-auto-loop (0ubuntu21) precise; urgency=low * Close mount's fd 3 so that it doesn't inherit a debconf file descriptor. -- Colin Watson Fri, 09 Mar 2012 10:59:14 +0000 partman-auto-loop (0ubuntu20) oneiric; urgency=low * Migrate from /var/run/sendsigs.omit to /run/sendsigs.omit.d/ntfs-3g, matching ntfs-3g 1:2011.1.15-0.1ubuntu2. -- Colin Watson Mon, 18 Jul 2011 12:21:33 +0100 partman-auto-loop (0ubuntu19) natty; urgency=low * Use 'dh $@ --options' rather than 'dh --options $@', for forward-compatibility with debhelper v8. * Improve wording of partman-auto-loop/unclean_ntfs. -- Colin Watson Wed, 23 Mar 2011 16:49:50 +0000 partman-auto-loop (0ubuntu18) karmic; urgency=low * Bind-mount /host on /target/host during installation, to match the installed system after reboot (LP: #435153). -- Colin Watson Tue, 29 Sep 2009 22:12:41 +0100 partman-auto-loop (0ubuntu17) karmic; urgency=low * Upgrade to debhelper v7. * Remove fstab.d/hostboot, which is no longer needed with GRUB 2's loop-mounting support (LP: #428407). -- Colin Watson Mon, 14 Sep 2009 11:41:02 +0100 partman-auto-loop (0ubuntu16) jaunty; urgency=low * Add ext4 support. -- Colin Watson Wed, 04 Mar 2009 18:31:16 +0000 partman-auto-loop (0ubuntu15) intrepid; urgency=low * Adjust fstab.d/hostboot for move of definitions.sh to lib/base.sh. -- Colin Watson Fri, 20 Jun 2008 13:23:03 +0100 partman-auto-loop (0ubuntu14) hardy-proposed; urgency=low * Make target mountpoint detection more robust in case of bindmounts (LP: #238701). -- Agostino Russo Wed, 28 May 2008 23:08:22 +0100 partman-auto-loop (0ubuntu13) hardy; urgency=low [ Agostino Russo ] * Allow disk images to be created externally (LP: #176019). * Added template required by autopartition-loop. [ Evan Dandrea ] * Add /host/boot to fstab (LP: #173659). Thanks Agostino Russo. -- Evan Dandrea Fri, 18 Jan 2008 15:58:52 -0500 partman-auto-loop (0ubuntu12) hardy; urgency=low * Grab pids of mount.ntfs as well as mount.ntfs-3g (LP: #150822). * Pass basenames rather than full paths to pidof. * Vcs-Bzr is now an official field. * Account for partman library code having moved to /lib/partman/lib/. -- Colin Watson Thu, 10 Jan 2008 08:42:52 +0000 partman-auto-loop (0ubuntu11) gutsy; urgency=low * Use $mount_move for existing mountpoints too (thanks, Agostino Russo). -- Colin Watson Tue, 02 Oct 2007 23:26:58 +0100 partman-auto-loop (0ubuntu10) gutsy; urgency=low * Call dh_installdebconf. * Use an existing mountpoint for /host if there is one. * Prevent ntfs-3g processes from being killed by /etc/init.d/sendsigs. -- Colin Watson Fri, 28 Sep 2007 15:26:59 +0100 partman-auto-loop (0ubuntu9) gutsy; urgency=low * Remove the 'mountpoint' file for the partition mounted on /host so that we don't try to mount it again later and get confused. * Create sparse files for now. This is probably not ideal as they will tend to fragment and this won't preallocate space, but the installer experience is intolerable at the moment as it takes so long to dd /dev/zero over the whole file. -- Colin Watson Sat, 22 Sep 2007 03:20:40 +0100 partman-auto-loop (0ubuntu8) gutsy; urgency=low * Use 'mount --move' outside d-i rather than 'mount -o move'; inconveniently, util-linux doesn't like the latter, and busybox doesn't like the former. * Actually write the size to the partition's 'size' file, not the type! -- Colin Watson Sat, 22 Sep 2007 01:30:01 +0100 partman-auto-loop (0ubuntu7) gutsy; urgency=low * Read all output from fstab.d scripts; exiting early causes very strange errors due to fstab.d scripts not making it to close_dialog before the next one starts. -- Colin Watson Thu, 20 Sep 2007 11:40:27 +0100 partman-auto-loop (0ubuntu6) gutsy; urgency=low * Skip any zero-sized partitions resulting from recipe expansion. -- Colin Watson Mon, 17 Sep 2007 11:07:44 +0100 partman-auto-loop (0ubuntu5) gutsy; urgency=low * Create ordinary swap files rather than creating swap partitions on top of loop devices. * apt-install lupin-support. -- Colin Watson Fri, 07 Sep 2007 12:48:41 +0100 partman-auto-loop (0ubuntu4) gutsy; urgency=low * Bail out if any of the specified image paths already exist. -- Colin Watson Wed, 29 Aug 2007 15:04:50 +0100 partman-auto-loop (0ubuntu3) gutsy; urgency=low * Priority: standard to match overrides. * Add finish.d script to create a /target/host mountpoint. -- Colin Watson Mon, 30 Jul 2007 18:03:49 +0100 partman-auto-loop (0ubuntu2) gutsy; urgency=low * Never use more than 90% of the host filesystem. -- Colin Watson Mon, 30 Jul 2007 14:39:43 +0100 partman-auto-loop (0ubuntu1) gutsy; urgency=low * Initial release. Not as well-integrated as one might like, as there's no way to create individual loopback mounts in partman at the moment. -- Colin Watson Mon, 30 Jul 2007 13:01:50 +0100 partman-auto-loop/debian/rules0000755000000000000000000000005111417034101013611 0ustar #! /usr/bin/make -f %: dh $@ --with d-i partman-auto-loop/debian/install0000644000000000000000000000002711253404400014126 0ustar autopartition-loop bin partman-auto-loop/debian/partman-auto-loop.templates0000644000000000000000000000121211542421226020037 0ustar Template: partman-auto-loop/unclean_ntfs Type: error _Description: NTFS partition not cleanly unmounted The NTFS partition was not cleanly unmounted. This probably indicates that the system was not shut down properly. Please run "chkdsk /r" from Windows; once that is fixed you should be able to resume the installation. Press OK to reboot. Template: partman-auto-loop/unclean_host Type: error #flag:translate!:3 _Description: Loop-mounted file systems already present The selected partition (partition ${PARTITION} of ${DISK}) already contains the following file system images: . ${IMAGES} . Please uninstall these before trying again. partman-auto-loop/debian/compat0000644000000000000000000000000211252020756013743 0ustar 7 partman-auto-loop/debian/control0000644000000000000000000000074311252021010014134 0ustar Source: partman-auto-loop Section: debian-installer Priority: standard Maintainer: Ubuntu Installer Team Uploaders: Colin Watson Build-Depends: debhelper (>= 7.0.8), dh-di, po-debconf (>= 0.5.0) Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-installer/partman-auto-loop/ubuntu Package: partman-auto-loop XC-Package-Type: udeb Architecture: all Depends: ${misc:Depends} Description: Automatically partition using a loop device partman-auto-loop/debian/po/0000755000000000000000000000000011542422222013157 5ustar partman-auto-loop/debian/po/POTFILES.in0000644000000000000000000000006610665275512014753 0ustar [type: gettext/rfc822deb] partman-auto-loop.templates partman-auto-loop/debian/po/templates.pot0000644000000000000000000000301311542422222015676 0ustar # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: ubuntu-installer@lists.ubuntu.com\n" "POT-Creation-Date: 2011-03-23 16:41+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #. Type: error #. Description #: ../partman-auto-loop.templates:1001 msgid "NTFS partition not cleanly unmounted" msgstr "" #. Type: error #. Description #: ../partman-auto-loop.templates:1001 msgid "" "The NTFS partition was not cleanly unmounted. This probably indicates that " "the system was not shut down properly. Please run \"chkdsk /r\" from " "Windows; once that is fixed you should be able to resume the installation. " "Press OK to reboot." msgstr "" #. Type: error #. Description #: ../partman-auto-loop.templates:2001 msgid "Loop-mounted file systems already present" msgstr "" #. Type: error #. Description #: ../partman-auto-loop.templates:2001 msgid "" "The selected partition (partition ${PARTITION} of ${DISK}) already contains " "the following file system images:" msgstr "" #. Type: error #. Description #: ../partman-auto-loop.templates:2001 msgid "Please uninstall these before trying again." msgstr "" partman-auto-loop/debian/copyright0000644000000000000000000000177110653346521014513 0ustar partman-auto-loop was written by Colin Watson , based on work done on partman-auto and partman-auto-lvm by Anton Zinoviev and others in the d-i team. Copyright (C) 2007 Canonical Ltd. partman-auto-loop is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. partman-auto-loop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with partman-auto-loop; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. A copy of the GNU General Public License is available in /usr/share/common-licenses/GPL-2. partman-auto-loop/debian/di-numbers0000644000000000000000000000005111252020723014523 0ustar finish.d lib/partman mount.d lib/partman