20 February 2012

70. Installing Debian on a USB stick -- live usb vs a true and full installation

Update 17 March 2013: See this post for a faster, better way of creating a full install if you're already running Debian.

Original post:
Every now and again I get posts like this one, or this one, via google news. While those posts --describing the use of unetbootin to create a 'live' USB analogue to a live CD -- may be technically correct, there's just so much more you can do.

In 1  we do the old boring bog-standard 'write live cd to a usb' thingy that you see pasted all over the web, but using cat instead of unetbootin.
In 2  we make a real, bootable installation on a usb drive.



1.  Creating a USB version of a live CD -- the boring option
With the current 'hybrid' Debian iso's it couldn't be easier.
THIS WILL WIPE YOUR USB STICK

 --- START HERE ---

a. Download the iso
Using jigdo is a good option. Downloading a business-card/netinstall iso is another, if you'll have a working internet connection available.

b. Plug in and mount your USB device and  find out the device name of your USB drive.
If it's mounted you can use
df -h
rootfs                                                   93G   36G   54G  40% /
udev                                                    3.9G     0  3.9G   0% /dev
tmpfs                                                   801M  980K  800M   1% /run
/dev/disk/by-uuid/..-10a350f85687   93G   36G   54G  40% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   1.6G   52K  1.6G   1% /tmp
tmpfs                                                   1.6G  816K  1.6G   1% /run/shm
/dev/sda6                                               745G  183G  525G  26% /home
/dev/sdc1                                               2.0G  434M  1.5G  23% /media/XP-KOMKU

or

mount
../dev/sdc1 on /media/XP-KOMKU type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0077,codepage=cp437,iocharset=utf8,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks)



to list mounted devices. In my case it's an old 2 G usb stick I used to create a Windows XP installation USB device on.

If you prefer a gui tool, start palimpsest (called Disk Utility in gnome)
It will be something akin to sdb1 or sdc1 etc. That means the device name is /dev/sdb or /dev/sdc, respectively. In our case, it's sdc.

c. Unmount but don't detach the device
You don't want anything else writing to it.

me@beryllium:~/Documents/screengrabs$ umount /dev/sdc1
me@beryllium:~/Documents/screengrabs$ df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   93G   36G   54G  40% /
udev                                                    3.9G     0  3.9G   0% /dev
tmpfs                                                   801M  976K  800M   1% /run
/dev/disk/by-uuid/..-10a350f85687   93G   36G   54G  40% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   1.6G   60K  1.6G   1% /tmp
tmpfs                                                   1.6G  820K  1.6G   1% /run/shm
/dev/sda6                                               745G  183G  525G  26% /home
d. Become root and use cat to write the iso to the USB device

sudo su

And write (assuming that the device name is sdc and you are using the businesscard iso)

cat debian-6.0.3-amd64-businesscard.iso > /dev/sdc

Done.

e. boot from your USB drive and go through the same steps as for a CD.  
Plug it in, then start your computer. Hit F12 (or F10 or del or F2) during the bios start-up to select boot medium. Choose to boot from usb. Older BIOSes can't boot from USB.



2. Really INSTALLING Debian on a USB
You can use either virtualbox or quemu for this. Here I show how to use virtualbox.

