0

I want to take a copy of my Ubuntu OS to a usb as an image where I can use this image later with a VM in Windows PC.

My usb stick is 16 GB (14.7GB actually) and the Ubuntu hard disk is 250 while the used space is only 10 GB. I can't use dd as it will also copy the whole 250GB and I only want to copy the used 10GB.

Also, don't tell me to use gzip as if I even compress it, I need to extract it again and my other PC with the VM is only 250GB hard disk.

2
  • There are methods for this task. Some are easier, some are more complicated. The best alternative depends on how your Ubuntu is installed. 1) Is it installed in UEFI mode (or BIOS alias CSM alias legacy mode)? Is there an MSDOS partition table or a GUID partition table (GPT)? Which version of Ubuntu is it?
    – sudodus
    Jun 16, 2017 at 16:54
  • It's not totally clear (to me) the size of your Ubuntu OS. It appears you're saying the Ubuntu OS drive is 250 GB and it's currently only using 10 Gigs of the available space. The steps will depend on the physical size of the OS drive. Jun 16, 2017 at 17:17

1 Answer 1

2
  1. Use Gparted to resize the Ubuntu OS installation to a size small enough to fit on your USB drive. You can resize it to 12GB.

  2. Use DD or a GUI drive backup utility such as Clonezilla to backup the 12GB drive to the USB stick. Your USB stick should now be bootable as if it were your original hard drive.

  3. For Virtualization converting the USB drive to VDI use VBoxManager.

  4. You can store the 12 GIG USB drive as an image DD or Ubuntu's GUI Disk Manager.

The Steps in detail

  • Resiz3 the Disk.

You'll have to use a Live session (or a different boot drive to run Gparted. The drive can't be in used while performing the resize.

  • Backup your Disk to the USB stick.

You can back it up with this commandline using DD:

$ dd if=[source drive/image] of=[destination drive or image] bs=4M status=progress

Source Drive - The USB stick (ie /dev/sdb, /dev/sdc, etc)
Destination drive or image:

You can also use the GUI method via Clonezilla to backup the harddrive to USB drive (or an image).

  • Convert to a Virtual Disk

If you backed up the drive as an image, use this command to create a VirtualBox image:

$ VBoxManage convertdd input.img output.vdi

Use this command to create the VirtualBox image from the USB drive itself:

$ VBoxManage convertfromraw /dev/sdX MyImage.vdi --format VDI

(The /dev/sdX will be /dev/sda, /dev/sdb, (or the appropriate device of your USB drive.))

You can transfer Device to Device using Clonezilla

The Clonezilla application has the option of transferring your USB drive (device) directly to your HardDrive (device).

Summary

After you have transferred the Smaller USB drive to the larger Hard Drive, you will have to use Gparted to resize the Drive/Partitions to regain the space available on the larger hard drive.

2
  • The dd method works with MSDOS partition tables, but need fixing if there is a GUID partition table (GPT). You can use gdisk to fix it (the backup partition table at the tail end of the drive). Maybe new versions of Clonezilla can do it all the way also for GPT, but at least earlier versions were not happy to clone to a smaller drive.
    – sudodus
    Jun 16, 2017 at 21:45
  • Thanks for the feedback and information.I tested the steps before posting them. You're right, that there is a method for using Clonezilla to backup to a smaller drive or partition. I have experimented with that in the past (when it wasn't built-in, but a tricky method for doing it. I didn't include those details because the the OP's main objective was described as a backup excluding the free space (which using Gparted to shrink the big drive will achieve that. The restore from the USB drive (or image) will certainly be to a drive that's larger than the 12GB backup. Jun 16, 2017 at 22:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .