Debian Stretch 9 - Install to an USB memory and run from it like it was a disk
This note is about actually installing Debian Stretch 9 onto an USB memory and the run the system from it, like it was a regular harddrive. It is not about putting a live ISO on a USB stick. Some requirements: - Machine running Debian Stretch 9 - USB memory with at least 4 GB - Root access - Internet access Note, the most obvious way to do this should be by connecting the USB memory to the host machine, in VirtualBox give it to the client machine and then just install to it. This works until you to boot of the new installation as of VirtualBox 5.2, then you get FATAL: Could not read from the boot medium! System halted. This is because VirtualBox BIOS does not seem to support booting from USB devices. Therefore in this guide is the USB memory connected as a disk to the VirtualBox.
Select ISO depending on USB size
You may select the installation ISO depending on the size of the USB memory. I found that Debian 9.9 MATE Live consumed a whole 4 GB stick so much that the installation aborted, while the net install without any graphical interface only consumed 1022 MB. Then adding MATE desktop by installing mate-desktop-environment(-core) consumes additional 750-1300 MB. For Debian I found the following size limits: 1 GB - too small for Debian 9.9 2 GB - console mode works, too small for MATE Desktop (1.9 GB in total when I tried), maybe other desktop environment may fit 4 GB - fits MATE Desktop, web browser, partition and text editor, This guide follow the minimal path and therefore does a small install and then add the necessities afterwards. To get the minimal installer, download the latest Debian network install from minimal CD ISO: https://www.debian.org/CD/netinst/
Run the installer
To run the installer you usually put it onto an USB memory, and boot the machine off it. You may do so if you have two USB memories - one for the live ISO and one as install target. But if you don't, you may do the install with VirtualBox, the instructions here goes that way. One benefit with this method is that grub will not be bothered with regular disks as the VirtualBox machine will only have the USB memory. Install VirtualBox: https://wiki.debian.org/VirtualBox When VirtualBox is properly installed, connect the USB memory to the system, if it is not already connected.
Preparing the disk file for the USB memory
Find out the device name of it on the host, by Gparted, df or dmesg|tail. It should be something like /dev/sdb. Warning, make sure you get the correct name, wrong one will set the wrong memory or disk as target. As root, go to your desktop folder and there create a VirtualBox hard drive file that points to the USB memory - replace /dev/sdX with the path to your USB memory. cd cd Desktop (or cd Skrivbord in Swedish) su VBoxManage internalcommands createrawvmdk -filename "usb.vmdk" -rawdisk /dev/sdX You get a file named usb.vmdk. Start a root shell and run VirtualBox: su virtualbox & In VirtualBox, create a new machine, set Debian 64-bit as OS and do not create a hard drive, instead select the usb.vmdk file previously created. In the VirtualBox machine disk drive insert the Debian ISO file and start the VirtualBox machine.
Follow normal install procedure, but when asked for swap do not create one. Edit the partition table so you only have one partition, a bootable ext4 with root (/). Install grub onto it. Installation should proceed without problem, when installed, unmount the ISO and boot. You now have an VirtualBox that boots off a USB memory. One problem I found was that the initial grub boot loader install used /dev/sdX references instead of UUID references in its configuration file. This results in inability to boot the USB memory outside VirtualBox, because /dev/sdX differ between machines. There are vague suggestions on how to make grub use UUID references instead. But I found that grub seems to solve this on it's own. What I did was only these simple commands in the VirtualBox machine: apt-get update apt-get upgrade update-grub This silently replaced the /dev/sdX paths with UUID= references and made it bootable outside VirtualBox. I did not change any configuration files. In the VirtualBox you may also want to edit /etc/fstab and add noatime, to stop adding access times to every file read from. Edit the line that looks like the one below so it has noatime in its options: UUID=<your uuid> / ext4 noatime,errors=remout-ro 0 1 Run df -h to check how much space you have left. On Debian Stretch 9 with a 4 GB USB memory I had used only about 865 MB (1022 MB with 9.9).
Add more - sudo, WiFi drivers
Basic needs, get vim, sudo, WiFi-drivers for Intel cards. Edit /etc/apt/sources.list, edit the line and add contrib non-free, like this: deb http://ftp.se.debian.org/debian/ stretch main contrib non-free deb-src http://ftp.se.debian.org/debian/ stretch main contrib non-free su apt-get install sudo firmware-iwlwifi adduser <username> sudo sudo +3108 kB firmware-iwlwifi +46,7 MB
Add more - console tools
If you intend to run this as a console only system, you may want to install some more. net-tools is ifconfig and pciutils is lspci. su apt-get install net-tools htop vim pv iotop pciutils lshw memtest86 Also edit /etc/default/grub and decrease the timeout at GRUB_TIMEOUT=<seconds> and show the log on boot by editing so it contains GRUB_CMDLINE_LINUX="" without quiet. Also edit /etc/ssh/sshd_config to get root login allowance. Uncomment so it says: PermitRootLogin yes Then: service sshd restart
Add more - Login manager and Graphical interface with
Comparison of desktop environment disk consumption: apt install xfce4 = +600 MB xfce4 xfce4-goodies = +656 MB lxde-core = +670 MB mate-desktop-environment-core = +773 MB (not enough applications for me at least) kde-plasma-desktop = +1598 MB task-xfce-desktop = +2071 MB task-lxde-desktop = +2130 MB cinnamon-desktop-environment = +2904 MB task-gnome-desktop = +3011 Graphical interface with LightDM and MATE desktop: su apt-get install lightdm mate-desktop-environment-core mate-applets network-manager network-manager-gnome mate-power-manager network-manager +21 MB network-manager-gnome +15MB You need the gnome package to get the network status applet working. The power manager is to manage how it handles lid open/closing and power buttons. Edit /etc/NetworkManager/NetworkManager.conf to make the network applet manage the interfaces, change the section below so managed says true: [ifupdown] managed=true Restart network manager: su service network-manager restart I also had to restart the virtual machine to get the network connection icon. To get auto-login with LightDM, edit /etc/lightdm/lightdm.conf, find the #autologin-user= line, comment it out and fill in the username to login. If you want to autologin, then you do not want to enter password to unlock the keyring either. Install seahorse: su apt-get install seahorse Run it as the local user: seahorse Then right click on Login in the left panel, select change password, enter the password, then when prompted for a new one leave them blank and ignore the warning. You will then not be prompted for login each time. Gparted partition editor, Synaptic package manager, Pluma text editor, Chromium/Firefox, git, smartmontools:
Add more - Partition editor, package manager, web browser
su apt-get install gparted synaptic pluma chromium git smartmontools firefox-esr firefox-esrl10n-sv-se gparted +12,1 MB If you install Google Chrome / Chromium, you may want to move the cache to a RAM disk: https://www.omgubuntu.co.uk/2010/11/move-google-chrome-cache-to-ramdisk For Firefox no RAM disk is needed: https://lifehacker.com/speed-up-firefox-by-moving-your-cache-to-ram-no-ram-di-5687850
Add more - remote desktop client
To get Remmina, add Backports. Edit /etc/apt/sources.list, add this: deb http://ftp.debian.org/debian/ stretch-backports main contrib Then update sudo bash apt-get update apt install -t stretch-backports libssh-4 remmina An alternative if Remmina is too big is rdesktop.
This is a personal note. Last updated: 2019-06-24 17:49:52.