Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Ubuntu

Mount a USB stick

Insert the USB stick. First get the device path of the usb stick by running lsblk.

It will look something like, assuming that it has only one partition.

sdb      8:16   1  14.9G  0 disk 
└─sdb1   8:17   1   1.6G  0 part

Get the filesystem type of the partition by running blkid,

sudo blkid /dev/sdb1
/dev/sdb1: UUID="...." TYPE="fat"

Now assuming that path /media exists, mount the partition.

sudo mount -t <type> /dev/sdb1 /media

it will mount the usb drive it to path /media.

Note: Default type is fat.

When done with the USB stick, unmount,

sudo umount /dev/sdb1

and remove the stick.

Debugging kernel or system program crash

File system check

The simplest way to force fsck filesystem check on a root partition eg. /dev/sda1 is to create an empty file called forcefsck in the partition's root directory.

sudo touch /forcefsck

This empty file will temporarily override any other settings and force fsck to check the filesystem on the next system reboot. Once the filesystem is checked the forcefsck file will be removed thus next time you reboot your filesystem will NOT be checked again. Once boot completes, the result of fsck will be available in /var/log/boot.log. Also the ram filesystem used during boot will log it in /run/initramfs/fsck.log. This file will be lost as soon as the system is shut down since the ram filesystem is volatile.

Security

Setting up ubuntu server with lubuntu desktop in a VirtualBox VM

Set up the VM with,

  • 4G memeory.
  • 32G vdi disk.
  • Network: NAT / Host only
  • Clipboard: bidirectional.

Setup linux

Install ubuntu server from server.iso using a USB drive.

Now setup the desktop,

sudo apt-get update
# Install lubuntu desktop
sudo apt-get install lubuntu-desktop
# get guest addition
sudo apt-get install virtualbox-guest-x11

Now go to Start > Preferences > Monitor settings and select a resolution of your choice.

Custom Resolution

First we need to find out what display outputs are available.

$ xrandr -q
Screen 0: minimum 640 x 400, current 1600 x 1200, maximum 1600 x 1200
Virtual1 connected 1600x1200+0+0 0mm x 0mm
   1600x1200       0.0* 
   1280x1024       0.0  
   640x480         0.0  
...

This means Virtual1 is the first output device, there might be more listed. Find which output you want the monitor to connect to.

Lets say we want a monitor resolution of 960 x 600 @ 60Hz.

# get a Modeline 
gtf 960 600 60

Lets say output will look like:

# 960x600 @ 60.00 Hz (GTF) hsync: 37.32 kHz; pclk: 45.98 MHz
Modeline "960x600_60.00"  45.98  960 1000 1096 1232  600 601 604 622  -HSync +Vsync

The string 960x600_60.00 is just an identifier proposed. For the following you can substitute it to anything more meaningful.

Now we will use this Modeline content to set our configuration,

# define a mode
xrandr --newmode "960x600_60.00"  45.98  960 1000 1096 1232  600 601 604 622  -HSync +Vsync
# map this mode to a output
xrandr --addmode Virtual1 "960x600_60.00"

At this point you can switch to the new resolution by going to Start > Preferences > Monitor settings and Selecting the resolution added. Alternatively you can switch mode for the output from the terminal,

xrandr --output Virtual1 --mode "960x600_60.00"

The whole thing can be turned into a bash script,

#!/bin/bash

# get the modeline for the following resolution
RESOLUTION="960 600 60"
# extract modeline settings
SETTINGS=$( gtf $RESOLUTION | grep Modeline | cut -d ' ' -f4-16 )
# define the mode
xrandr --newmode $SETTINGS
# get name of mode from settings
MODE=$( echo $SETTINGS | cut -d ' ' -f1 )
# get the first connected output device
DEVICE=$( xrandr -q | grep "connected" | head -1 | cut -d ' ' -f1 )
# map this mode to the device
xrandr --addmode $DEVICE $MODE
# switch to the new mode
xrandr --output $DEVICE --mode $MODE

Changing the cursor size

To change the size of your mouse cursor, open the desktop configuration file ~/.config/lxsession/lubuntu/desktop.conf, find the key iGtk/CursorThemeSize and update the value to the desired size.

Converting VirtualBox VDI (or VMDK) to a ISO

create raw image

VBoxManage clonemedium turnkey-core.vdi turnkey-core.raw --format RAW

Next, mount the raw disk as a loopback device.

mkdir turnkey-core.mount
mount -o loop turnkey-core.raw turnkey-core.mount

GOTCHA 1: If your VM has partitions, it's a little tricker. You'll need to setup the loop device, partition mappings and finally mount the rootfs partition. You will need kpartx to setup the mappings.

loopdev=$(losetup -s -f turnkey-core.raw)

apt-get install kpartx
kpartx -a $loopdev

# p1 refers to the first partition (rootfs)
mkdir turnkey-core.mount
mount /dev/mapper/$(basename $loopdev)p1 turnkey-core.mount

Extract root filesystem and tweak for ISO configuration Now, make a copy of the root filesystem and unmount the loopback.

mkdir turnkey-core.rootfs
rsync -a -t -r -S -I turnkey-core.mount/ turnkey-core.rootfs

umount -d turnkey-core.mount

# If your VM had partitions (GOTCHA 1):
kpartx -d $loopdev
losetup -d $loopdev

Because the VM is an installed system as opposed to the ISO, the file system table needs to be updated.

cat>turnkey-core.rootfs/etc/fstab<<EOF
aufs / aufs rw 0 0
tmpfs /tmp tmpfs nosuid,nodev 0 0
EOF

GOTCHA 2: If your VM uses a kernel optimized for virtualization (like the one included in the TurnKey VM builds), you need to replace it with a generic kernel, and also remove vmware-tools if installed. You can remove any other unneeded packages.

tklpatch-chroot turnkey-core.rootfs

# inside the chroot
apt-get update
apt-get install linux-image-generic
dpkg --purge $(dpkg-query --showformat='${Package}\n' -W 'vmware-tools*')
dpkg --purge $(dpkg-query --showformat='${Package}\n' -W '*-virtual')

exit

Generate the ISO Finally, prepare the cdroot and generate the ISO.

tklpatch-prepare-cdroot turnkey-core.rootfs/
tklpatch-geniso turnkey-core.cdroot/

this will create my_system.iso

Thats it!

burn it to usb

You can use dd.

usb partition looks like /dev/sd<?><?> where <?><?> is a letter followed by a number.

Look usb disk up first by running lsblk. It will look something like,

sdb      8:16   1  14.9G  0 disk 
├─sdb1   8:17   1   1.6G  0 part /media/username/usb volume name
└─sdb2   8:18   1   2.4M  0 part 

Now you can unmount the usb as following,

 sudo umount /dev/sdb1  

Then, next (this is a destructive command and wipes the entire USB drive with the contents of the iso, so be careful):

 sudo dd bs=4M if=path/to/my_system.iso of=/dev/sdb1 conv=fdatasync  status=progress

Where my_system.iso is the input file, and /dev/sdb1 is the USB device you're writing to.

Reset password

SSH keys