jump to navigation

Migrate a virtualbox VM to a bigger virtual disk 2012-03-18

Posted by claudio in Uncategorized.
Tags: , , , ,
3 comments

When a virtual machine has limited use, you don’t want to loose too much space. Sometimes, however, you get the size wrong.

In my case, I have a minimal Windows VM on my Ubuntu laptop. Once in a while I test an upcoming Padre (The Perl IDE) release or update a crappy usb device with Windows-only support. Win-modems may be gone, but we still have GPS devices that run GNU/Linux but can only be connected to Windows. (I guess seeing your market-share shrink because of smart-phones is what they call bad karma, TomTom.)

Windows being Windows, adding disks is a terrible experience (what’s up with the alphabet as a mounting point?) and moving a Windows installation to a second disk is a nightmare. Luckily, free software gets the job done:

1. Make sure your guest machine is halted properly. This is specially important for a NTFS (virtual) partition of a Windows VM.

2. Download Ubuntu (It does not matter if you use the 32- or the 64-bit version, other GNU/Linux distribution will work as well). The screenshots are from a Ubuntu 11.10 setup.

3. In the specific VM-settings, add a new disk (to the same disk controller) and a new cdrom. Load the Ubuntu iso in the virtual cdrom drive.

 

4. Make sure the VM boots from the cdrom.

 

5. “Try” Ubuntu. Once Ubuntu is loaded, launch “gparted”.

 

6. Select the old disk (normally the first one, check the size).

 

7. Right on the disk representation and “copy” it.

 

8. Select the new disk from the combo-box on the upper right (check the size).

9. Go to “Device”, choose “Create Partition Table…”. Click “Apply” in the pop-up window.

 

10. Right on the disk representation and “paste” the original disk. Click “Apply” in the pop-up window.

11. Click on the green “Apply tick” on the icon menu to apply the changes. This will take some time. Get some coffee.

 

12. Right on the disk representation and select “Manage Flags”. Enable “boot”.

13. Shut down the Ubuntu Live cd.

 

14. Remove the original disk from the VM configuration (back it up first).

 

That’s it!

Advertisements

Define the main screen in Ubuntu Unity dual screen setup 2011-05-13

Posted by claudio in Uncategorized.
Tags: , ,
6 comments

I use a dual screen setup at home. On the left side I have a big lcd screen and on the right the fixed screen of the laptop (on a docking station). The big screen is my main screen, while the smaller screen is for things I like to keep open like mail or an irc session (ssh+screen+irssi).

In this new install, the unity global menu can be found on the smaller screen.This probably makes sense on a lot of setups, but I prefer this icon menu on my main screen as it feel more accessible (it’s physically closer) and it autohides anyway.

I did not find a graphical way to set this up, but editing the configuration file is very easy:

$ vi ~/.config/monitors.xml

or if you prefer a graphical editor:

Press Alt + F2 and type “gnome-text-editor ~/.config/monitors.xml”

Identify you main monitor (name, resolution, etc) and change “no” into:

<primary>yes</primary>

That’s it.

Create an encrypted partition/usb disk 2009-12-02

Posted by claudio in Uncategorized.
Tags: , ,
2 comments

Update 2016/09/08: on recent Ubuntus (e.g. 16.04) you can use the graphical “disks” application to create a Luks+ext4 partiton. The defaults are sane. However, it’s still advisable to put random data on the new disk before encryption. This howto is still useful for non-X setups.
Update 2012/03/18: up to date with Ubuntu 11.10.
Update 2010/04/30: Addition for the new 4KB block size drives.

If you are like me and use a laptop as your main computer, you will run out of space very soon. USB disks are a great alternative to store your photography or music collection or, simply, files you don’t use everyday. I always keep backups off-site (a USB disk) and I want to have those encrypted. This is what I did (open a shell):

  1. Install the cryptography software:
    $ sudo apt-get install cryptsetup
  2. Write some random data to your disk (we will assume it’s called /dev/sdx, type “dmesg” after inserting the disk to figure out the device, or if it’s windows formatted and automounted have a look at the output of “mount”):
    $ sudo dd if=/dev/random of=/dev/sdx bs=4K
    This will taken a long time, at least a few days (create some IO). A good -shorter- compromise (a day) will be:
    $ sudo badblocks -c 10240 -s -w -t random -v /dev/sdx
  3. Create a new Linux partition table with cfdisk (create new partition table if asked, chose New and assign all the disk, use a primary partition).
    $ sudo cfdisk /dev/sdx
  4. Setup a partition using fdisk (compatible with the new 4KB block size drives):
    $ sudo fdisk -uc /dev/sdx

    Command (m for help): d
    Selected partition 1
    Command (m for help): n
    Command action
    e   extended
    p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First sector (2048-2930277167, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-2930277167, default 2930277167):
    Using default value 2930277167
    Command (m for help): t
    Selected partition 1
    Hex code (type L to list codes): 83
    Command (m for help): p
    Disk /dev/sdx: 1500.3 GB, 1500301910016 bytes
    81 heads, 63 sectors/track, 574226 cylinders, total 2930277168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x4fabbfc4
    Device Boot      Start         End      Blocks   Id  System
    /dev/sdx1         2048  2930277167  1465137560   83  Linux
    Command (m for help): w
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    Syncing disks.
  5. Create the encrypted partition. Make the paraphase long and difficult to guess:
    $ sudo cryptsetup --verbose --verify-passphrase luksFormat /dev/sdx1 -c aes-cbc-essiv:sha256
  6. Create a filesystem (I am using ext4, the chose device and label name is “disk5”, change it to your taste):
    $ sudo cryptsetup luksOpen /dev/sdx1 disk5
    $ sudo mkfs.ext4 /dev/mapper/disk5 -L disk5
    $ sudo cryptsetup luksClose disk5
  7. Mount it going to “Computer” in Nautilus, double clicking the disk and inserting your paraphrase. I chose not let Gnome store the encrypting paraphrase for automounting as it would make encryption as weak as your system password (and we know how to retrieve/change those)…

 