[NOTE: there's a leaner, faster, better way described here: http://verahill.blogspot.com/2013/03/361-installing-debian-on-usb-stick-from.html ]

  •  Note that a tiny 2 Gb USB stick isn't suitable for a full Debian + Gnome installation. It may, however, work well with e.g. openbox and xmonad. Or just work in the terminal -- use mutt for email, mcabber for chat, elinks for http/www etc.
  • Here I show how to install using the businesscard iso, but I've done this with the regular Debian DVD version in the past.
  • Also, few USB devices operate at 480 Mbps -- so be prepared that installation via virtualbox onto a USB device will take considerably longer than a regular installation.
  • Solid state devices degrade with I/O, so use your USB stick for back-up use during e.g. travel etc. Don't trust the integrity of it. 


There are a few good reasons for installing a full linux version on a thumb drive or a regular but external harddrive:
*  a thumb drive will allow you too carry an independent OS with you, allowing you to e.g. temporarily borrow a computer from a friend but running your own system. An installation, as opposed to a 'live cd', allows you to customise the setup and install programs. USB 2 is quite slow, and many thumb drives are slower than that, so you're probably better off running a light system than a full on gnome-shell desktop. That's not so say that you can't -- I have.
* installing onto a usb-connected harddrive will allow you to setup and prepare headless boxes or systems without a direct internet connection.

First you need to install virtualbox, which is available in the debian repos (sudo apt-get install virtualbox virtualbox-guest-additions), and -- in order to enable USB 2 support --  the "VirtualBox 4.1.8 Oracle VM VirtualBox Extension Pack" from https://www.virtualbox.org/wiki/Downloads
Start virtualbox and go to  File/Preferences/Extensions to install the extension pack you downloaded.

 --- START HERE ---

Installing debian (or any os) on an external USB stick/drive using virtualbox
a. Start virtualbox and click on New.

b. Click through the Name, Operating System and Version questions, Select a memory size which is reasonable for the intended use and target machine. Give it at least 256 Mb. Don't fret about this step -- on each boot your system will autodetect the amount of available RAM. The next question is the key to the whole undertaking: DO NOT SET A START-UP DISK (or any virtual harddisk)

In the next dialogue box you'll be asked if you want to continue or go back - yes, you want to continue.

c. Your new machine is now ready to be set up. Select it and click on settings; Got to storage, IDE controller and choose a virtual CD/DVD disk file. Select the debian installation iso.

d. Next click on USB, enable USB 2 controller, and add a filter for your device by e.g. hitting alt+insert and selecting it from the list.


e. You're ready to install! Start the virtual machine, and the installation should start without you having to select boot device. Most of the setting are the same as in any normal install. Pay attention when you come to the Partition Disk dialogue though. Make sure that you're not doing something silly and accidentally deleting something you shouldn't be a-deleting, even though the risks of that are very slim.

Delete the existing partitions and create a new one. I added a tiny swap space too, hoping that this will make the difference between a freeze and a slow crawl on underpowered systems.
f. Continue with the installation as normal.



g. Postscript:
* /dev/sda1 vs UUID. Once you're done with the installation  and have shut down your virtualbox, mount the USB drive as a normal thumb drive and have a look at fstab in particular -- if you're using relative paths (e.g. sda) instead of absolute paths using UUID, you may run into problems at some point.




In the screengrab you see that

# / was on /dev/sda1 during installation
UUID=8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca /               ext4    errors=remount-ro 0       1

Which means we're good.

You may want to comment out
/dev/sda1       /media/usb0     auto    rw,user,noauto  0       0
/dev/sda2       /media/usb1     auto    rw,user,noauto  0       0
/dev/sda5       /media/usb2     auto    rw,user,noauto  0       0

But I haven't in the past and all has been good.

* network interfaces -- you may find that no network interface is configured for you and that no interface shows up when you use ifconfig. Use ip addr to get a list over interfaces. If the interface is e.g. eth2, you may  want to edit /etc/network/interfaces and add

auto eth2
iface eth2 inet dhcp

or (the ip's are just examples)

auto eth2
iface eth2 inet static
address 192.168.1.100
gateway 192.168.1.1
netmask 255.255.255.0

And then run sudo service networking restart

That's it. You now have a full installation on either a 'removable' drive or on an HDD which you can install in a desktop/laptop.


Links to this page:
http://vk.com/topic-50603_27808581
http://forum.debian.org.tr/arsiv-konu-391.0-debian-live-usb.html
http://alsamixer.wordpress.com/2012/10/07/installing-debian/
http://cv.uoc.edu/app/phpBB3/viewtopic.php?f=3511&t=20897
http://www.computerbase.de/forum/showthread.php?t=1208228&p=13936928

17 February 2012

70. Bug in Debian version of Gnuplot 4.4.0

The symptom:

Gnuplot 4.4.0-1.1 (the current Debian version) can't handle numbers smaller than 10**(-9) properly
e.g.
me@beryllium:~/Dropbox$ gnuplot
G N U P L O T
Version 4.4 patchlevel 0
last modified March 2010
System: Linux 3.2.0-1-amd64
Copyright (C) 1986-1993, 1998, 2004, 2007-2010
Thomas Williams, Colin Kelley and many others
gnuplot home:     http://www.gnuplot.info
faq, bugs, etc:   type "help seeking-assistance"
immediate help:   type "help"
plot window:      hit 'h'
Terminal type set to 'wxt'
gnuplot> print 10**(-9)
1e-09
gnuplot> print 10**(-10)
7.09186959928599e-10
gnuplot> print 10**(-11)
8.22536045240377e-10

It's not related to set zero.

gnuplot> set zero 1e-20
gnuplot> print 10**(-11)
8.22536045240377e-10
gnuplot> print 10**(-10)
7.09186959928599e-10
gnuplot> print 10**(-9)
1e-09
gnuplot> 

Currently, I'm using version 4.4.0-1.1 -- which is used in all versions of Debian.


me@beryllium:~$ apt-cache showpkg gnuplot
Package: gnuplot
Versions:
4.4.0-1.1 (/var/lib/apt/lists/ftp.au.debian.org_debian_dists_testing_main_binary-amd64_Packages) (/var/lib/apt/lists/ftp.au.debian.org_debian_dists_stable_main_binary-amd64_Packages) (/var/lib/apt/lists/ftp.au.debian.org_debian_dists_unstable_main_binary-amd64_Packages) (/var/lib/dpkg/status)
..
Dependencies:
4.4.0-1.1 - gnuplot-nox (2 4.4.0-1.1) gnuplot-x11 (2 4.4.0-1.1) gnuplot-doc (2 4.4.0-1.1)
Provides:
4.4.0-1.1 -
Reverse Provides: 

The bug affects the output from the print statement as well as the internal handling of numbers:




gnuplot> plot 10**(-11)
Warning: empty y range [8.22536e-10:8.22536e-10], adjusting to [8.14311e-10:8.30761e-10]



gnuplot> plot 10**(-12)
Warning: empty y range [-1.3748e-09:-1.3748e-09], adjusting to [-1.36105e-09:-1.38855e-09]
gnuplot> plot 10**(-12)/10**(-10)
Warning: empty y range [-1.93855:-1.93855], adjusting to [-1.91917:-1.95794]





gnuplot> set xrange [10**(-9):10**(-12)]
gnuplot> plot x 



The bug is similar to this: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=360087

Integer overflows are not reported. A hint could be printed that real
(float) numbers should (could) be used to avaid this problem.
gnuplot> print 1000000*100000
1215752192
gnuplot> print 1000000**2
-727379968
gnuplot> print 100000**2
1410065408
gnuplot> a=2000000**2
gnuplot> print a
1385447424
gnuplot> print 10000**2 # OK
100000000
which ended up with "Added tag(s) wontfix. "
Ergo, if you're using debian and you are using gnuplot for serious purposes (research, work), compile your own version of gnuplot as per below.


ANNOYING: there are packages such as maxima which depend on gnuplot. Remove the debian version of gnuplot using apt-get and you lose maxima too. Octave, which one would think would be a heavier user of gnuplot, does not depend on gnuplot but merely recommends it.


Package: maxima                        
State: not installed
Version: 5.26.0-3
Priority: optional
Section: math
Maintainer: Camm Maguire <camm@debian.org>
Uncompressed Size: 47.8 M
Depends: libc6 (>= 2.3), libgmp10, libreadline6 (>= 6.0), libx11-6, gnuplot-x11
Maybe time to build your own maxima.deb? In the end you will end up with a very inelegant system with mixed packages.


Upstreams:
I've compiled and checked the current upstreams version:

me@beryllium:~$ sudo apt-get autoremove gnuplot gnuplot-nox
cd ~/temp
wget http://downloads.sourceforge.net/project/gnuplot/gnuplot/4.4.4/gnuplot-4.4.4.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fgnuplot%2Ffiles%2F&ts=1329439455&use_mirror=aarnet
 mv gnuplot-4.4.4.tar.gz\?r\=http\:%2F%2Fsourceforge.net%2Fprojects%2Fgnuplot%2Ffiles%2F gnuplot-4.4.4.tar.gz
tar -xvf gnuplot-4.4.4.tar.gz
./configure
make 
sudo checkinstall


me@beryllium:~/temp/gnuplot-4.4.4$ sudo dpkg -i gnuplot_4.4.4-1_amd64.deb
(Reading database ... 446323 files and directories currently installed.)
Preparing to replace gnuplot 4.4.4-1 (using gnuplot_4.4.4-1_amd64.deb) ...
Unpacking replacement gnuplot ...
Setting up gnuplot (4.4.4-1) ...
Processing triggers for man-db ...
me@beryllium:~/temp/gnuplot-4.4.4$ gnuplot
G N U P L O T
Version 4.4 patchlevel 4
last modified November 2011
System: Linux 3.2.0-1-amd64
Copyright (C) 1986-1993, 1998, 2004, 2007-2011
Thomas Williams, Colin Kelley and many others
gnuplot home:     http://www.gnuplot.info
faq, bugs, etc:   type "help seeking-assistance"
immediate help:   type "help"
plot window:      hit 'h'
Terminal type set to 'x11'
gnuplot> print 10**(-9)
1e-09
gnuplot> print 10**(-10)
1e-10
gnuplot> print 10**(-11)
1e-11
gnuplot> print 3.14*10**(-10)
3.14e-10
gnuplot> print 3.14*10**(-20)
3.14e-20
gnuplot> print 3.14*10**(-21)
3.14e-21
gnuplot> print 3*10**(-12)/(4*10**(-14))
75.0
gnuplot> 

Ergo, upstreams v 4.4.4 works.

Update: Here's my bug report:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=660299

69. Reverse VNC using vncviewer and tightvnc

Reverse VNC is a good way of helping people remotely. It requires that your IP is remotely accessible, but it does NOT require that the client's IP is public.

This is based on http://ubuntuforums.org/showthread.php?t=299489 and https://caedesnotes.wordpress.com/2010/01/08/remote-administrationtech-support-with-reverse-vnc/ but with screenshots. If both of you are using linux but you for some reason prefer vnc over ssh, have a look at that link for how to do (i.e. using x11vnc on the client)

Like a lot of people I have parents. Like most of those people, my parents aren't too interested in augmenting their computer skills. Which is fine. But trying to explain over the phone where to click etc. gets old really fast -- VNC is an advantage here if they are running windows. Parents also tend to appreciate lots of screenshots -- so I've provided that. It's running on a French version of XP -- it's my way of indirectly learning and keeping my French alive.

-- START HERE --

The situation:
You're running linux. The client is running Windows. You are you, the person you're helping is The Client.
Set up your system before having the client follow the instructions here. I put the client instructions first so you can send them to this page.



The Client:
They are running Windows. They don't have a public IP. Here's what they should do:

1. Download tightvncviewer from here: http://www.tightvnc.com/download.php

2. Installation of tightvnc

a) Install both client and server or only server. It doesn't matter -- the server is important here.


b) During setup, make sure that you check all the boxes as shown below


