2011-12-19

Grub2 Configuration Examples

Grub2 Configuration Examples

ABSTRACT
I use Ubuntu11.10 as my "main Operating System (OS)" that uses GRUB2 to boot.
In order several other OS, I added my own boot entries to Grub.

Bellow you will find GRUB entries than allows me to boot the following OSes:
  • Ubuntu 11.10
  • Windows Vista
  • CentOS release 6.1
  • Puppy Linux 5.2.2
  • Parted Magic 2011_11_24
  • Parted Magic 2011_11_24 from an ISO image file
  • Oracle VM (OVM) 3.1

MY DISK AN PARTITIONING STRUCTURE

In order to understand how to access the partitions from GRUB2 i need to know the partitioning structure of my disks.
Where the several OS are located.

The Structure of my two Disks (sda 1TB and sdb 3TB) using the command "df":
root@ubu11:/etc/grub.d# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 49G 31G 19G 63% /media/565EC2BA5EC291E3
/dev/sda2 786G 111M 785G 1% /media/Backup
/dev/sda3 485M 53M 407M 12% /media/4e3a3a1c-5a1e-48d3-bf31-abc1f621ef10
/dev/sdb2 481G 58G 400G 13% /
/dev/sdb4 2.3T 194G 2.0T 10% /media/Data

The Structure of my Disk (sda 1TB) using "fdisk" (i could not display the structure of the 3 TB disk using this program):
root@ubu11:/etc/grub.d# fdisk /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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: 0x00000001

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 102414374 51206163+ 7 HPFS/NTFS/exFAT
/dev/sda2 102414375 1748723444 823154535 7 HPFS/NTFS/exFAT
/dev/sda3 1748723712 1749747711 512000 83 Linux
/dev/sda4 1749747712 1953523711 101888000 5 Extended
/dev/sda5 1749749760 1953523711 101886976 8e Linux LVM


AUTOMATICALLY GENERATED ENTRIES
Grub2 automatically generate entries by "autoprobing" exitent bootable OSes.

In the generated file "/boot/grub/grub.cfg" I got find the following entries (besides others) generated during the installation and update.

The entry of the own (main) Ubuntu 11.10 OS:
menuentry 'Ubuntu, with Linux 3.0.0-14-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod gzio
insmod part_gpt
insmod ext2
set root='(hd1,gpt2)'
search --no-floppy --fs-uuid --set=root a76be1e4-00f2-4282-953f-751eceac0ad1
initrd /boot/initrd.img-3.0.0-14-generic
}

linux /boot/vmlinuz-3.0.0-14-generic root=UUID=a76be1e4-00f2-4282-953f-751eceac0ad1 ro quiet splash vt.handoff=7
And the Windows Vista entry that GRUB2 automatically generated by its OS probing functionality:
menuentry "Windows Vista (loader) (on /dev/sda1)" --class windows --class os {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 565EC2BA5EC291E3
chainloader +1
}


MY OWN HAND WRITTEN ENTRIES
Perform the following steps as "root":
# cd /etc/grub.d/
# vim -g 40_custom

Append the following entries to the file " /etc/grub.d/40_custom ":

#-------------------------------------------------------------------------------------------------
# I have two hard disks
# 1st) SATA SAMSUNG HD 103UJ - 1 TB => /dev/sda
# 2nd) SATA Hitachi HDS7203 - 3 TB => /dev/sdb
#
# I configured the BIOS to boot from the 2nd HD containing Ubuntu 11.10 as main OS with GRUB2.
# This file contains the own configuration of this GRUB2.

# In the configuration entries bellow the following HD GRUP mapping is used:
# Physical HD GRUB2 Notation
# --------------- -------------------------------
# 1st HD /dev/sda (hd1, ...) i.e. 2nd HD for GRUB
# 2nd HD /dev/sdb (hd0, ...) i.e. 1st HD for GRUB
# GRUB2 seems to regard the own HD (from which the Computed gets
# booted) as the first one and the other as the second.
#-------------------------------------------------------------------------------------------------


