Monday, April 14, 2014

Expanding an Existing VirtualBox Disk

Issue

You have spent ages installing an operating system onto a VirtualBox virtual disk, but now find that after updates and software installations that most of the disk space has already been used. 

What to do?

Reinstall on a new larger VirtualBox virtual disk?
No!

Fortunately existing VirtualBox virtual disks can be resized with VBoxManage and then GParted can be used to resize the existing partition to fill up the extra space created by VBoxManage from within the virtual machine.

This page describes a simple procedure to use to increase the storage capacity of an existing VirtualBox virtual disk.

Procedure

This example procedure demonstrates how to increase the capacity of an existing virtual disk used in a Windows Virtual Machine.

Ideally you want your existing VirtualBox virtual disk to be in vdi format, but even it if it is in another format (vmdk in this example) its capacity can still be expanded by simply cloning the disk from vmdk to vdi format. A vmdk disk simply means an additional step (Step 1) not needed for a vdi disk.

Step 1
Skip this step if your virtual disk is already in vdi format.

VBoxManage clonehd Input.vmdk Output.vdi --format vdi

Step 2
VBoxManage modifyhd Output.vdi --resize 40960

Note --resize expects the new disk size in MegaBytes, here we show 40960 MB which is equivalent to 40 GB.

Step 3
Remove the original virtual disk from the Virtual Machine and replace it with the newly created (expanded) vdi virtual disk.

Step 4
Download the GParted.iso and then use it as bootable CD in the Virtual Machine.

Step 5
Boot up the Virtual Machine, which will then run GParted, resize the existing partition to fill the now larger disk. Then close down the Virtual Machine.

Step 6
Remove the GParted.iso from the Virtual Machine so that it will boot up normally.

Boot the Virtual Machine. Assuming it is a Windows Virtual Machine then Windows will give an error message.

Don't do anything!

Let Windows automatically update the virtual disk to the new size.

Let Windows make the necessary corrections.

Once Windows boots up you should have an expanded virtual disk that fully utilises the extra space you created in Step 2.

Finished!

Well Done!

======================================================

Further Reading

How-to-Geek : How To Enlarge a Virtual Machine’s Disk in VirtualBox or VMware

How to resize a VirtualBox vmdk file

Resize your /dev/sda1 disk of your Vagrant / VirtualBox VM

How to increase hard disk size after installing a guest OS?

======================================================


Converting Videos for the iPhone 5s

Overview

This page describes how to use the free software HandBrake to convert video files into a format suitable for playing on the iPhone 5s and iPod Touch.

HandBrake comes in two versions:
  1. Graphical user interface version (HandBrake), suitable for converting a small number of video files manually
  2. Command line version (HandBrakeCLI) that is best suited for converting multiple files automatically via a Bash shell script.
The operating system used in these examples is a version of Linux Ubuntu (Mint KDE Nadia). HandBrake runs on Mac and Windows as well as Linux. For multiple video conversions a simple Bash shell script is provided that uses HandBrakeCLI.

Two Bash shell scrips are provided:

(a) General script for converting any videos into .mp4
(b) Specific script that only converts .mp4 files.

Introduction

Long before I purchased an Apple iPhone 5s, I knew that my favourite video container (MKV) was not directly supported on Apple hardware. While it is possible to install Apps that will play MKV video files I wanted to be able to use the iPhone's native media software. It was obvious that I would need to find a reliable and easy method to convert multiple video files into the correct video format for an iPhone.

A quick look at the Apple 5s technical specifications shows that the following video formats are supported by the iPhone 5s:

(i) H.264 video up to 1080p, 60 frames per second, High Profile level 4.2 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4 and .mov file formats;

(ii) MPEG-4 video up to 2.5 Mbps, 640x480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps per channel, 48kHz, stereo audio in .m4v, .mp4 and .mov file formats;

(iii) Motion JPEG (M-JPEG) up to 35 Mbps, 1280x720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format

For space and quality reasons I chose the H.264 video codec, AAC audio codec and mp4 container specification. The key is that not all .mp4 files will play on an iPhone and so must be converted into the iPhone compatible mp4 format via HandBrake / HandBrakeCLI .

HandBrake / HandBrakeCLI provides a preset(--preset="iPhone & iPod touch") that converts videos into a suitable specification that will play on iPhone and iPod Touch devices. So it was simply question of using HandBrake's iPhone and iPod Touch preset.

======================================================

(a) Bash Script for Converting any videos into iPhone .mp4 format

#!/bin/bash
clear
clear
echo  "Start of $0"
echo
## This is to stop Bash breaking on Spaces and force it to break at the End of each Line.
IFS=$'\n'

count=0
# Change this input directory to suit you if you are not already in the source media directory.

# cd "/WinF/Inputs"

for i in *.*
do
echo "Starting $i"
echo
#j=$(basename $i .*)

j=${i%.*}

echo -e "$i WITHOUT original EXTENSION is \n$j"
echo


echo -e "New filename without old Extension is :   \n$j"
echo

# Here we output the files into the directory /WinF/HandBrake-Output obviously change this to to suit you.

# Choose a HandBrakeCLI preset from 
# HandBrakeCLI --preset-list

#HandBrakeCLI -i "$i" --preset="iPad" -o /WinF/HandBrake-Outputs/$j.mp4

HandBrakeCLI -i "$i" --preset="iPhone & iPod touch" -o /WinF/HandBrake-Outputs/$j.mp4

# Following example from 

# ffmpeg -i "$i" -ab 256k "${i%m4a}mp3"
let count=$count+1
echo
echo "====================================================================================="
echo
echo "$i done"

echo "Files processed=$count"
sleep 10

echo
echo "====================================================================================="
echo

done
======================================================

(b) Bash Script for Converting .mp4 files into iPhone .mp4 format


#!/bin/bash
clear
clear
echo  "Start of $0"
echo
## This is to stop Bash breaking on Spaces and force it to break at the End of each Line.
IFS=$'\n'

count=0

# Change this input directory to suit you.
cd "/WinF/Inputs"

for i in *.mp4
do
echo "Starting $i"
echo
j=$(basename $i .mp4)

echo -e "$i WITHOUT MP4 EXTENSION is \n$j"
echo

echo -e "New filename with MP4 extension removed is :   \n$j"
echo

# Here we output the files into the directory /WinF/HandBrake-Output obviously change this to to suit you.

#HandBrakeCLI -i "$i" --preset="iPad" -o /WinF/HandBrake-Outputs/$j.mp4

HandBrakeCLI -i "$i" --preset="iPhone & iPod touch" -o /WinF/HandBrake-Outputs/$j.mp4


# Following example from 
# ffmpeg -i "$i" -ab 256k "${i%m4a}mp3"

echo
echo "====================================================================================="
echo

echo "$i done"

echo "Files processed=$count"

let count=$count+1

sleep 10

echo
echo "====================================================================================="
echo

done
======================================================

Further Reading 



HandBrake Downloads

HandBrakeCLI

HandBrake Guide

======================================================