How to mount partitions from a disk image

No Comments

You can use the dd command to create images of disk drives, removable usb disks and so on.

If the disk you are making the image of has multiple partitions you cannot simply type “mount -o loop <image> <mount point>” to mount the resulting disk image file.

First you need to find the partitions offsets with the sfdisk command:

# sfdisk -l -uB image.iso
Disk image.iso: cannot get geometry
Disk image.iso: 973 cylinders, 255 heads, 63 sectors/track
Warning: The partition table looks like it was made
for C/H/S=*/4/32 (instead of 973/255/63).
For this listing I'll assume that geometry.
Units = blocks of 1024 bytes, counting from 0
Device Boot   Start       End    #blocks   Id  System
image.iso1   *       16     31231      31216    e  W95 FAT16 (LBA)
image.iso2        32256   7265599    7233344   83  Linux
image.iso3            0         -          0    0  Empty
image.iso4            0         -          0    0  Empty

With this information you can calculate the starting offset of each partition by multiplying the start block by the block units in bytes (1024 bytes in this case):

# echo $(( 32256 * 1024 ))
33030144
# echo $(( 16 * 1024 ))
16384

Mounting is easy now, you specify the file system type and the partition offset. To mount the first partition on the example file above:

# mount -o loop,offset=16384 -t vfat image.iso /mnt/

To mount the second partition:

# mount -o loop,offset=33030144 -t ext2 image.iso /mnt/

Here you go! Hope it helps!

Civilization V strategies

No Comments

Civilization V new features likes policies, city-states and non-stacked units require new strategies to be developed.

Here is a list of strategies to succeed in the game:

  • Stay ahead in science. Research Writing early and build a library and the National College wonder while you have only one city. To build the National College each city needs to have a library so it is better to build it early.
  • Focus on Gold. Gold will increase research and will allow you to provide gold gifts to city-states.
  • Be allied with city-states. They can provide you with units, culture, gold, resources and research. It can be expensive so the Patronage policies are a good idea. If you are playing a game with diplomatic victory enabled, city-states will help you succeed.
  • Eliminate other players early. Specially if they are militaristic they’ll hunt you sooner or later. Use archers and warriors. Attack with all units at the same time on the same city. Don’t divide your army unless you have enough units.
  • Increase your culture as much as possible.
  • Increase the generation of great people as much as possible, for example building the Garden city improvement. Great scientist can provide you with free technology and Great engineers can speed up the construction of wonders.

Cannot load windows after removing the linux partition

No Comments

If you had Windows and Linux running on your system and just formatted the Linux partition you probably can’t load Windows anymore because the boot loader can’t load its configuration.

To solve this problem boot your pc using a Linux installation cd-rom that uses grub as the boot loader (typically right after the system boots it will show the boot loader menu) – recent distributions have fancy boot loaders with graphical interfaces, avoid those for this.

Use Backtrack Linux for example.

On the grub meny type ‘c’ for a command line and then type the following commands:

grub> rootnoverify (hd0,0)

grub> chainloader+1

grub> boot

You should be booting into Windows XP.

Now to restore your Windows MBR download MbrFix from www.sysint.no and unzip it to a local folder.

Open the command prompt and enter the following command:

Mbrfix.exe /drive 0 fixmbr

Press Y and you should have your MBR fixed. You can reboot your system.

Virtual Box: using raw hard disk feature to access an external USB storage device

No Comments

Using Virtual Box 4.0.8 for MAC OSX 10.6.7 I was unable to access data on my external USB disk on a Windows 7 guest machine.

No solution was found after searching the web although there are similar issues out there like:

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

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

I was almost ready to give up when I found page 142 on the Virtual Box manual. Section 9.7.1 tells how to configure a physical disk to be accessed as if it was attached to the guest/virtual machine.

So the guest OS instead of accessing the disk using the USB bus it would access using the SATA or IDE bus.

There’s a warning on that page that I’m copying here:

Warning: Raw hard disk access is for expert users only. Incorrect use or use of an outdated configuration can lead to total loss of data on the physical disk. Most impor- tantly, do not attempt to boot the partition with the currently running host operating system in a guest. This will lead to severe data corruption.

