Showing posts with label terminal. Show all posts
Showing posts with label terminal. Show all posts

06 March 2012

94. Virtualisation from the command line -- creating a debian image in virtualbox

I came across these posts and decided to put my own spin on it.
EDIT: fixed the port/device numbers for the dvd drive


Virtual box on the CLI

Here's my take on it. Most of it is self-explanatory. As with everything else Linux, names are case-sensitive.

VBoxManage createvm --name debi_dd --ostype Debian_64 --basefolder /home/me/tmp/virtual

Virtual machine 'debi_dd' is created.
UUID: 3cab43c4-d071-4d71-9e01-22a6f4e80645
Register the vm:
VBoxManage registervm `pwd`/debi_dd.vbox

or you will get
VBoxManage: error: Could not find a registered machine named 'debi_dd'

Create a harddrive:
VBoxManage createhd --filename debi_hd --size 5000 --format VDI --variant Standard


0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: b11e6465-3ac6-441d-9e14-6417135b7cd1
The size is given in mb, VDI is the standard virtualbox format, but you can use  VMDK or VHD too. There are several variants -- Fixed, Standard, Split2G, Stream and ESX. Fixed is fixed size, standard expands as data is added, Split2G splits the HDD into 2GB chunks for filesystems which can't handle large files, Stream is 'optimized for streaming downloads and can be compressed' and I suspect that ESX is referring to VMWare's hypervisor product.

Create a SATA controller (for a win xp guest , use IDE instead)
VBoxManage storagectl debi_dd --name "ATA controller" --add sata --controller IntelAhci

Attach your harddrive
VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 0 --device 0 --type hdd --medium debi_hd.vdi

and a DVD player and point it towards your debian iso
VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 1 --device 0 --type dvddrive --medium ~/jigdo/debian-testing-amd64-CD-1.iso

Configure your VM hardware
VBoxManage modifyvm debi_dd --memory 256 --acpi on --boot1 dvd --clipboard bidirectional --nic1 nat --cableconnected1 on --bridgeadapter1 eth0 --usb on --usbehci on

You will need to have an X server running, either on the computer hosting the virtualbox, or you need to ssh in using ssh -X -C user@server. But it works. Once you have a working linux installation you can run headless.
You can also use remmina to connect via rdp at localhost:3389.

VBoxManage startvm debi_dd

Waiting for VM "debi_dd" to power on...
VM "debi_dd" has been successfully started.
You'll now be doing the usual graphical installation...


** I had some problems with network dhcp, but manually setting the ip, gw, netmask and dns server went fine. It may be particular to my networking set up (3 cards, 2 using static ip)

Make sure to install ssh server so you can easily connect to your running VM.

So you're done installing...

Eject the DVD

VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 1 --device 0 --type dvddrive --medium emptydrive


Associate e.g. localhost:2222 with virtualbox:22
VBoxManage modifyvm "debi_dd" --natpf1 "guestssh,tcp,,2222,,22"

Time to go headless:
VBoxHeadless -s debi_dd
Oracle VM VirtualBox Headless Interface 4.1.8
(C) 2008-2011 Oracle Corporation
All rights reserved.
VRDE server is listening on port 3389.

and 
ssh verahill@localhost -p 2222
to log in

You can also use remmina
Connect to localhost:3389 and you'll be greeted with:
remmina in action


Use
 VBoxManage controlvm debi_dd poweroff
to power off

There's a bit of housekeeping to do with any freshly installed linux machine:
sudo apt-get install bzip2 vim 
sudo updatedb
and edit /etc/apt/sources.list to remove the cd.
You may want to edit /etc/default/grub too and set
GRUB_TIMEOUT=1
GRUB_CMDLINE_LINUX_DEFAULT="text"

Don't forget to sudo update-grub

If you don't want headless mode, just
VBoxManage startvm debi_dd

Removal

VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 1 --device 0 --type dvddrive --medium none
VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 0 --device 0 --type dvddrive --medium none 
VBoxManage unregistervm debi_dd --delete 
VBoxManage closemedium disk debi_hd.vdi --delete 
rm debi_dd/ -rf

08 January 2012

41. Chinese character and input support on debian testing

Update: You should also install support for gtk and gtk3:
sudo apt-get install ibus-gtk3 ibus-gtk
in order to be able to use it with e.g. thunderbird.

Original post:
Here's how to set up Chinese (simplified) support in Gnome 3 /gnome-shell and the terminal (bash).

First install the fonts:
sudo apt-get install fonts-arphic-*

Next. add Chinese via locales:
sudo dpkg-reconfigure locales

Select
zh_CN.UTF-8