# Physically this OS is installed on the 1st HD, on the 3rd partition.
# For GRUB on the 2nd HD, 3rd partition => (hd1, msdos3)
# I do not know why, but I needed to use "insmod ext2" in order to see the 3rd partition and needed
# to use "msdos3" in order to access it.
# (I do not know if the other insmod are realy needed. I did not try without them.)
menuentry "CentOS release 6.1 (on /dev/sda2)" {
insmod gzio
insmod part_gpt
insmod ext2
insmod part_msdos
set root='(hd1,msdos3)'
linux /vmlinuz-2.6.32-131.0.15.el6.x86_64 ro root=/dev/mapper/vg_cent-lv_root rd_LVM_LV=vg_cent/lv_root rd_LVM_LV=vg_cent/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=sg-latin1 crashkernel=auto rhgb quiet
initrd /initramfs-2.6.32-131.0.15.el6.x86_64.img
}

# Boots the directory "/PuppyLinux522" on the same HD as GRUB (1st HD, 2nd Partiton => "(hd0,gpt2)")
# This is the same partition as the one where this file GRUB configuration file is stored.
menuentry "Puppy Linux 5.2.2 (auf /PuppyLinux522)" {
insmod ext2
set root='(hd0,gpt2)'
search --no-floppy --fs-uuid --set=root a76be1e4-00f2-4282-953f-751eceac0ad1
linux /PuppyLinux522/vmlinuz pdev=sdb2 psubdir=PuppyLinux522
initrd /PuppyLinux522/initrd.gz
}

# Boots the directory "/PMagicLinux" on the same HD as GRUB (1st HD, 2nd Partiton => "(hd0,gpt2)")
# This is the same partition as the one where this file GRUB configuration file is stored.
mmenuentry "Parted Magic 2011_11_24 (auf /PMagicLinux)" {
recordfail
insmod gzio
insmod part_gpt
insmod ext2
insmod part_msdos
set root='(hd0,gpt2)'
search --no-floppy --fs-uuid --set=root a76be1e4-00f2-4282-953f-751eceac0ad1
linux /PMagicLinux/pmagic/bzImage root=/dev/sdb2 directory=PMagicLinux edd=off noapic load_ramdisk=1 prompt_ramdisk=0 rw vga=791 loglevel=0 max_loop=256 keymap=de_CH-latin1
initrd /PMagicLinux/pmagic/initrd.img
}

# Boots the ISO image file "pmagic_2011_11_24_x86_64.iso" in the directory "/ISOs" on the same HD
# as GRUB but on another partition (1st HD, 4nd Partiton => "(hd0,gpt4)")
menuentry "Parted Magic 2011_11_24 ISO (on (hd0,gpt4)/ISOs/pmagic_2011_11_24_x86_64.iso" {
set isofile="/ISOs/pmagic_2011_11_24_x86_64.iso"
loopback loop (hd0,gpt4)$isofile
linux (loop)/pmagic/bzImage iso_filename=$isofile boot=pmagic edd=off noapic load_ramdisk=1 prompt_ramdisk=0 rwnomce sleep=0 loglevel=0 keymap=de_CH-latin1 vga=791
initrd (loop)/pmagic/initrd.img
}


After having addad the entries from above, I regenerated the file " /boot/grub/grub.cfg":
# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found background image: DanjaForGrubBackground.png
Found linux image: /boot/vmlinuz-3.0.0-14-generic
Found initrd image: /boot/initrd.img-3.0.0-14-generic
Found linux image: /boot/vmlinuz-3.0.0-13-generic
Found initrd image: /boot/initrd.img-3.0.0-13-generic
Found linux image: /boot/vmlinuz-3.0.0-12-generic
Found initrd image: /boot/initrd.img-3.0.0-12-generic
Found linux image: /boot/vmlinuz-2.6.38-11-generic
Found initrd image: /boot/initrd.img-2.6.38-11-generic
Found linux image: /boot/vmlinuz-2.6.38-8-generic
Found initrd image: /boot/initrd.img-2.6.38-8-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows Vista (loader) on /dev/sda1
done