Following the instructions on that section I could access my external USB drive successfully.

This is what I did, remember that I’m using OSX as host operation system.

Connected my usb drive. OSX automatically mounts it.

Opened a terminal and wrote mount to find which /dev device is the disk mapped to. It was /dev/disk1s1:

$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
/dev/disk0s3 on /Volumes/BOOTCAMP (ntfs, local, read-only, noowners)
/dev/disk1s1 on /Volumes/SergioDrive (exfat, local, nodev, nosuid, noowners)

Now before using it on virtual box I unmounted it on OSX:

$ diskutil unmount /Volumes/SergioDrive
/Volume SergioDrive on disk1s1 unmounted

Now I created the virtual box image file that I’ll use to configure my virtual machine:

$ VBoxManage internalcommands createrawvmdk -filename ~/VBAccessToSergioDrive.vmdk -rawdisk /dev/disk1s1
RAW host disk access VMDK file /Users/machados/VBAccessToSergioDrive.vmdk created successfully.

Now you can use the virtual box gui to add the image file as a disk to the virtual machine. This is done under the storage definitions. I added another disk under SATA controller.

This can also be done on the command line with this command:

$ VBoxManage storageattach "Windows 7" --storagectl "SATA Controller" --port 1 --device 0 --type hdd --medium ~/VBAccessToSergioDrive.vmdk

The command has no output. Of course “Windows 7″ is the name of my virtual machine.

This image file can only be used with the same physical external disk because it maps the UUID of the disk.

How to make network manager ignore a networking device

No Comments

This was done on Ubuntu 10.10.

My laptop has a built in wifi device but it doesn’t supports the N norm.

I bought a new wifi device and I want network manager to ignore the built in.

To do that I added the following line to /etc/network/interfaces:

iface eth1 inet manual

This makes eth1 configuration manual and network manager ignores it.

How to make Ralink rt2870 driver work on Ubuntu 10.10

17 Comments

This works with Ubuntu 10.10 and a usb wifi adapter with the Ralink rt2870 chipset.

The driver released with Ubuntu kernel 2.6.35-22-generic is version 2.1.0.0 and doesn’t work…

I downloaded version 2.4.0.1 from Ralink web site and compiled it the following way.

cd /usr/src
tar xvfj /tmp/2010_0709_RT2870_Linux_STA_v2.4.0.1.tar.bz2
cd 2010_0709_RT2870_Linux_STA_v2.4.0.1/
sed -i.bak "s/HAS_WPA_SUPPLICANT=n/HAS_WPA_SUPPLICANT=y/" os/linux/config.mk
sed -i.bak "s/HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n/HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y/" os/linux/config.mk

Changed file include/os/rt_linux.h line 1077 to:

#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr) usb_alloc_coherent(pUsb_Dev, BufSize, GFP_ATOMIC, pDma_addr)

And line 1078 to:

#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr)        usb_free_coherent(pUsb_Dev, BufSize, pTransferBuf, Dma_addr)

Then compiled it:

make

Removed the Ubuntu released driver out of the way:

mv /lib/modules/`uname -r`/kernel/drivers/staging/rt2870 ~/.rt2870.bak

And installed the new one:

make install

Also removed the rt2800 module out of the way:

echo 'blacklist rt2800usb' >> /etc/modprobe.d/blacklist.conf

And rebooted my pc.

After the system booted up the new driver was loaded:

# modinfo rt2870sta | grep -i version
version: 2.4.0.0
srcversion: 5598BFE60F8B720D8D64062
vermagic: 2.6.35-22-generic SMP mod_unload modversions 686

Also I could connect to my wireless network at 130Mb/s (from the output of nm-tool).

Connecting an USB storage device to a vmware guest

No Comments

Although the instructions herein might apply to other releases of software this article assumes that you are using Windows 7 64bit as a host operating system, VMWare Server 2.0.2 and Ubuntu 10.04 as guest operating system. It is also assumed that the guest operating system is installed and working.

Note that when the usb storage device becomes available to the guest operating system, it becomes unavailable to the host operating system. So you should save and close any file/document open from the same storage device.