You will not need to share your password with the person helping you. Make sure not to leave these blank.


c) Tightvnc requires the administrator password to be able to accept connections.

Right-click on the icon in the taskbar tray, and click on Configuration...

Change main server port to 5500. We're doing this to be consistent.
You may de-select 'Serve Java Viewer to Web clients)




The steps above you will only need to do once.

The following steps you will need to do each time you want to get help:
1. Right-click on the vnc icon in the taskbar tray. Select Attach Listening Viewer...

2. In Hostname or IP address of the viewer, type the IP address given to you by the person helping you. In this example it's 192.168.1.102, but it can be anything. Append ::5500 to the IP address. In our example, the input is 192.168.1.102::5500


That's it. If something not described here is happening, make sure to tell the person helping you. Especially if messages about Blocked programmes or Firewalls come up.

You (linux person):
Your public IP is 192.168.1.102 in the example above. Your port 5500 is open to the world.

sudo apt-get install vncviewer

Start your listening session by

vncviewer -compresslevel 9 -listen 0
vncviewer -listen: Listening on port 5500
vncviewer -listen: Command line errors are not reported until a connection comes in.


Once the connection is started by the client you get:
Connected to RFB server, using protocol version 3.8
Enabling TightVNC protocol extensions
No authentication needed
Authentication successful
Desktop name "tantalum"
VNC server default format:
  16 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 31 green 63 blue 31, shift red 11 green 5 blue 0
Using default colormap which is TrueColor.  Pixel format:
  32 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
You can play around with the compresslevels which runs from 0 to 9. Make sure to keep an eye on your firewall log -- your client/parent may easily get frustrated if things aren't working -- and you really don't want to be the cause of it.


Notes:
iptables
I tested this by running windows xp in virtualbox on one linux box, 192.168.1.1, and piped the vnc connection through to another linux box at 192.168.1.102. The firewall settings I had to do were:

On 192.168.1.1

Open port 17500 to tcp traffic from 192.168.1.102 to 255.255.255.255:
sudo iptables -A INPUT -i eth1 -s 192.168.1.102 -d 255.255.255.255 -p tcp --dport 17500 -j ACCEPT


On 192.168.1.102
Open port 5500 to tcp traffic destined for 192.168.1.102:
sudo iptables -A INPUT -d 192.168.1.102 -p tcp --dport 5500 -j ACCEPT