This entry worked once but I do not use it any more because this Linux version is very restricted and Parted Magic offers the same functionality and more:
menuentry "OK: Gparted Live 0.10.0 (auf /Data/ISOs)" {
set isofile="/ISOs/gparted-live-0.10.0-3.iso"
loopback loop (hd0,gpt4)$isofile
linux (loop)/live/vmlinuz boot=live config union=aufs noswap noprompt ip=frommedia findiso=$isofile toram=filesystem.squashfs
initrd (loop)/live/initrd.img
}

# 2011.12.19 - OK but not used any more, because Parted Magic 2011_11_24 that I have installed is a newer version and 64 bit.
# With the 64 bit version I can perform all operations. This is not the case on by 64 bit computer with this
# version 4.10 on 32 bit mode.
# I created the directory /PartedMagicLinux on root of the directory tree of the Ubuntu 11.10, than I copyed the
# content of the USB memory stick containing Parted Magic Version 4.10 32 bit into it.
menuentry "Parted Magic 32 bit Version: 4.10 (on /PartedMagicLinux)" {
recordfail
insmod gzio
insmod part_gpt
insmod ext2
insmod part_msdos
set root='(hd0,gpt2)'
search --no-floppy --fs-uuid --set=root a76be1e4-00f2-4282-953f-751eceac0ad1
linux /PartedMagicLinux/pmagic/bzImage root=/dev/sdb2 directory=PartedMagicLinux edd=off noapic load_ramdisk=1 prompt_ramdisk=0 rw vga=791 loglevel=0 max_loop=256 keymap=de_CH-latin1
initrd /PartedMagicLinux/pmagic/initramfs
}

OK but not used any more because I uninstalled Ora VM Server
menuentry "OK: Oracle VM Server-ovs (xen-4.0.0 2.6.32.21-41ovs)" --class gnu-linux --class gnu --class os {
insmod part_msdos
insmod ext2
set root=(hd1,msdos2)
multiboot /boot/xen.gz dom0_mem=826M
module /boot/vmlinuz-2.6.32.21-41xen ro root=UUID=ace79edc-24cf-4831-b313-015306190462
module /boot/initrd-2.6.32.21-41xen.img
}


The following entries does not work yet:
menuentry "OnWork: ISO: Fedora 14" {
set isofile="/ISOs/Fedora-14-i686-Live-Desktop.iso"
loopback loop (hd0,gpt4)$isofile
linux (loop)/isolinux/vmlinuz boot=isolinux iso-scan/filename=$isofile noeject noprompt --
initrd (loop)/isolinux/initrd0.img
}


The these entries are only examples that I have taken from the Internet:
menuentry "Example: Lucid ISO" {
loopback loop (hd0,1)/boot/iso/ubuntu-10.04-desktop-i386.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/ubuntu-10.04-desktop-i386.iso noprompt noeject
initrd (loop)/casper/initrd.lz
}

menuentry "Example: Karmic 64-bit ISO" {
loopback loop (hd0,1)/boot/iso/ubuntu-9.10-desktop-amd64.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/ubuntu-9.10-desktop-amd64.iso noprompt quiet splash
initrd (loop)/casper/initrd.lz
}

menuentry "Example: Gparted Live ISO" {
set isofile="/boot/iso/gparted-live-0.10.0-3.iso"
loopback loop (hd0,1)$isofile
linux (loop)/live/vmlinuz boot=live config union=aufs noswap noprompt ip=frommedia findiso=$isofile toram=filesystem.squashfs
initrd (loop)/live/initrd.img
}

menuentry "Example: SystemRescue CD ISO" {
set isofile="/boot/iso/systemrescuecd-x86-1.5.8.iso"
loopback loop (hd0,1)$isofile
linux (loop)/isolinux/rescue64 setkmap=us isoloop=/systemrescuecd-x86-1.5.8.iso
initrd (loop)/isolinux/initram.igz
}