Before you start, make sure the guest virtual machine is stopped and logout from VMWare server.

Start by finding the vendor id and product id of the storage device. The best way to do this is to open the latest vmware log file. It is located in the same directory where the vmx files for the guest virtual machine are.

Once you have the latest vmware log file open, search for the string “USB: Found device” without the quotes.

You’ll find something similar to:

Sep 03 14:14:35.759: vmx| USB: Found device [name:Wacom\ USB\ Composite\ Device vid:056a pid:00d1 path:1/0/2 speed:full family:hid,hid-bootable]
Sep 03 14:14:35.759: vmx| USB: Found device [name:Seagate\ RSS\ USB\ Mass\ Storage\ Device vid:0bc2 pid:2100 path:1/1/1 speed:high family:storage]
Sep 03 14:14:35.759: vmx| USB: Found device [name:Realtek\ RTL8187\ Wireless\ 802.11b/g\ 54Mbps\ USB\ 2.0\ Network\ Adapter vid:0bda pid:8187 path:1/1/9 speed:high family:other]

From that listing you should be able to locate your usb storage device. Once you have found it, copy the vid and pid values from the respective line. For example:

vid:0bc2 pid:2100

Now, run notepad as administrator (right click on the Notepad icon found in Start > All Programs > Accessories menu and select ‘Run as Administrator’).

Click ‘Yes’ on the security question to allow Notepad to be run as administrator.

Now press Ctrl+O to open the vmx configuration file. On the lower right corner of the Open File dialog there is a combo box where, by default, “Text Documents (*.txt)” will be selected. Change that to “All Files (*.*)”.

Now locate the directory were your guest machine configuration files are (likely to be under C:\Virtual Machines) and open the file with .vmx extension.

Scroll down to the bottom of the file and enter the following on a new line (replace the contents within quotes with your vendor and product id found above):

usb.autoConnect.device0="vid:0bc2 pid:2100"

Save and close the file.

Now start your guest virtual machine. If you are using Ubuntu 10.04 your USB device will be automatically shown on your desktop.

You’ll also notice that a notification on Windows 7 will show up notifying you that a device driver for vmware was installed successfully.

Skype on Ubuntu Linux 10.04

2 Comments

There are some issues with version 2.1.0.81 of Skype on Ubuntu Linux (possibly other distributions as well).

The first issue is the default theme on Skype versus the one for Ubuntu. The default theme on Skype configured menu text with dark colors and the default Ubuntu theme configures menus with dark background. This makes the menu text mostly invisible.

Luckily by moving the mouse pointer over the menu the background highlight makes the text visible.

To change this permanently select “Options” from the Skype menu on the bottom left corner of the Skype window or press CTRL+O.

On the “General” section change the style from “Cleanlooks” to “Desktop Settings”. Close and restart Skype. Now you should see the menu text clearly.

The second issue is a problem with the video camera. This might or might not happen to you. It is a known problem with a workaround on the Skype release notes:

