Showing posts with label virtualbox. Show all posts
Showing posts with label virtualbox. Show all posts

Tuesday, September 29, 2020

Compacting virtual disk image (VirtualBox)...

Scenario
Host OS: Manjaro Linux
Guest OS: Kali Linux

Action on guest OS:
- Log in to guest OS
- Clear package manager cache
- Uninstall unnecessary apps
- Delete unnecessary files
- Clear logs
- Boot into vm via Linux Live USB iso
- Open terminal
- Install zerofree if not exist
- Run the command below
$ zerofree -v /dev/sdX
- Replace sdX with the actual partition like sda1, sda2 etc
- Shut down the vm

 Action on host OS:
- Open terminal and run VBoxManage command
$ VBoxManage modifymedium disk /path/your-vdi-image --compact

Monday, September 21, 2020

How to test Live USB on VirtualBox Linux...

Plugged in your USB pendrive.

Check your USB drive details:
$ sudo fdisk -l

Add your user to disk group:
$ sudo usermod -a -G disk $USER

Open terminal and run the command below (replace X with your drive). There's no need for sudo:
$ vboxmanage internalcommands createrawvmdk -filename ~/usb.vmdk -rawdisk /dev/sdX

Next open VirtualBox and create new vm. When in the hard disk option, use an existing virtual hard disk file. Select usb.vmdk file that you've created earlier in the previous step.

Complete setup.

Now you can start the newly created vm to test your Live USB.

Wednesday, March 2, 2011

Compacting/Shrinking virtual disk image...

Working on virtual machine with dynamic virtual disk gives an advantage to those with limited disk space. But after using it for a while (install/uninstall/copy/paste/delete), the actual size of your virtual disk image may have grown to nearly defined size, guest system reported that the disk usage was less than the size reported on host system. It should be fine provided if you have larger disk space. However, if that's not the case, than the best option would be to compact (known as shrink in VMWare) the virtual disk image.

In general, 3 steps are required to achieve this task
1) Disk cleanup / Defrag the hard drive on guest system

2) Execute "sdelete -c" to zero the free disk space before compressing the virtual disk image (sdelete tool was provided by Microsoft) on guest system
> sdelete -c [drive letter]
3) Compact the virtual disk image

VirtualBox user
Execute VBoxManage command on host system
$ VBoxManage modifyhd [filename] --compact
VMWare user
Shrinking needs to be done on guest system. Complete the first two steps above then:
1) Open VMWare tools by right click VM icon in system tray

2) Go to Shrink tab, under supported partitions, check the mount point checkbox

VMWare Tools Properties


3) Click "Prepare to shrink" and once ready, click "Yes" to proceed

Preparing shrink process


Ready to go


Shrinking in progress


If everything working as expected, virtual disk usage on both guest and host should be ~same

Note:
Test environment
Host: Linux Mint 10 64-bit
VirtualBox guest: Windows Server 2003 32-bit
VMWare guest: Windows 7 Profesional 64-bit

Friday, September 25, 2009

Bridge option (VirtualBox)...

An old post from my lost blog.

Finally...it's working


Finally...I'm able to use network bridge option for my vm under VirtualBox (after a lot of trial and error). Actually there's a bug in VirtualBox that will caused FireStarter (an interface for iptable) to stop working if I use bridging.

http://www.virtualbox.org/ticket/970

Fortunately, there's still a workaround even though it will be easy if I just remove FireStarter, but I really need it because without it, undoubtedly it's difficult for me to configure the firewall on my machine (I'm still at beginner level).

Guest ping Host OS


Host ping Guest OS


Guest ping another physical machine within the network


Steps need to be done on Host OS
1) Install the utilities
$ sudo apt-get install bridge-utils uml-utilities
2) Add your username as part of uml-net group
$ sudo gpasswd -a [your user name] uml-net
3) Open network interface
$ sudo gedit /etc/network/interfaces
4) Add the text below at the end of the line
auto tap0
    iface tap0 inet manual
    up ifconfig $IFACE 0.0.0.0 up
    down ifconfig $IFACE down
    tunctl_user [your user name]

    auto br0
    iface inet dhcp
    bridge_ports eth0 tap0
5) Restart network service
$ sudo /etc/init.d/networking restart
Note:
you can also use static ip instead of dhcp.

Virtual Machine Settings


Steps need to be done on virtual machine
1) Under Details tab go to Network option

2) Under Adapter 0 tab, enabled the network adapter and set the value
Attached to = Host Interface

3) Under Host Interface Settings set value
Interface Name = tap0

This should work fine if you're not using FireStarter. Otherwise below is an extra steps that need to be done. Before you proceed, let's do some checking.

1) Go to terminal and type
$ sudo iptables -nL
2) If the output is something as shown below. Then only we fix FireStarter.
Chain INPUT (policy ACCEPT)
    target prot opt source destination

    Chain FORWARD (policy ACCEPT)
    target prot opt source destination

    Chain OUTPUT (policy ACCEPT)
    target prot opt source destination

FireStarter


Steps need to be done to fix FireStarter
1) Edit FireStarter script
$ sudo gedit /etc/firestarter/firestarter.sh
2) Search for the text as shown below
if [ "$MASK" = "" -a "$1" != "stop" ]; then
        echo "External network device $IF is not ready. Aborting.."
        exit 2
    fi
3) Replace the text with the text below
#if [ "$MASK" = "" -a "$1" != "stop" ]; then
        # echo "External network device $IF is not ready. Aborting.."
        # exit 2
    #fi
4) Reboot your machine

5) Once your machine restarted, open FireStarter and go to Preferences

6) Under Firewall->Network Settings set your
Internet connected network device = eth0
Local network connected device = br0

7) Checked Enabled internet connection sharing

8) Click Accept button

FireStarter Settings