# shrinking linux vhd in hyper-v

**URL:** <https://forums.suse.com/t/shrinking-linux-vhd-in-hyper-v/22564>\
**Category:** SLES Virtualization\
**Created:** [April 28, 2012, 10:25pm UTC](https://forums.suse.com/t/shrinking-linux-vhd-in-hyper-v/22564 "2012-04-28T22:25:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![khill1963](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@khill1963](https://forums.suse.com/u/khill1963)\
**Post date:** [April 28, 2012, 10:25pm UTC](https://forums.suse.com/t/shrinking-linux-vhd-in-hyper-v/22564/1 "2012-04-28T22:25:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [April 29, 2012, 12:33am UTC](https://forums.suse.com/t/shrinking-linux-vhd-in-hyper-v/22564/2 "2012-04-29T00:33:40Z")

</div>

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](http://tinyurl.com/openSUSE-T-C)

---

<div class="post-metadata">

**Author:** ![khill1963](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@khill1963](https://forums.suse.com/u/khill1963)\
**Post date:** [April 29, 2012, 4:02pm UTC](https://forums.suse.com/t/shrinking-linux-vhd-in-hyper-v/22564/3 "2012-04-29T16:02:23Z")

</div>

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](http://tinyurl.com/openSUSE-T-C)[/QUOTE]

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [April 29, 2012, 10:08pm UTC](https://forums.suse.com/t/shrinking-linux-vhd-in-hyper-v/22564/4 "2012-04-29T22:08:12Z")

</div>

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](http://tinyurl.com/openSUSE-T-C)