(For traditional characters choose zh_HK, zh_SG or zh_TW)

As default language English is probably a good idea
In my case it's en_AU.UTF-8

Edit ~/.bashrc and add the following lines:
LANGUAGE=zh_CN.UTF-8
LANG=zh_CN.UTF-8

Run
source .bashrc

Install ibus:
sudo apt-get install ibus-pinyin 
This pulls another 18 packages with it

Start ibus-daemon in terminal
An icon in the notification tray still appear
Right-click, choose Preferences (P)
Click on the second tab (input methods)
Select an input method -> Chinese -> Pinyin

You should now be able to choose between regular (latin) input and Chinese characters using Ctrl+Space.

To make ibus-daemon start with gnome, run
gnome-session-properties
and add
ibus-daemon

And you're more or less done.

Sogou is a popular pinyin database on the Windows platform -- but afaik it's not available for Linux. On Linux, it seems that the ibus-pinyin-db-open-phrase database is the default ibus database used to guess what characters you intend to type, but you can also install and select either ibus-googlepinyin or ibus-pinyin-db-android. After installation you need to select the database by going to preferences in the ibus daemon and selecting it as input method. Not being Chinese I can't tell whether sogou, google pinyin and android pinyin are comparable.

Sogou does however work with Google Chrome/Chromium on linux -- go to Preferences/Extensions -- Get More Extensions, and install the Sogou Cloud Pinyin Extension for Chrome.


11 December 2011

27. Linux: some applications

Here are some linux tools which I've found myself using:
_Terminal/cli_:
email -- mutt
chat -- mcabber
spreadsheet -- sc, sed + gawk, python
calculator -- bc
editing -- vim, nano
browser -- elinks
music -- cplay
plotting -- gnuplot
maths -- octave, maxima
Gnome (some of these I use only in the terminal, so I list them twice):
terminal -- guake
latex -- gvim, texmaker, latexilla
editing -- gvim, gedit
plotting -- gnuplot
maths -- octave, maxima
system stats -- conky
email -- evolution
chat -- gajim
browser -- chrome
video -- vlc
music -- mostly cplay in cli, but otherwise vlc
crypto -- truecrypt
password management -- keepassx
I probably spend 90% of my time using vim since, being a 'simple' editor, it's so versatile. Before taking the time to learn vim, I used gedit (and to a smaller extent nano) for the same purpose. Nano is fine, but vim is more ubiquitous (in the form of vi) and has an excellent tutorial included. I simply don't know what the full capabilities of nano are -- maybe it's only as powerful as, say, notepad, or maybe it can do everything vim can.
I gave emacs a serious try about a year ago, and it didn't suit me. I do appreciate that emacs can be considered as an OS almost in itself, but since I believe in the idea of one program - one task, and find vim more user-friendly (not meaning learner-friendly, although it is too) I felt more motivated to get serious with vim. Two weeks with emacs brought me to the same level as two rather relaxed evenings with vim.

06 December 2011

23. Configuring Mutt for two IMAP accounts

Edit: fastmail configuration added -- see beneath original post

Here's my situation: I have a personal gmail account, and a google apps gmail account via my job.

A lot of the configuration stuff (gpg in particular) was copy/pasted from some website a few years ago. Kudos to them. If I only remembered who they were, I'd give credit where credit is due.

