Bash script command line

Gli argomenti passati allo script si trovano nelle variabili $1, $2, ecc….
Tutti gli argomenti vengono raccoli nell’ array $@ : è utile quando si ha un numero variabile di argomenti, come nel caso delle espansioni della shell (vedere, come nel seguente esempio

for FILE1 in "$@"
   wc $FILE1

Allo script possono essere passati anche dei flag (o opzioni): per gestirli si usa getopts

while getopts u:d:p:f: option
        case "${option}"
                u) USER=${OPTARG};;
                d) DATE=${OPTARG};;
                p) PRODUCT=${OPTARG};;
                f) FORMAT=$OPTARG;;

il ciclo while sfrutta la funzione getopts, la quale a sua volta usa la optstring: quest’ ultima indica a getopts quali flag aspettarsi e come gestirli.
Getopts assegna il flag alla variabile ${option}: con lo switch case/esac andiamo a sfruttarlo.
Il valore della variabile assegnata al flag è contenuto in ${OPTARG}.
I duepunti nella optstring sono importanti: un duepunti accanto ad un flag indicano che quel flag richiede un valore.
Un duepunti all’ inizio della optstring indica che i flag non presenti nella optstring vengono assegnati con una ${option} == “?”: ciò permette di gestire gli errori (magari informando l’ utente).

Gli argomenti non gestiti da getopts sono catturati da $1, $2, ecc….

VGA passthrough – situazione

February 1st, 2013


The VGA passthrough club – did you succeed, and how?

I can’t do away with Windoze, but I hate dual-boot. I also need native (or near-native) graphics support in the Windows VM.

In the end I chose Xen to host Linux and a Windows 7 VM which uses a dedicated graphics card for native graphics performance. It works extremely well, with what I consider top-notch performance that doesn’t stand (much) behind a native Windows installation on bare metal.

In fact, I’m so thrilled about it that I wonder why not every dual-booter is switching to virtualization. (I’m actually not that surprised since it was quite challenging to get it working.)

Here my questions:

Has anybody tried VGA passthrough?

If yes, which hypervisor/method did you use (Xen, KVM, VMware, etc.)?

How easy or difficult was it?

In the end I would like to know if there are perhaps better or easier ways to get it working. Thanks in advance for your feedback!
LM14 64bit (Ubuntu 12.10) with Xen hypervisor 4.1.2 and Windows 7 Pro 64 bit guest using VGA passthrough


February 3rd, 2013


Re: The VGA passthrough club – did you succeed, and how?

You indeed need suitable hardware. Here is what you need:

1. CPU with VT-d (Intel) or AMD-Vi (AMD) support. This feature is also called IOMMU. See, or for Intel CPU’s see

2. A motherboard that supports VT-d. See the Wikipedia link above, as well as…e-motherboards and

3. A motherboard BIOS that supports VT-d. I’m not joking here, one BIOS release may support VT-d, the next one doesn’t. In some cases there is no way going back to the earlier BIOS that does support it. See links under 2.

4. A graphics card that supports VGA passthrough. In general, most modern AMD (ATI) graphics cards will work, but it’s best to check here…TestedAdapters and
Some Nvidia graphics adapters are also supported, namely the Quadro series of “Multi-OS” capable cards starting with the Quadro 2000 model upwards (the Quadro 600 for example isn’t specified as “Multi-OS”). There are some more Nvidia graphics adapters that work, but first check the links above if it’s listed.
The newer Xen 4.2 hypervisor supposedly improves graphics cards compatibility, though I haven’t tried it.

It is MUCH easier if you have two graphics cards, or a CPU internal GPU (like on most new Intel desktop CPUs) and a discrete graphics card for passthrough.One will serve Linux, the other your Windows guest.

If your hardware doesn’t meet the above, either replace the incompatible part, or forget the whole thing!

I’ve written a how-to for Linux Mint 13/14, which should likewise work with Ubuntu 12.04 and 12.10:

Now to your questions.

My goal was to get fast switching on 2 desktops, the way you would have 2 full OSes booted simultaneously.

My PC works as if I have two PCs. I could hook up two screens, keyboards and mice and two people would be able to use it at the same time, with full video acceleration on both. Right now I switch from one to the other via KVM button and the input selector on my screen, but if I have to go forth and back a lot I run a remote desktop in Windows to connect to my Linux dom0, or vice versa. I use a SAMBA share under Linux to copy files between the two.

