How to create a distraction free writing environment on Debian Linux

This is my writing environment:

It offers:

Note: Text editing is done using Vim. Please don’t stop reading, I promise you can quickly learn to work efficiently with Vim.

What you need:

  1. USB stick with minimum 4GB capacity. It will help (but isn’t mandatory) if it’s a USB 3 stick.
  2. Computer already running Linux (any distribution will do, but this guide will specifically target Debian/Ubuntu)

Note: If you don’t already have a machine running Linux, please contact me and I can provide instructions on alternatives. I will also aim to publish a post soon explaining how to carry out these instructions if you have Windows or MacOS.

These are the steps to follow to create your own distraction free writing environment on Linux:

NOTE: Either append sudo to all commands below, or su to act as root.

1. Install required packages:

apt install util-linux e2fsprogs debootstrap coreutils

2. Insert the USB stick into your computer.

3. Find out what device the USB stick is:


The USB stick will likely be sdb or sdc or similar. Please be confident you know which device it is before continuing.

For the purposes of this guide, I will use sdb to represent the USB stick. If yours differs, please substitute sdb in all cases below. For example your USB stick might be sde, in which case sdb will become sde and sdb1 will become sde1.

4. Unmount the USB stick:

umount /dev/sdb

5. Format the USB stick:

fdisk /dev/sdb

The commands are:

The process will be similar to:

Welcome to fdisk (util-linux 2.29.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x75f802dd.

Command (m for help): p
Disk /dev/sde: 7.2 GiB, 7748222976 bytes, 15133248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x75f802dd

Command (m for help): n
Partition type
p   primary (0 primary, 0 extended, 4 free)
e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-15133247, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-15133247, default 15133247): 

Created a new partition 1 of type 'Linux' and of size 7.2 GiB.

Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

6. Create a file system on the USB stick:

mkfs.ext4 /dev/sdb1

The results will be similar to:

mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 1891400 4k blocks and 473280 inodes
Filesystem UUID: 1363653a-d71a-4a62-ba38-b1b4d3f52bbd
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

7. Install Linux

I have decided to install the 64 bit (amd64) version of the stable release.

Note: You could also use the i386 architecture, or choose stretch (currently testing) or sid releases. For what we want to achieve though, which is a light and stable distraction free writing environment, Debian stable is best.

mkdir ~/tmp/usbstick -p
mount /dev/sdb1 ~/tmp/usbstick
debootstrap --arch amd64 stable ~/tmp/usbstick

Debootstrap will take some time to run, and will result in something to this:

I: Retrieving InRelease 
I: Retrieving Release 
I: Retrieving Release.gpg 
I: Checking Release signature
I: Valid Release signature (key id 75DDC3C4A499F1A18CB5F3C8CBF8D6FD518E17E1)
I: Retrieving Packages 
I: Validating Packages 
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Base system installed successfully.

When debootstrap has finished, mount our paths and chroot into the new system:

mount -t proc none ~/tmp/usbstick/proc
mount --bind /sys ~/tmp/usbstick/sys
mount --bind /dev ~/tmp/usbstick/dev
cp /etc/resolv.conf ~/tmp/usbstick/resolv.conf
chroot ~/tmp/usbstick/

8. Basic setup

Update sources.list:

echo 'deb stretch main contrib non-free' > /etc/apt/sources.list`

Update package sources:

apt update

Install packages (including the all important Vim):

apt install locales sudo vim

Set locale environment variables:

echo 'export LC_ALL="C"'>>/etc/bash.bashrc
echo 'export LANG="C"'>>/etc/bash.bashrc

Set a hostname:

echo ' writer-os >> /etc/hosts'

Source the file so that our changes are active:

source /etc/bash.bashrc

Add your login user (writer), set a password and add the user to the sudo group

useradd -m writer
passwd writer
usermod -G sudo -a writer

9. Make the usbstick bootable

NOTE: Make sure to install grub to /dev/sdb (replace with your sdb/sdc) so that you don’t wreck your main system.

grep -v rootfs /proc/mounts > /etc/mtab
apt install grub-pc linux-image-amd64

Setup your /etc/fstab:

blkid /dev/sdb1 -o export|head -n 1 > /etc/fstab

Find out the UUID of the drive we are installing to:

blkid /dev/sdb1

Edit /etc/fstab (we mount the tmp directory in RAM to minimise USB disk access):

UUID=(insert UUID here)       /       ext4    defaults,noatime,nodiratime,discard,errors=remount-ro,user_xattr    0 1
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0



The results should be similar to:

Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.9.0-2-amd64
Found initrd image: /boot/initrd.img-4.9.0-2-amd64

10. Install various firmware.

We do this so we have basic hardware and network access for updating the system, regardless of what hardware we are running on.

apt install firmware-linux firmware-atheros firmware-brcm80211 firmware-iwlwifi firmware-realtek broadcom-sta-dkms

11. Clean up:

apt-get clean

12. Configure vim

This section is coming soon. For now, you can use Vim with its defaults. But I will add a post soon that describes how to set some better defaults for writers.

13. Finish

Everything is now installed, so we can unmount the USB stick:

umount $HOME/tmp/usbstick/sys
umount $HOME/tmp/usbstick/dev
umount $HOME/tmp/usbstick/proc
umount $HOME/tmp/usbstick/

14. Done!

You can now insert your USB stick in to any computer, use the BIOS to boot from the USB stick, and have your own distraction free writing environment!

If you build this USB writing environment, please let me know how you go.


Posted on Mar 22, 2017 in Articles & How To | Tags: WritingLinuxDebianDistraction FreeProse