#! /bin/bash # The functions used to mount and unmount the filesystems for lvmbuilder # lvmbuilder -- Debian package builder using LVM # Copyright (C) 2007 Kapil Hari Paranjape # based on: # pbuilder -- personal Debian package builder # Copyright (C) 2001-2006 Junichi Uekawa # # This program 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 of the License, or # (at your option) any later version. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # lvmbuilder by Kapil Hari Paranjape 2007 Aug 15 # pbuilder by Junichi Uekawa 2001 Aug 25 set -e function clean_basedev(){ echo -n "This will wipe out $BASEDEV. Proceed?[y/N]" read ans if [ "$ans" != "y" -a "$ans" != "Y" ] then exit 0 fi echo "Making new file system at $BASEDEV." mke2fs $BASEDEV } function unmount_basedev(){ umount $BASEDEV e2fsck -f -v $BASEDEV } function setup_workplace(){ # Size computations BASESIZE=$(blockdev --getsize $BASEDEV) COWSIZE=$(blockdev --getsize $COWDEV) TOTAL=$[ $COWSIZE + $BASESIZE ] # Load the necessary modules modprobe dm_zero dm_mirror dm_snapshot dm_mod ## Create the total base device # It consists of the base device extended by zeroes. # The length of the zeroes is the size of the cow. ( echo 0 $BASESIZE linear $BASEDEV 0 ; \ echo $BASESIZE $COWSIZE zero ) | \ dmsetup create $TOTALNAME ## Create the work device # It is the snapshot device with the all writes # going to the cow device. The file-system is resized # to the maximum extent possible. echo 0 $TOTAL snapshot $TOTALDEV $COWDEV n 16 | \ dmsetup create $WORKNAME [ -b $WORKDEV ] && resize2fs $WORKDEV mount $WORKDEV $BUILDPLACE } function takedown_workplace(){ umount /dev/mapper/lvmbuilder-work dmsetup remove lvmbuilder-work dmsetup remove lvmbuilder-total } function showhelp(){ cat <