menuentry "Example: Parted Magic ISO" {
set isofile="/boot/iso/pmagic-5.2.iso"
loopback loop (hd0,1)$isofile
linux (loop)/pmagic/bzImage iso_filename=$isofile boot=live load_ramdisk=1 prompt_ramdisk=0 noeject noprompt
initrd (loop)/pmagic/initramfs
}

menuentry "Example: Boot IMG - Seagate Tools" {
linux16 /memdisk bigraw
initrd16 /SeaTools.img
}

# Courtesy of cbowman57 in Post #54; with Clonezilla ISO located in sda9's root directory (/)
menuentry "Example: Clonezilla live" {
set isofile="(hd0,9)/clonezilla-live-1.2.8-3-amd64.iso"
loopback loop $isofile
linux (loop)/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run=\"ocs-live-general\" ocs_live_extra_param=\"\" ocs_live_keymap=\"\" ocs_live_batch=\"no\" ocs_lang=\"\" vga=788 ip=frommedia nosplash toram=filesystem.squashfs findiso=$isofile
initrd (loop)/live/initrd.img
}

# Modified from the post by Dancer_69
menuentry "Example: Gentoo 11 Live DVD" {
set isofile="/boot/iso/gentoo-livedvd-x86-amd64-32ul-11.0.iso"
loopback loop (hd1,6)$isofile
linux (loop)/boot/gentoo root=/dev/ram0 init=/linuxrc dokeymap looptype=squashfs loop=/image.squashfs cdroot initrd=/boot/gentoo.igz isoboot=/boot/iso/gentoo-livedvd-x86-amd64-32ul-11.0.iso
initrd (loop)/boot/gentoo.igz
}

2011-10-08

Verwendung von Migros M-IDentity Sticks unter Ubuntu 11.04 und Ubuntu 11.10

Hier habe ich die Informationen aus verschiedene Forem zum Gebrauch des Migros M-IDentity Sticks unter folgenden Linux Versionen zusammengefasst und leicht angepasst:
- Ubuntu 11.04
- Ubuntu 11.10

Alle Arbeiten müssen als Linux User "root" durchgeführt werden.

Wenn man den Stick einsteckt, wird es dadurch automatisch "gemountet".
Wenn man es nicht mehr braucht, kann man den Stick einfach rausziehen. Es wird dann automatisch "unmounted" und die Icons verschwinden. Es muss nicht (und kann auch nicht) mittels Nautilus (Datei "Explorer") "unmounted" werden.

Datei /etc/udev/rules.d/70-ebanking-stick.rules erstellt.
Wegen der schlechte Formatierungsmöglichkeiten in diesem Block, habe ich die 4 Zeilen nummeriert.
(Den Code ohne die Zeilennummern und leerschlag rauskopieren.)
1. ATTR{idVendor}=="0d46", ATTR{idProduct}=="4081", MODE="0666"
2. SUBSYSTEMS=="scsi", KERNEL=="sr?", ATTRS{vendor}=="KOBIL", SYMLINK+="eBanking"
3. SUBSYSTEMS=="scsi", ACTION=="add", KERNEL=="sr?", ATTRS{vendor}=="KOBIL", RUN+="/usr/local/bin/mountEbanking.sh"
4. ACTION=="remove", SUBSYSTEM=="block", KERNEL=="sr?", RUN+="/usr/local/bin/umountEbanking.sh"


Um den Stick automatisch nach den obigen Regeln zu Mounten/Unmounten habe ich folgende Scripte erstellt.

Script /usr/local/bin/mountEbanking.sh:
#!/bin/sh
MNT_POINT="/media/eBanking"
[ ! -d ${MNT_POINT} ] && mkdir ${MNT_POINT}
mount -o users,exec /dev/eBanking ${MNT_POINT}