Can you confirm your Windows 7 installation behaves as native?

95% yes. Everything except the following two issues work as if I was running Windows directly on the hardware. The two issues I’ve found are:
I) Youtube video stops after a few seconds, hangs for a while, and continues, just to stop again after a few seconds. This is most likely a networking issue with the bridge, though I haven’t figured out what exactly. Somehow Windows “looses” the DNS server, or access to it. One work around would be to pass through a dedicated NIC. I haven’t tried it though.
II) I can’t watch video using VLC when the video file is on a network drive. I believe this is the same network problem as above.
EDIT: Both problems are solved now using the latest GPLPV drivers under Windows.

Other than these two issues I haven’t found any problem.

What about other peripherals? Scanner, printer, gamepad, etc.?

In addition to the graphics card, I’m passing 2 USB controllers through to Windows. Everything connected to these ports is fully controlled by Windows, with Windows native drivers.
Just an example how well this works: I use Windows for photo editing. To calibrate my screen I use a spectrophotometer (some device that measures light / colors) which is connected via USB. The software then shows different color patches on the screen which my calibrating device reads and reports back to the PC (via USB port). At the end, the software loads the corrected color curve directly into my screen via the DVI port of the graphics card. This can only work when the calibration software is able to communicate with the graphics card.
Other external devices I frequently use under Windows are:
– Keyboard and mouse are connected via KVM USB switch;
– CF card reader (to transfer photos from the camera’s CF cards to the PC);
– External hard drive for backup – it’s automatically detected by the backup program when I connect it to the USB port;
– USB audio controller – a low-cost ~5$ USB stick that works without any issues, it’s permanently plucked in;
– USB flash drives – they work as expected.

I haven’t set up my printer yet to work with Windows. But I can’t see any reason why it shouldn’t work. I have both a USB 2.0 and a USB 3.0 controller passed to Windows. The transfer speed is as expected. If you have an external HDD or memory card reader to connect, use a USB 3.0 controller – it makes a huge difference.

Good luck!


February 7th, 2013


Re: The VGA passthrough club – did you succeed, and how?

I can’t do away with Windoze, but I hate Has anybody tried VGA passthrough?

Yes, I have a setup with 2 desktops, each running in their own virtual machine with passed through radeon4350 and usb cards.
Apart from that, a few other virtual machine servers run on the same hardware.

Which hypervisor/method did you use (Xen, KVM, VMware, etc.)?

I’m using Xen 4.2 at the moment, it seems to me that in general Xen is way ahead of the game when it comes to PCI Passthrough.

How easy or difficult was it?

Once i started to use the catalyst driver instead of the open source driver (which complains about not being able to find the bios), everything was pretty straight forward.
I installed ubuntu and windows7 in a vnc session and later installed Catalyst. Windows 8 was even easier, it installed a working vga driver out of the box.
Note that i just used pci-passthrough, not the advanced vga-passthrough patches.
Besides the vga adapter itself, i also passthrough the onboard audio of the adapter (hdmi), and an usb controller, so basically i have 2 seperate terminals, each running their own os (either Ubuntu/Windows7/Windows8).
All operating systems behave asif they run on native hardware, only difference is that the boot screen doesn’t appear on my vga cards, because i chose to do only pci-passthrough. The boot window appears on the VNC session.

Note that as stated above, using the right CPU, Mainboard and VGA Card is essential here.
In my case: Intel Core i7 860, Asus P7P55D Evo, Asus EAH4350 Silent.


You can use any number of cards from any number of manufacturers.

Dom0 won’t care because while it will know that there are devices there, you’ll be passing kernel boot parameters to tell it to ignore looking for and binding drivers to the cards so it will just leave them alone for the domUs to deal with.

Each domU will only know about the card assigned to it so they in turn won’t care that you have multiple video cards from either the same manufacturer or different ones. As long as the domU’s OS has drivers for the card(s) assigned to it, it’ll be able to use it fully.

My Xen server setup has a cheap Nvidia card for the Xen host and a Radeon 7750 driving multiple monitors dedicated to one of the guests. Works like a charm.

Note: there are still some issues with rebooting domUs that have assigned VGA adapters. The video card may not be reset during the reboot process and may fail to initialize properly following the reboot. I haven’t found a solution for this yet so you may want to do some searches on FLR (Function Level Resets) with Xen VGA passthrough.



Apt pinning (Debian)

