shrinking linux vhd in hyper-v

If i am running SLES 11 as a vm guest in hyper-v and have shrunk the partition down but want to compact the vhd does anyone here have nay experince with that? I was told i need to use zerofree but i can’t find a suse variant of that program? they say i need to write zeros to the unallocated space. Any ideas? Thanks.

On Sat, 28 Apr 2012 19:34:01 +0000, khill1963 wrote:
[color=blue]

If i am running SLES 11 as a vm guest in hyper-v and have shrunk the
partition down but want to compact the vhd does anyone here have nay
experince with that? I was told i need to use zerofree but i can’t find
a suse variant of that program? they say i need to write zeros to the
unallocated space. Any ideas? Thanks.[/color]

Try:

dd if=/dev/zero of=file.tmp
rm file.tmp

You’ll need to do this on each mounted filesystem to get the full effect.

Those commands create a file full of NULL chars and then remove it.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Jim,
So me being a novice to linux can you explain that command to me? Also will it only write zeros to the unallocated portion of the vhd and not all of it? I would assume since this is the boot partition i would need to boot from a linux cd and run it from there. Thanks.

[QUOTE=Jim Henderson;4285]On Sat, 28 Apr 2012 19:34:01 +0000, khill1963 wrote:
[color=blue]

If i am running SLES 11 as a vm guest in hyper-v and have shrunk the
partition down but want to compact the vhd does anyone here have nay
experince with that? I was told i need to use zerofree but i can’t find
a suse variant of that program? they say i need to write zeros to the
unallocated space. Any ideas? Thanks.[/color]

Try:

dd if=/dev/zero of=file.tmp
rm file.tmp

You’ll need to do this on each mounted filesystem to get the full effect.

Those commands create a file full of NULL chars and then remove it.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C[/QUOTE]

On Sun, 29 Apr 2012 13:04:01 +0000, khill1963 wrote:
[color=blue]

So me being a novice to linux can you explain that command to me?
Also will it only write zeros to the unallocated portion of the vhd and
not all of it? I would assume since this is the boot partition i would
need to boot from a linux cd and run it from there. Thanks.[/color]

dd is the “data dump” command.

if=/dev/zero - takes the contents of /dev/zero as the ‘input file’

of=file.tmp - specifies that the contents of the input file are written
to the file ‘file.tmp’.

Because you’re creating a new file, it won’t overwrite allocated blocks
(because it’s a file and not the device file, it’s going to allocate
blocks as any program creating a file and writing to it writes).

Because you’re writing just a normal file, you don’t need to boot from a
LiveCD and run it there - it’s just a regular file, written to a mounted
filesystem.

man dd

This will give you more detailed information about the dd command.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C