Script /usr/local/bin/umountEbanking.sh:
#!/bin/sh
MNT_POINT="/media/eBanking"
if [ -d ${MNT_POINT} ]; then
umount ${MNT_POINT}
rmdir ${MNT_POINT}
fi


Obige Scripts ausführbar machen:
sudo chmod +x /usr/local/bin/umountEbanking.sh
sudo chmod +x /usr/local/bin/mountEbanking.sh

2011-02-19

Script zur Konvertierung von Keepass CSV Export Dateien in mBackup CSV Dateien

Auf dem iPhone ist es im Moment nicht möglich im Schweizer iTunes AppStore irgendein Programm zu erwerben, welches KeePass Dateien wenigstens lesen kann.

CORREKTUR
Vor einigen Monaten bin ich auf "MyKeepass" umgestiegen.
Wiederum seit einigen Monaten verwende ich das Programm "MiniKeePass".
Beide funktionierten sehr gut.
"MiniKeePass" erlaubt das erstellen von Einträge.
Bei "MyKeepass" weis ich nicht mehr.
Ich bin schlussendlich auf "MiniKeePass" umgestiegen, weil es damit einfacher ist die Username und Passwort in den anderen Anwendungen zu "pasten".


Ich fand blog.familieluetke.de. Dort wird beschrieben wie man CSV Dateien, welche aus KeePass exportiert wurden, mittels mBackup auf dem iPhone in das Programm mSecure übertragen kann. mSecure kann dann die Einträge lesen und auch bearbeiten. Die Bearbeitung der Einträge macht aber leider wenig sind. Der umgekehrte Weg (vom mSecure --> KeePass) würde einen Strukturverlust mit sich bringen, weil mSecure keine Baumstruktur von Gruppen kennt (im Gegensatz zu KeePass.

Im oben erwähnten Blog wird erwähnt , dass die Reihenfolge der Spalten aus der KeePass CSV-Datei mittels Excel in die richtigen Reihenfolge gebracht werden kann. Wenn man den Prozess aber regelmässig durchführen will, ist dies unpraktisch.

Mein unten aufgelisteten Script führt diese Umstellung automatisch durch.

In KeePass hat man normalerweise auch mehrere Arten von Einträge in Gruppen (mit verschiedene Icons) . Mein Script erlaubt die Eigene KeePass Gruppen in mSecure Eintragstypen mit gleiche oder unterschiedliche Namen zu „übersetzen“. Dazu muss man eine Liste von Wörterpaaren am Anfang des Scripts anpassen. Die Namen in der linken Spalte entsprechen den Gruppen-Namen in KeePass (diese müssen explizit exportiert werden). Die Namen in der rechten Spalte müssen den Namen der Eintragstypen in mSecure entsprechen. Um KeePass Einträge aufnehmen zu können, müssen die Einträge in mSecure immer das gleiche Format haben (URL-Feld, Benutzername-Feld und Passwort-Feld). (Den Kommentar/Hinweis-Feld muss man nicht erstellen. Es ist implizit vorhanden).

Hier mein Script:

#!/usr/bin/perl
#===============================================================================
# FILE NAME: Convert_Keepass_CSV_To_mSecure.pl
# DATE : 2011.02.19
# Tested with versions:
# - KeePass: 1.14
# - mBackup: 1.0.8
#
# Converts a KeePass CSV export file to a CSV format that can be imported by
# mBackup. Such an import creates a kind of backup entry in mBackup.
# This backup entry in mBackup can be loaded into mSecure on the iPhone by
# performing a restore.
#
# This allows to have more than one type of entries in mSecure (each type with
# own name and icon), like the groups in KeePass.
#
# PREREQUISITES: Language Perl. On UNIX systems like Linux, MacOS, Solaris etc.
# Perl should already be installed. On Windows download and install
# Cygwin (http://www.cygwin.com/) and use the install program of
# Cygwin to install Perl.
#
# USAGE: In mSecure create your own Types, always with the folloging fields
# URL, UserName, Password
# (The comment field always implicitly exists)
# In this script, insert/change the pairs of KeePass type name and
# mSecure type name to the list specified by the hash table "entryTypeLst"
# bellow.
# In KeePass export the desired group/trees to CSV file(s) by choosing:
# Options:
# [x] Encode/replace newline characters by 'n'
# Fields to export:
# [x] Password Groups
# [x] Title
# [x] User Name
# [x] Password
# [x] URL
# [x] Notes
#
# Go to the directory were you exported the KeePass CSV files and call this script:
# ./Convert_Keepass_CSV_To_mSecure.pl InKeePassCsvFileName OutmSecureCsvFileName
#
# PARAMETERS: This script reads the file given as first parameter (KeePass CSV file)
# and appends the result to the file given as second parameter (CSV file
# that can be imported by mBackup).
#
# PROBLEMS & SOLUTIONS:
# If you are not able to execute this script check the following.
# - Is this script executable? To be sure, you can make it executable with the following
# statement:
# chmod ug+x Convert_Keepass_CSV_To_mSecure.pl
# - Perhaps the path for Perl that I used in my script, does not match the location
# of Perl on your Computer. Look, if the statement "which perl" returns the same
# path as i used on the very first line of this script (i.e. "/usr/bin/perl")
# if not, change the first line accordingly.
#===============================================================================
my $lineNr= 2;
my $title;
my $user;
my $pwd;
my $url;
my $comment;

# Hash table. Key: Entry type name from KeePass
# Value: Translation from KeePass entry type to the entry type name in mSecure
my %entryTypeTransLst =
(
# KeePass Type, mSecure Type
"Home Alarmanlage", "Hause Alarmanlage",
"Bankkonten", "Bankkonten",
"Device", "Geräte",
"Div.Codes", "Verschiedene Zugriffscodes",
"Diverses", "Verschiedenes"
);
# Whenever a type can not be mapped from KeePass to mSecure by the list above, the type
# below willbe used
my $UNKNOWN_TYPE="Unknown Type";



# ---------- Check input parameters ---------
# Check first parameter (input file name)
if ( !$ARGV[0] ) {
print "ERROR: Name of the input CSV file (first paramater) is missing!";
exit;
}
open(IN_FILE, "<$ARGV[0]"); # Check second parameter (output file name) if ( !$ARGV[1] ) { print "ERROR: Name of the output file (second paramater) is missing!"; exit; } # ---------- Check input file content --------- # Check if any entry contains the separator character ';' # Skip first line $line=;
while( $line= )
{
# Abort if char is found ; because this is our record entry separator character
if ( $line=~ /;/ ) {
print "ERROR: Remove separator char ';' from line $lineNr\n";
close(IN_FILE);
exit;
}
$lineNr++;
}
close(IN_FILE);
print "OK: No separator char ';' found in any entry\n";


# ---------- Start processing ---------
$lineNr= 2;
open(IN_FILE, "<$ARGV[0]"); open(OUT_FILE, ">>$ARGV[1]");

# Skip first line
$line=;
while( $line= )
{
# Remove starting \" from line
$line=~s/^\"//;
# Remove ending \" from line
$line=~s/\"\W*$//s;
# Replace windows CR+LF by the UNIX LF
$line=~s/\\r\\n/\\n/g;
# Split the line into its parts
($type, $title, $user, $pwd, $url, $comment)=split(/","/, $line);
# Translate KeePass types to mSecure types
if ( defined($entryTypeTransLst{$type}) ) {
$type= $entryTypeTransLst{$type};
}
else {
print "INFO: Line $lineNr. No translation defined for KeePass type \"$type\". Translating to \"$UNKNOWN_TYPE\"\n";
$type= $UNKNOWN_TYPE;
}
# Generate / reformat to mSecure format
print OUT_FILE $type.";".$title.";".$comment.";".$url.";".$user.";".$pwd.";\n";
$lineNr++;
}

close(IN_FILE);
close(OUT_FILE);

print "Finished\nLines read: $lineNr\nAppending entries to file: $ARGV[1]\n";

# END OF FILE