That’s it!

Split one flac (+ cue) file into separate tracks (update: including embedded cue files, ape) 2009-02-09

Posted by claudio in Uncategorized.
Tags: , ,
add a comment

flac

You may have backupped your music cd’s using a single flac file instead of a file for each track. In case you need to split the cd-flac, do this:

Install the needed software:

$ sudo apt-get install cuetools shntool

Split the album flac file into separate tracks:

$ cuebreakpoints sample.cue | shnsplit -o flac sample.flac

Copy the flac tags (if present):

$ cuetag sample.cue split-track*.flac

The full howto can be found here (aidanjm).

Update (April 18th, 2009):
In case the cue file is not a separate file, but included in the flac file itself do this as the first step:

$ metaflac --show-tag=CUESHEET sample.flac | grep -v ^CUESHEET > sample.cue

(NB: The regular syntax is “metaflac –export-cuesheet-to=sample.cue sample.flac“, however often the cue file in embedded in a tag instead of the cuesheet block).

Update (March 5th, 2017):
In case the source file is one unsplitted ape file, you can convert it to flac first.

$ sudo apt-get install ffmpeg

$ ffmpeg -i sample.ape sample.flac

Tips & Tricks: merge postscripts or pdf files 2008-06-28

Posted by claudio in Uncategorized.
Tags: , , , ,
add a comment

It’s nice that firefox 3 can directly create pdfs (print, select print to file). However, while doing research and creating pdfs of articles, some were split in different pages (or needed additional information, like citation information). Here’s how to merge those pdfs from the command line:

$ gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=result.pdf input1.pdf input2.pdf input3.pdf

Change the PAPERSIZE value to “letter” if you live where the use that format. “result.pdf” is the result of merging “input1.pdf”, “input1.pdf” and “input1.pdf”. Change the values to fit your files.

VirtualBox: Install Windows XP using pbx boot 2008-06-24

Posted by claudio in Uncategorized.
Tags: , , , , , ,
16 comments

VirtualBox is a great product for a developer (or even a regular user) to run several OSes simultaneously. I run Linux on my laptop, but I need a Windows partition with certain software and updates to connect to the work network. A virtual machine is a fine solution. Specially when running in seamless mode (only the program is open in your Linux desktop and not the complete Windows desktop).

Installing Windows from cd on a VirtualBox instance is really easy. However, I need a *specific* windows installation that can only be installed from a Windows PXE server at work. Sadly, the virtualbox open source edition delivered with Ubuntu 8.10 is unable to do this. This is what I did: (more…)

How to change the default shell editor in Ubuntu 2008-06-18

Posted by claudio in Uncategorized.
Tags: , , , ,
1 comment so far

Using nano as the default shell editor is probably a great choice for a Gnu/Linux distribution (also) aimed for Unix newbies. If you know your way on the command line however, you’ll scream from frustration for every “i”, “:wq!” or “ZZ” you type and you see the characters in the text you are editing. Specially frustrating in cron. If you don’t know what “i”, “:wq!” or “ZZ” do, don’t worry, nano is working fine for you. (more…)

Create html from a chm file 2008-05-04

Posted by claudio in Uncategorized.
Tags: ,
add a comment

Microsoft crew 1978

Sometimes documentation can be found in the horrible chm format (Microsoft compiled html). There are UNIX viewers to see these kind of files (gnochm, xchm, etc) but it is nicer to have it in a more flexible format (print, search, edit): html. I use “extract_chmLib” for this.

Extract the file documentation.chm to directory documention:

$ extract_chmLib documentation.chm documentation

Use external functions/modules in korn shell (ksh) 2007-08-07

Posted by claudio in Uncategorized.
Tags: , , , , , ,
1 comment so far

The korn shell is a great shell to write shell scripts. Some functionalities are really nice. By example, you can write your functions or modules in a separate file and use it within your program. The secret lies in the FPATH environment variable. (more…)