When attempting to use zero-tool on a partition that G4L is unable to mount, one gets an error message stating it could not recognize the partition.
the partition selection should offer only valid choices. Currently there is no way to zero a linux swap partition, but zero tool can select it for zeroing.
after giving the error message, the zero tool proceeds to zero this path: /dev/ (takes a few seconds, probably G4L's ramdisk?), which is nonesense. It should return to menu after the error message.
Thank you.
The zero function was designed to clear partitions that linux can mount and
then write zeros to directly. The swap partition isn't of that type. I just did a test with this little scripted called clearswap and it does seem to do the job in my test, but will have to see how to implement it.
Note: This was on a running Fedora 21 machine with an 8G swap partition on /dev/sda7. Did a swapoff -a before running the script, and afterwards ran a swapon -a with no issues.
The first line gets the partition that is listed as type swap. (assumes on 1?)
The second line gets the current UUID of the partition to be used in
recreating (mkswap)
The third line just prints the info will testing to make sure it was correct.
The forth line clears the physical partition
The fifth line then recreates the partition as a swap using the UUID
PART=`blkid | grep swap | cut -f 1 -d:`
UUID=`blkid | grep swap | cut -f 2 -d\"`
echo $PART $UUID
dd if=/dev/zero bs=20M of=$PART
mkswap $PART -U $UUID
So, it doesn't seem to be a big thing, but not sure what would happen with
swap partitions that are setup using label or perhaps.
This could be done on the running OS before running the g4l.
Last edit: Michael Setzer II 2015-04-04
Just a note: when I originally posted that above script it didn't include the ` marks. I added it later, but believe it emailed the original only.
PART=`blkid | grep swap | cut -f 1 -d:`
UUID=`blkid | grep swap | cut -f 2 -d\"`
echo $PART $UUID
dd if=/dev/zero bs=20M of=$PART
mkswap $PART -U $UUID
Yes, I've seen this little script in the other report.
But I posted this to explain that G4L gives an error then seems to attempt zeroing /dev/ and shows a progress (that reaches 100% very quickly) and then removes 0bits file ...
This should not happen.
I have done more work. Currently, taken the cleandrive8.dialog script that uses the same code as was later included into g4l30o11 script.
Did find a few issues. It did have a section to check if the mount failed, but after blanking the partition it still would end up blanking the /mnt/local on the ramdisk. So, no issue.
Modified the script so that it would avoid that issue, and then added the code to have it blank out the partition. Currently doesn't show progress, but could use the same progress. Think I would want to order a check to make sure, since it will completely wipe the contents of the partition, but as long as it is a swap partition it should matter??
Here is the code in the modified cleandrive8x.dialog.
pcnt=0
JETCAT=`which jetcat-mod `
if [ $? = "0" ] ; then echo $JETCAT
else JETCAT="/jetcat-mod"
fi
if [ ! -d /mnt/local ] ; then
mkdir /mnt ;
mkdir /mnt/local ;
dialog --timeout 10 --msgbox "Needs /mnt/local directory\n(10 second timeout)" 0 0
fi
f_radiolist()
{
$DIALOG --backtitle "$backtitle" --title "$1" --radiolist "$2" 0 0 0 $3
}
f_textbox()
{
$DIALOG --clear --backtitle "$backtitle" --title "$1" --textbox $2 0 0
}
part_info2()
{
partonly="";
partlist="";
disklist="";
#LC_ALL=C added since regular sort was sorting sda after sda# options.
#busybox sort works correctly, but if one uses script on anther version
#it might sort incorrectly. dm stuff added to put lvm partition at end.
fsarchiver probe 2>&1 | grep -v = | grep \[ | sed 's/dm/zz/g' | LC_ALL=C sort | sed -e 's/ /@/g' -e 's/zz/dm/g' >/tmp/sysinfo2
while read LINE
do
xxdev=`echo $LINE | cut -b2-5`;
xxdev2=`echo $LINE | cut -b2-3`;
xxsize=`echo $LINE | cut -b55-66 | sed 's/@//g'`;
xxtype=`echo $LINE | cut -b21-31 `;
xxtype2=`echo $LINE | cut -b32-32 `;
if [ "$xxtype2" != "]" ] ; then
xxtype=`echo $LINE | cut -b21-51 `;
fi
pad="";
a=`echo ${#xxsize}`;
while [ $a -le 10 ]
do
pad=$pad_;
a=$(($a + 1));
done
if [ "$xxdev2" == "dm" ]; then
xxtype="LVM2_"$xxtype;
fi
if [ "$xxtype2" != "]" ]; then
disklist="$disklist `printf "%s %s%s--%s off" $xxdev $pad $xxsize $xxtype `";
fi
partlist="$partlist `printf "%s %s%s--%s off" $xxdev $pad $xxsize $xxtype `";
if [ "$xxtype2" == "]" ] ; then
partonly="$partonly `printf "%s %s%s--%s off" $xxdev $pad $xxsize $xxtype `";
fi
done </tmp/sysinfo2
partonly=`echo $partonly | sed 's/@//g'`
partlist=`echo $partlist | sed 's/@//g'`
disklist=`echo $disklist | sed 's/@//g'`
if [ -z "$partonly" ] ; then
partonly="none no_partitions off";
fi
if [ -z "$partlist" ] ; then
partlist="none no_partitions off";
fi
if [ -z "$disklist" ] ; then
disklist="none no_disks off";
fi
}
part_info()
{
partitions=`grep .d /tmp/sysinfo
printf "Drive/Partition sizes:\n" >> /tmp/sysinfo
grep .d >/tmp/sysinfo
printf "\nDrive models:\n" >> /tmp/sysinfo
for h in $partitions
do
length=`echo $h |wc -c`
if [ $length -lt 5 ]; then
echo $h >> /tmp/sysinfo
cat /proc/ide/$h/model >> /tmp/sysinfo 2>/dev/null
fi
done
### 2008/5/27 New partlist to have size and partitiion type.
partlist="";
partonly="";
### 2009/3/15 New disklist to have just disks without partitions
disklist="";
fdisk -l 2>/dev/null | grep /dev | grep -v Disk | sed s/*/\ / | awk '{print $1,$6$7$8}' | cut -b6-30 >/tmp/partout
grep .d /tmp/sysinfo2
while read LINE
do
xxdev=`echo $LINE | cut -f1 -d\ `;
xxsize=`echo $LINE | cut -f2 -d\ `;
xxsize2=`echo ${#xxsize}`;
pad="";
a=$xxsize2;
while [ $a -le 12 ]
do
pad=$pad_;
a=$(($a + 1));
done
xxtype="";
xxtype=`grep $xxdev\ /dev/null | cut -f2 -d\ `;
if [ -z $xxtype ]; then
xxtype="DISK";
### 2009/3/15 New disklist to have just disks without partitions
disklist="$disklist `printf "%s %s%s--%s off" $xxdev $pad $xxsize $xxtype `";
fi
partlist="$partlist `printf "%s %s%s--%s off" $xxdev $pad $xxsize $xxtype `";
if [ "$xxtype" != "DISK" ] ; then
partonly="$partonly `printf "%s %s%s--%s off" $xxdev $pad $xxsize $xxtype `";
fi
done </tmp/sysinfo2
### End of addition
}
progress()
{
(
while test "$pcnt" != "$value"
do
## Modified Jetcat-mod to display two decimal positions
## have to cut off the decimals for the gauge to work.
if test "$value" == "100"; then
pcnt=`tail -n1 /tmp/progress.out`
pcnt2=`tail -n1 /tmp/progress.out | cut -d. -f 1 `
printf "%s\n" $pcnt2
fi
if test "$value" != "100"; then
if [ " " = "$testx" ]; then
pcnt=`df . | grep % | grep / | awk '{print $4}'`
else
pcnt=`df . | grep % | grep / | awk '{print $5}'`
fi
echo $pcnt | cut -d% -f 1
# printf "%s\n" $pcnt
fi
printf "%s\n" "\n"
## msg variable set before calling the progress function to
## make minor variation between different screens.
printf "%s\n" "$msg"; printf "%s\n" "\n"
printf "%s\n" "\n"
printf "%s\n" "The progress bar shows the percentage of the amount written";
printf "%s\n" "to the size of the destination."; printf "%s\n" "\n";
printf "%s\n" "Please stand by, this might take some time!"; printf "%s\n" "\n"; printf "%s\n" "\n"
## Percentage displays with 2 decimal places, plus start time and current time.
## This lets one check time status of process in addition to percentage
printf "%s\n" "Progress"; printf "%s\n" "\n"
printf "%s\n" "$pcnt"; printf "%s\n" "\n"
printf "%s\n" "XXX";
printf "%s\n" "$pcnt"
sleep 5
done
) |
$DIALOG --backtitle "$backtitle" --title "Working..." --clear --gauge "One moment..." 30 100
rm /tmp/progress.out
touch /tmp/progress.out
## Added a pause to let the user see final results before it returns.
}
backtitle="Program to clear free space"
FSARCH=`which fsarchiver `
if [ $? = "0" ] ; then
part_info2
else
part_info
fi
f_radiolist "PICK DRIVE" "Choose drive to write to/read from.\n(Use Space Bar)\
\nThe drive that contains or will contain the image\
\nSupported FS are:\
\next2. ext3, ext4, reiserfs - Linux\
\nfat32 - Windows95/98/NT/2k/XP\
\nntfs - Windows NT/2k/XP\
\n\nSelect partition (example: /dev/hda1):" "$partonly" 2> /tmp/filelocaldrive
retvallocaldrive=$?
choicelocaldrive=$(cat /tmp/filelocaldrive)
if [ -n "$choicelocaldrive" ]; then
case $retvallocaldrive in
$DIALOG_OK)
localdrive=$choicelocaldrive
###
umount /mnt/local 2>/dev/null
chkswap=`blkid /dev/$localdrive | grep swap`
mount /dev/$localdrive /mnt/local >/tmp/mount 2>&1
retvalmount=$?
if [ $retvalmount != 0 ] ; then
f_textbox "ERROR" /tmp/mount
umount /mnt/local 2>/dev/null
if [ -n chkswap ]; then
echo "Clearing SWAP partition"
UUID=`blkid | grep swap | cut -f 2 -d\"`
dd if=/dev/zero bs=20M of=/dev/$localdrive
mkswap /dev/$localdrive -U $UUID
echo "Done"
sleep 10
fi
localdrive=""
else
cd /mnt/local
chkvfat=`blkid /dev/$localdrive | grep vfat`
if [ -z "$chkvfat" ]; then
{
msg="Clearing Free Space on /dev/$localdrive"
value="100"
freesize=`df . | grep % | grep / | awk '{print $1 - $2}'`
original=`df . | grep % | grep / | awk '{print $4}'`
testx=`df . | grep % | grep / | cut -b1-1`
if [ " " = "$testx" ]; then
freesize=`df . | grep % | grep / | awk '{print $1 - $2}'`
original=`df . | grep % | grep / | awk '{print $4}'`
else
freesize=`df . | grep % | grep / | awk '{print $2 - $3}'`
original=`df . | grep % | grep / | awk '{print $5}'`
fi
printf "%s\n" "$freesize $original"
dd if=/dev/zero bs=2M 2>/dev/null | $JETCAT -f 5000 -p $freesize 2>/tmp/progress.out >0bits &
progress
cat /tmp/progress.out
value=$original
msg="Removing 0bits file"
$DIALOG --sleep 10 --infobox "PAUSE FOR 10 SECONDS" 5 25
rm 0bits &
progress
}
else
lblank7
fi
$DIALOG --sleep 10 --infobox "Drive Should now have all free space cleared" 5 50
fi;;
esac
cd /
umount /mnt/local 2>/dev/null
fi
ftp://amd64gcc.dyndns.org/g4l0.49alpha/
Latest alpha15 has the updated cleandrive8x.dialog that supports swap partitions.
ftp://amd64gcc.dyndns.org/g4l0.49alpha/g4l-v0.49alpha15-fc21.iso
ftp://amd64gcc.dyndns.org/g4l0.49alpha/cleandrive8x.dialog
Made the old cleandrive8.dialog and new cleandrive8x.dialog to be in sync with same lines, and blank lines were the updates were added.
Still need to put changes in g4l script since the code was added originally. The process works from g4l boot, but script would also work on running system, but would require a swapoff be done before running. Might just add that to the script since it would matter doing a swapoff if it isn't currently on.
Since the script does partitions separately, this would handle multiple swap partitions.
Here are a few modifications to make better sense (userwise).
Changed the order things are being run :
Please test it within G4L, I could't inject it into my VM.
I did some experiments with a way to make it so dd won't output "no space left on device" error, but I am unsure of it. Would require a fast (bs=20M) pass and a slow pass (bs=1k seek=almost_end_of_partition) and maybe it's too much just for a message like that.
Side question: I believe you added "ClearHP" in the main menu to highlight them, although, wouldn't (logically) belong to "Utilities" next to "Zero-Tool" ?
Would wiping the swap partition be a problem in case of a system in hibernation? (never used it on linux).
Also, perhaps the label might be preserved (if exists).
I have created another alpha,
ftp://amd64gcc.dyndns.org/g4l0.49alpha/g4l-v0.49alpha16-fc21.iso
It has slightly modified cleandrive8x.dialog screen, and g4l30o11.new script that has the code added. I have tested it with Virtual Box setup, in which I have a virtual disk with a partition that I had made into a test swap partition. It doesn't show the partition type error for the swap, since I have the error message in an if so it doesn't display if the partition is swap. Will have to look about preserving the partition label. Will have to look at that. Don't know how Linux does the hibernation file, with windows I just delete the paging file and hibernation file before doing an image.
Concerning slack space clearing, that would be a major issue, since it would require making changes to every file, and would probable effect the file date/time stamps. Also, don't think if would actually make much difference since it would be at max 1 custer size for each file.
The clean process doesn't yet do anything fancy or suppress the no space message, but that could be fixed with a redirect to null.
In looking at the Label option, I found an error in the parsing if there was a label since that shows up before the uuid if present? So had to come with a more complex process of parsing.
In doing the testing came up with this code.
BLKID2=`blkid /dev/sda7 | cut -f 2 -d\:`
LABEL=""
UUID=""
for a in $BLKID2
do
export $a
done
LABEL=`echo $LABEL | tr -d \"`
UUID=`echo $UUID | tr -d \"`
mkswap -L "$LABEL" -U "$UUID" /dev/sda7
So, have put it into the g4l30o11.new and cleandrive8x.dialog.
Also, did a test on my classroom system.
Systems have an 8G swap partition, and doing an image as is, produced a 2.1G file using lzop compressing in about 2 minutes. Then used the zeroing swap and redid the backup, and it was only 32M and took about 1 1/2 minutes. So not a big savings in time, but made a much bigger difference in image size than I would have thought?