Skype does not work well with newer version of GSPCA Webcams driver (Linux Kernel >=2.6.27), possible workaround:

  • Ubuntu 32 bit: install “libv4l-0″ package and launch Skype with: LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype
  • Ubuntu 64 bit: install “lib32v4l-0″ package and launch Skype with: LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so skype
  • Other distributions might have the same library, but may have a different path.
  • In my case I already had the package ??libv4l-0 installed. If that’s not your case, or if you’re not sure, run on a terminal window:

    sudo aptitude install libv4l-0

    With the library installed you cannot simply start Skype from the start menu because the variable LD_PRELOAD needs to be customized for Skype.

    So you have to start it from a terminal window or change Ubuntu menu. To change Ubuntu menu do the following:

    • Open the System > Preferences menu and select “Main Menu”
    • On the left select the “Internet” menu and on the right select “Skype”.
    • Click “Properties”.
    • On “Command:” replace the default command with: bash -c “LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype”

    Now every time you start Skype your video should work.

    Move grub from internal disk to external storage

    2 Comments

    When I installed Ubuntu Linux on my USB 8GB stick I didn’t noticed where grub was being installed. After a while I noticed that I could only boot my Windows installation (on the internal hard drive) via the USB 8GB stick.

    What happened was that Ubuntu install changed the master boot record (MBR) of my internal drive and set it up to load the remaining of Grub (it is split in 2 because otherwise it wouldn’t fit on the MBR) from the USB storage.

    To fix this I could use the Windows tools (fixmbr) but that requires me to boot using the recovery console and login as system administrator. Although using fixmbr would restore the Windows boot loader it would erase grub and make the USB storage  not bootable.

    What worked for me was MbrFix from sysint (www.sysint.no). REMARK: following the instructions below might make your computer unusable and eventually make you lose data.

    First I got the list of partitions on my internal disk:

    C:\>MbrFix.exe /drive 0 listpartitions
    # Boot Size (MB) Type
    1 Yes     76316    7  NTFS or HPFS
    2             0    0  None
    3             0    0  None
    4             0    0  None

    Next I saved my internal disk mbr to a file:

    C:\>MbrFix.exe /drive 0 savembr Backup_MBR_0.bin

    Next I listed my partitions on my USB disk drive:

    C:\>MbrFix.exe /drive 1 listpartitions
    # Boot Size (MB) Type
    1          6440  131  Linux native (usually ext2fs)
    2          1223  130  Prime
    3             0    0  None
    4             0    0  None

    Now I want to put grub on my USB disk:

    C:\>MbrFix.exe /drive 1 restorembr Backup_MBR_0.bin
    You are about to Restore MBR,
    are you sure (Y/N)? Y

    Now let’s see how the partition looks like:

    C:\>MbrFix.exe /drive 1 listpartitions
    # Boot Size (MB) Type
    1 Yes     76316    7  NTFS or HPFS
    2             0    0  None
    3             0    0  None
    4             0    0  None

    Ups! what happened there? My Linux partitions are gone… Let me try and fix this…

    C:\>MbrFix.exe /drive 1 /partition 1 setpartitiontype 131
    You are about to Set partition type,
    are you sure (Y/N)? Y
    Partition 1, type before: 7 NTFS or HPFS
    Partition 1, type after: 131 Linux native (usually ext2fs)
    
    C:\>MbrFix.exe /drive 1 /partition 2 setpartitiontype 130
    You are about to Set partition type,
    are you sure (Y/N)? Y
    Partition 2, type before: 0 None
    Partition 2, type after: 130 Prime
    
    C:\>MbrFix.exe /drive 1 listpartitions
    # Boot Size (MB) Type
    1 Yes     76316  131  Linux native (usually ext2fs)
    2             0  130  Prime
    3             0    0  None
    4             0    0  None

    Looks like by setting the partition types back to their original values solved the problem.. yes it did.. ufff…

    Now let’s restore the original Windows boot loader on the internal disk:

    C:\Documents and Settings\machados\My Documents\Downloads>MbrFix.exe /drive 0 fixmbr
    You are about to Fix MBR,
    are you sure (Y/N)? Y

    Now I could boot the system without the USB disk connected to my laptop.

    I could also boot my Linux system by connected the USB disk and selecting “boot from usb storage” from my bios boot menu.

    Installing VirtualBox additional tools on Ubuntu 9.10 Karmic Koala

    2 Comments

    This procedure was tested on VirtualBox 3.0.12 for Windows and Ubuntu 9.10 Server 32 bit as Guest.

    To be able to enjoy seamless integration between the host operating system and the VirtualBox guest you have to install VirtualBox Additional Tools on the guest operating system.

    To do so, follow the steps:

    Ensure you have a working Internet connection.

    Step 1:

    Install requirements for the Additional Tools:

    sudo apt-get install gcc linux-source-virtual linux-headers-virtual dkms
    

    Reboot after installation.

    Step 2:

    After logging in again find the Install Additional Tools option on the Devices menu.

    Then on your guest mount the cdrom:

    sudo mount /media/cdrom
    

    Step 3:

    Now install the tools:

    cd /media/cdrom
    ./VBoxLinuxAdditions-x86.run

    This will install the additional tools for virtual box.

    Reboot your system and you’re all set.

    Older Entries