LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to reduce linux disk size before virtualizing it? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-reduce-linux-disk-size-before-virtualizing-it-4175602229/)

ppmoore 03-20-2017 06:15 PM

How to reduce linux disk size before virtualizing it?
 
Hello,

I have Ubuntu installed on an SSD in my laptop. I've decided I want to install Windows instead of Linux, and to run Linux as a VM guest on Windows using Virtualbox. The SSD is 256GB, of which only about 60GB in total is used by the various partitions on the disk. The rest of the space is simply unallocated.

I was thinking of using dd to convert the installation to an image file, and then convert the image file to a VDI file using the virtualbox management tools.

Code:

dd if=/dev/sdb of=/VMs/sdb.img
The problem is that dd takes complete copy of the disk, including the unused space; in my case the image file will have the same 256GB size as the original SSD. I would like to reduce the size of this image file. Is there a way to do this using dd (or any other tool)?. I've noticed dd's count option. Can this be used?

I've googled this, and the emphasis seems to be on intermediate file size for file transportation purposes, which can be reduced by piping dd's output through gzip. But this won't affect the actual image file size.

Many thanks,
Paul

jefro 03-20-2017 06:59 PM

I might be tempted to use gparted to shrink the partitons from a live media. Then two ways to go.

1. Copy it over to some place. The now smaller partition and boot area.

Then you could dd then maybe convert it or import it to a vm.

Or

2. Use some clone app like clonezilla/gparted/partimage or such to move the install off.

Then load windows, update (forever) and install a vm.


Note, in the clone process you'd only need the sdx part of the partition and boot info and not the entire drive like you were trying to do. Just the file based would be what clonezilla does but doesn't like going smaller.



Note, in reality you could possibly zero out free space and dd with compression to some file then maybe use that on a growing vm drive. I've never done it that way.

Ztcoracat 03-20-2017 07:10 PM

http://gparted.org/livecd.php

michaelk 03-20-2017 08:03 PM

You could create a smaller drive image file and copy using loop devices(s) like in the link below.

https://wiki.archlinux.org/index.php...irtual_machine

ppmoore 03-21-2017 01:09 AM

Thanks for the replies.

I don't need to use gparted to reduce the size of the partitions. The problem isn't the size of the partitions on the disk - as I indicated, they only take up about 60GB. The problem is the physical size of the SSD. The SSD is 256GB, and I'm trying to reduce the size of the image file generated by the output of dd, from256GB to something like 80GB.

@michaelk: I think that using a loop device is a solution. I'll try it later this evening.

Paul

JJJCR 03-21-2017 01:21 AM

Quote:

Originally Posted by ppmoore (Post 5686258)
Thanks for the replies.

I don't need to use gparted to reduce the size of the partitions. The problem isn't the size of the partitions on the disk - as I indicated, they only take up about 60GB. The problem is the physical size of the SSD. The SSD is 256GB, and I'm trying to reduce the size of the image file generated by the output of dd, from256GB to something like 80GB.

@michaelk: I think that using a loop device is a solution. I'll try it later this evening.

Paul

If dd produces 80GB, I think it should be okay already. How do you know that it's only using 60GB?

Or check out this one: https://superuser.com/questions/6108...reated-with-dd

Command from above link: losetup --find --partscan foo.img


All times are GMT -5. The time now is 05:24 PM.