Since I'm paranoid about protecting my identitity, let's say that the google apps account is vera@hill.com and my gmail account is verahill@gmail.com (it isn't).

Here's how it can be done:
1. create ~/.mutt
2. You want to create the following files in ~/.mutt :
private.account
work.account
muttrc


Optional:
aliases
signature.private
signature.work

3. Here are the contents of the files (the passwords are from http://xkcd.com/936/):

~/.mutt/private.account:
set from=verahill@gmail.com
set hostname="gmail.com"
unset folder
set folder="imaps://verahill@gmail.com@imap.gmail.com"
set postponed="=Drafts"
set record="=Sent"
set smtp_url="smtps://verahill@gmail.com@smtp.gmail.com"
set spoolfile="imaps://imap.gmail.com/INBOX"
set from='Vera Hill <verahill@gmail.com>'
set signature="~/.mutt/signature.private"

~/.mutt/work.account:
set from=vera@hill.com
set hostname="hill.com"
unset folder
set folder="imaps://vera@hill.com@imap.gmail.com"
set smtp_url="smtps://vera@hill.com@smtp.gmail.com"
set from='Vera Hill <vera@hill.com'
set realname='Vera Hill'
set postponed="=Drafts"
set record="=Sent"
set spoolfile="imaps://imap.gmail.com/INBOX"
set signature="~/.mutt/signature.private"

basic ~/.mutt/muttrc
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates

set sort='threads'
set sort_aux='last-date-received'
set imap_check_subscribed


auto_view text/html #needs ~/.mailcap and install elinks!
set attribution="* %n <%a> wrote\a ecrit:\n"

set pager_index_lines="15" #split view 

# Make sure the inbox updates and bind a key
set timeout=15
set mail_check=60
bind index "i" imap-fetch-mail

#dual boxes specific
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/private.account<enter><change-folder>!<enter>'
macro index <f4> '<sync-mailbox><enter-command>source ~/.mutt/work.account<enter><change-folder>!<enter>'

folder-hook 'verahill@gmail.com' 'source ~/.mutt/private.account'
folder-hook 'vera@hill.com' 'source ~/.mutt/work.account'

account-hook imaps://verahill@gmail.com 'set imap_user=verahill@gmail.com imap_pass=correcthorsebatterystaple smtp_pass=correcthorsebatterystaple'
account-hook imaps://vera@hill.com 'set imap_user=vera@hill.com imap_pass=Tr0ub4dor&3 smtp_pass=Tr0ub4dor&3'
source ~/.mutt/private.account # default account

~/.mailcap:

#allows viewing html, but requires that elinks is installed
text/html;                      elinks %s; nametemplate=%s.html
text/html;                      elinks -dump %s; nametemplate=%s.html; copiousoutput


You can do a lot more -- if you want to use an address book (aliases), create a file called ~/.mutt/aliases with each line having an alias of the format:
alias  Obama "Barak Obama" <potus@whitehouse.gov>

Add the following to the end of your muttrc:
 # Addressbook
set alias_file=~/.mutt/aliases
set sort_alias=alias
set reverse_alias=yes
source $alias_file

If you want to use GPG add this to your muttrc (anywhere) and the ID of your key is C1C2C3C4:
# GPG stuff - autosign


set pgp_decode_command="gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f"
set pgp_verify_command="gpg --no-verbose --batch --output - --verify %s %f"
set pgp_decrypt_command="gpg --passphrase-fd 0 --no-verbose --batch --output - %f"
set pgp_sign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f"
set pgp_clearsign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f"
set pgp_encrypt_only_command="pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 0xC1C2C3C4 -- -r %r -- %f"
set pgp_encrypt_sign_command="pgpewrap gpg --passphrase-fd 0 --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0xC1C2C3C4 -- -r %r -- %f"
set pgp_import_command="gpg --no-verbose --import -v %f"
set pgp_export_command="gpg --no-verbose --export --armor %r"
set pgp_verify_key_command="gpg --no-verbose --batch --fingerprint --check-sigs %r"
set pgp_list_pubring_command="gpg --no-verbose --batch --with-colons --list-keys %r" 
set pgp_list_secring_command="gpg --no-verbose --batch --with-colons --list-secret-keys %r" 
set pgp_autosign=yes
set pgp_sign_as=0xC1C2C3C4
set pgp_replyencrypt=yes
set pgp_timeout=1800
set pgp_good_sign="^gpg: Good signature from"

If you prefer vim to nano:
set editor="vim -c 'set tw=70 et' '+/^$' "
set edit_headers=yes

A colour-scheme which happens to work with my set-up for guake:
color index green black plain
color normal green black
color status white black
color body green black plain
color header cyan black plain
color quoted blue black
color tree green black

Not sure what this does (something to do with headers) but it's there in my file:

ignore "Authentication-Results:"

ignore "DomainKey-Signature:"

ignore "DKIM-Signature"

hdr_order Date From To Cc

EDIT:
If you want to add a fastmail account (in my case me@imap.cc), do this:
There's no free smtp service from fastmail, so I use the gmail smtp service

Create imapcc.account in ~/.mutt and fill it with

set from=me@imap.cc
set hostname="imap.cc"
unset folder
set folder="imaps://me@imap.cc@messagingengine.com"
set postponed="=Drafts"
set record="=Sent"
set smtp_url="smtps://verahill@gmail.com@smtp.gmail.com"
set spoolfile="imaps://messagingengine.com/INBOX"
set from='Me at gmail <verahill@gmail.com>'
set signature="~/.mutt/signature.private"


and edit ~/.mutt/muttrc to add the following lines:

macro index <f5> '<sync-mailbox><enter-command>source ~/.mutt/imapcc.account<enter><change-folder>!<enter>'

folder-hook 'me@imap.cc' 'source ~/.mutt/imapcc.account'
account-hook imaps://me@imap.cc 'set imap_user=me@imap.cc imap_pass=ashortpassword smtp_pass=correhorsebatterystaple'