Control: tag -1 + patch On Fri, 05 Aug 2016 13:55:14 +0100 Brian Drummond <bri...@shapes.demon.co.uk> wrote: > *** Reporter, please consider answering these questions, where appropriate *** > > * What led up to the situation? > 0) Okay, this will be embarrassing... > 1) Occasional need to work on i386 software on an x86-64 machine. > 2) Previous experiment led to a marginally usable "minimal" /chroot/i386 > partition (without internet connection) > 3) Desire to add internet connection to same, start by listing packages which > would be installed by "debootstrap --print-debs" > 4) Failure to understand that "debootstrap --print-debs" operated by > performing the entire debootstrap operation, > listing packages, then deleting the created directory, despite a note in the > manfile to that effect. > 5) Further failure to note that such deletion would apply recursively to any > automounted partitions in said created directory. > 6) Previous experiment involved automounting /proc, /sys, /var/tp, and /home > into said /chroot/i386 partition. > 7) Re-using the /chroot/i386 directory name in the "debootstrap > --print-files" command. Without the --keep-bootstrop-dir option, since I was > about to replace it. > 8) I said this was embarassing... > > * What exactly did you do (or not do) that was effective (or > ineffective)? > Sadly, I no longer have my exact notes, as will become clear. But > approximately, the command was (possibly with sudo, or after su): > debootstrap --print-debs /chroot/i386 > > * What was the outcome of this action? > Well I briefly saw the list of packages flash past, before debootstrap got to > the "The TARGET directory will be deleted...." part. > At which point various strange things started happening, until it gradually > dawned on me that /home and /var/tmp were slowly disappearing before my > eyes... > > * What outcome did you expect instead? > > Somehow I expected to be left with a list of .deb packages and a functioning > computer. I now understand my expectations were unrealistic. > > Perhaps I have been punished enough ... and perhaps it would be a good idea > to modify the bit of debootstrap that implements > "The TARGET directory will be deleted...." and convince it to stop at > automounted partitions in /etc/fstab (and/or mtab)? > > It is too late for me, but it might be very pleasing to some future unwary > operators to be left with their /home partition intact... > > (NB the packages/versions listed below apply to a reinstall, not the exact > formerly-running system, for reasons that are hopefully clear)
if I understand correctly, the problem is two-fold: - debootstrap removes everything in a directory even if there was stuff in it beforehand (this should not happen) - debootstrap removes recursively across filesystem boundaries (how was this not noticed earlier?) The following patch should fix this: @@ -409,6 +409,11 @@ fi fi +TARGET_EMPTY=true +if [ "$(ls -A "$TARGET")" ]; then + TARGET_EMPTY=false +fi + ########################################################################### if in_path dpkg && \ @@ -698,8 +703,8 @@ fi if am_doing_phase kill_target; then - if [ "$KEEP_DEBOOTSTRAP_DIR" != true ]; then + if [ "$KEEP_DEBOOTSTRAP_DIR" != true && "$TARGET_EMPTY" == true ]; then info KILLTARGET "Deleting target directory" - rm -rf "$TARGET" + rm -rf --one-file-system "$TARGET" fi fi Thanks! cheers, josch
signature.asc
Description: signature