Per prima cosa si impostano i repository: oltre a quelli della release in uso, possono esserne aggiunti altri a piacimento.
Possono essere aggiunti modificando il file /etc/apt/sources.list, ma c’è anche la possibiltà di aggiungere nuovi file nella directory /etc/apt/sources.list.d/, ognuno dei quali ha la stessa funzione di sources.list: questi nuovi file DEVONO avere il nome che termina con .list: con il comando man sources.list si trova

La directory /etc/apt/sources.list.d fornisce un metodo per aggiungere voci di sources.list in file separati che terminano con .list. Il formato è il medesimo del file sources.list regolare.

Ora che i repository sono configurati, il sistema APT può essere istruito ad installare una determinata versione di un pacchetto tra le varie disponibili nei repository utilizzati: per farlo, bisogna configurare le “preferenze” di APT, o con un file unico /etc/apt/preferences o con dei frammenti di file in /etc/apt/preferences.d/: da man apt_preferences

The APT preferences file /etc/apt/preferences and the fragment files in the /etc/apt/preferences.d/ folder can be used to control which versions of packages will be selected for installation

In generale, le preferenze sono del tipo:

Package: <nome del pacchetto>
Pin: <condizioni>
Pin-Priority: nnn

#ad esempio:
Package: *
Pin: release a=testing
Pin-Priority: 850

La configurazione di APT (e di tutti i programmi ad esso collegati) è contenuta nel file /etc/apt/apt.conf e nella directory /etc/apt/apt.conf.d/ (vedere man apt.conf).
Può essere necessario modificare la configurazione, ma di solito quella di default è già soddisfacente.
Per consultare la configurazione attualmente esistente si usa il comando apt-config dump (magari in pipe per leggerlo meglio: apt-config dump | less).
Ad esempio, se voglio aggiungere il repository experimental per prendere solo un pacchetto (iceweasel) ma voglio lasciare la mia distribuzione allineata con i repository testing, mi basta verificare che il dump della configurazione contenga

APT::Default-Release "wheezy";

e poi da aptitude vado a selezionare il pacchetto iceweasel che preferisco tra tutti quelli disponibili: non mi serve di configurare le “preferenze” di apt per il pinning, vado in manuale.

Windows 7: cancellare elenco oggetti recenti


Versione facile: right-click sul pulsante Start o sul menu Start->Proprietà->Menu Start, poi deselezionare l’ opzione “Archivia e visualizza gli elementi aperti di recente nel menu Start e nella barra delle applicazioni”; cliccando OK o Applica si ha l’ immediata cancellazione della cronologia.

Versione complessa: la cronologia degli elementi usati di recente si trova nel percorso C:\Users\%nome utente%\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations , infatti dopo la cancellazione descritta precedentemente la cartella risulta svuotata.


La lista di oggetti di uso frequente è chiamata Jump List in inglese: nel percorso C:\Users\%nome utente%\AppData\Roaming\Microsoft\Windows\Recent\ troviamo 2 cartelle, AutomaticDestinations e CustomDestinations, la prima per la cronologia creata automaticamente dal S.O.

La stessa cartella Recent è usata per la cronologia delle “Risorse recenti”.


I file AutoDest sono di tipo OLE Compound, e contengono stream multipli di 2 tipi:

  • un tipo di stream identificato da un numero esadecimale, che contiene dei dati simili ai Windows Shortcut (LNK)
  • un altro tipo di stream chiamato DestList, che somiglia a una lista MRU/MFU (most recently, most frequently used).
    Questo stream contiene un header di 32 byte, seguito da strutture di 114 byte seguite da una stringa a lunghezza variabile Unicode. L’ header da 114 byte contiene:

    Offset Size Description
    0x48 16 bytes NetBIOS name of the system; padded with zeros to 16 bytes
    0x58 8 bytes Stream number; corresponds to the numbered stream within the jump list
    0x64 8 bytes FILETIME object
    0x70 2 bytes Number of Unicode characters in the string that follows

I file *.customDestinations-ms sono di tipo MS-SHLLINK.

Pasta asparagi e cipolle

Far appassire la cipolla nell’ olio con un cucchiaio di brodo.
Poi unire gli asparagi puliti e tagliati, un po’ di pepe, un pizzico di sale (grosso) e un mestolo di brodo.
Cuocere a fuoco medio e con il coperchio per almeno 10 minuti, ma prolungare la cottura se necessario.
Saltare la pasta cotta nella padella del condimento e servire con un filo di olio e una spolverata di pepe.