Arch Linux crypto installation

After live cd is loaded you need to setup network connection. For ethernet follow the next steps:

ip link set eth0 up #set interface up
ip addr add broadcast dev eth0 #set ip address
ip route add default via #set gateway

Setting gateway in the example above may fail. If so, you can try next commands:

ip route add dev eth0
ip route add default via dev eth0

It is good to set right time now:

timedatectl set-ntp true

Next step is to prepare our filesystems. We will be using LVM on LUKS. For /boot i am using partition on my USB flash drive /dev/sdb1 formatted to ext2. Encrypted partition with LUKS is /dev/sda1, you may choose whatever you want.

So lets create LUKS encrypted partition:

cryptsetup -v --cipher aes-xts-plain64 --key-size 512 --hash sha512 luksFormat /dev/sda1

You need to enter secure password in prompt, so choose wisely. Now open our partition:

cryptsetup luksOpen /dev/sda1 lvm

We opened encrypted partition /dev/sda1 as lvm name and it is now available at /dev/mapper/lvm. To create LVM follow the next steps:

pvcreate /dev/mapper/lvm #create physical volume
vgcreate ArchVol /dev/mapper/lvm #create volume group named ArchVol
lvcreate -L 4G ArchVol -n swap #in ArchVol create 4GB partition named swap
lvcreate -l 100%FREE ArchVol -n root #in ArchVol create partition named root filled all remaining space

After this time to format our new logical partitions:

  • root available at /dev/mapper/ArchVol-root
  • swap available at /dev/mapper/ArchVol-swap
  • boot is my USB flash drive at /dev/sdb1
mkfs.ext4 /dev/mapper/ArchVol-root
mkswap /dev/mapper/ArchVol-swap
mkfs.ext2 /dev/sdb1

Mount aour filesystems and activate swap:

mount /dev/mapper/ArchVol-root /mnt
mkdir /mnt/boot
mount /dev/sdb1 /mnt/boot
swapon /dev/mapper/ArchVol-swap

Okay, now exact Arch installation:

pacstrap /mnt base

This bootstraps base system. To generate our /etc/fstab accordingly to mountpoints:

genfstab -U /mnt >> /mnt/etc/fstab

Now lets chroot to our system:

arch-chroot /mnt

Inside we need to set proper timezone and time:

ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
hwclock --systohc

To setup locales just select and generate them:

nano /etc/locale.gen
/etc/locale.conf LANG=en_US.UTF-8

Fill the hostname:

nano /etc/hostname
nano /etc/hosts

Arch Linux has many available ways to configure network. So i am using systemd-networkd. For wired ethernet connection create the next config /etc/systemd/network/

Name = eth0

Address =
Gateway =

We are almost done. The few things which are left is generating initramfs image and installing bootloader. Our initramfs image must be configured with extra features such as lvm and encrypt. Edit configuration file /etc/mkinitcpio.conf:

HOOKS="...  encrypt  lvm2  ...  filesystems  ..."
MODULES="i915"  #if you use intel graphics

Generate initramfs: mkinitcpio -p linux

Set root password: passwd root

Install and configure bootloader:

pacman -S grub

Next you need to add your encrypted partition UUID to grub config. You can get it by running next command:

blkid /dev/sda1

# example output
/dev/sda1: UUID="cddd0a60-8281-4a09-8cce-1c5cb8849f62" TYPE="crypto_LUKS" PARTUUID="61979b00-998a-409d-aeb1-08e50f45023c"

Note the UUID part. Add it to /etc/default/grub:


Install bootloader to MBR of our USB flash drive and generate config:

grub-install --target=i386-pc /dev/sdb1
grub-mkconfig -o /boot/grub/grub.cfg

At this point we have everything done. Time to unmount our partitions and reboot.

umount /mnt/boot
umount /mnt
swapoff /dev/mapper/ArchVol-swap

Congratulations! Enjoy your fresh Arch Linux system on encrypted partition and boot USB flash drive as a key!

Arch Linux crypto installation

Network Manager restart after suspend/hibernate

Open a terminal and type the following:

sudo nano /etc/systemd/system/wifi-resume.service Now paste the script in there with a right click. Exit with CTRL + X and press Y to save. Now to activate it: sudo systemctl enable wifi-resume.service


#sudo systemctl enable wifi-resume.service
Description=Restart networkmanager at resume

ExecStart=/bin/systemctl restart network-manager.service


Hope this helps. It works on my laptop.

Network Manager restart after suspend/hibernate

GPG Quick Start

A quick HOWTO for getting started with GnuPG.

Your Key

Private and public keys are at the heart of gpg’s encryption and decryption processes. The best first step is to create a key pair for yourself.

Generate a private key.

gpg --gen-key

You’ll have to answer a bunch of questions:

What kind and size of key you want; the defaults are probably good enough.

How long the key should be valid. You can safely choose a non-expiring key for your own use. If you plan to use a key for public signing, you might want to consider a yearly expiration.

Your real name and e-mail address; these are necessary for identifying your key in a larger set of keys.

A comment for your key, perhaps to distinquish a key used for special tasks like signing software releases. The comment can be empty.

A passphrase. Whatever you do, don’t forget it! Your key, and all your encrypted files, will be useless if you do.

Keyserver Registration

You might also want to register your key with public keyservers so that others can retrieve your key without having to contact you directly.

First up, you need to identify your key’s ID or fingerprint. The former is easier to use, the latter a bit more secure.

In the example below,

  • the ID is 8F54CA35; it’s on the line marked pub;
  • the fingerprint is 00E5 2D6D 91C0 20D0 F596 2CC5 1E36 9C62 8F54 CA35.
[~]$ gpg --fingerprint heinlein
pub   1024D/8F54CA35 2000-11-10
      Key fingerprint = 00E5 2D6D 91C0 20D0 F596  2CC5 1E36 9C62 8F54 CA35
uid                  Paul Heinlein <>
uid                  [jpeg image of size 3853]
uid                  Paul Heinlein (Galois, Inc.) <>
sub   1024g/6088B91E 2000-11-10

To send them, you’ll need to locate a public key server. MIT’s is well known, but there are others.

# using ID (GnuPG versions 1 and 2)
gpg --keyserver --send-keys '8F54CA35'
# using fingerprint (GnuPG version 2 and higher)
gpg --keyserver \
    --send-keys '00E5 2D6D 91C0 20D0 F596  2CC5 1E36 9C62 8F54 CA35'

ASCII Version

You may also want to generate an ASCII version of your public key for distribution by e-mail or posting on a web site.

gpg --armor --output pubkey.txt --export 'Your Name'

Encrypting a file for personal use

Encrypting files for your personal use is quite easy.

Encrypt a file called foo.txt. The argument to the --recipient option should be the all or part of the name you used when generating your private key.

# the long version
gpg --encrypt --recipient 'Your Name' foo.txt

# using terse options
gpg -e -r Name foo.txt

The encrypted version of the file will by default be named foo.txt.gpg. You can modify that behavior using the --output (-o) option.

Decrypt the encrypted file. You’ll be asked to provide the passphrase you used when generating your private key. If you don’t use the --output option, the contents of the encrypted file will be sent to standard output.

gpg --output foo.txt --decrypt foo.txt.gpg

Encrypting a file for someone else

The really cool thing about GnuPG is that you can safely encrypt files for others using publicly available keys.

Import your friend’s key, which you might have received via e-mail or on a floppy. If the file is named key.asc, then just use the --import option to add it to your keyring:

gpg --import key.asc

That’s it! You can verify the import using the --list-keys option.

Alternatively, you might be able to find your friend’s key on a public keyserver. Here’s what a session looks like when someone searches for my key.

[~]$ gpg --keyserver --search-keys 'paul heinlein'
gpg: searching for "paul heinlein" from hkp server
(1)  Paul Heinlein <>
       1024 bit RSA key 8F54CA35, created: 2014-06-16 (revoked)
(2)  Paul Heinlein <>
     Paul Heinlein <>
     Paul Heinlein <>
     Paul Heinlein (Galois, Inc.) <>
       1024 bit DSA key 8F54CA35, created: 2000-11-10
Keys 1-2 of 2 for "paul heinlein".  Enter number(s), N)ext, or Q)uit > Q

A few notes on this:

  • The first result (marked “revoked”) was the result of a failed test I conducted. You can ignore it.
  • My key has several e-mail addresses attached to it. That’s perfectly normal.
  • In the example above, I chose the Q)uit option. Had I pressed 1 or 2, that key would have been downloaded and added to my local keyring.

Once you’ve got the other person’s public key, encrypt a file using it.

gpg --encrypt --recipient '' foo.txt

You’ll end up with a file called foo.txt.gpg that you can send as an e-mail attachment or make available for downloading via ftp or the web.

Decrypting a file from someone else

If someone sends you an encrypted file, the file has typically been encrypted using your public key. Decrypting it is no different than decrypting a file you’ve encrypted for your own use.

gpg --output foo.txt --decrypt foo.txt.gpg

Detached Signatures

GnuPG can come in handy when you want to be assured that the file you’ve just downloaded is the one its creator wants you to have. The OpenVPN developers, for instance, release GnuPG signatures for all their downloads.

To verify a file using its detached signature, you must first have imported the signer’s public key. Assume we’ve downloaded crucial.tar.gz and the developers have also released a signature file, crucial.tar.gz.asc. Once you’re confident that you have the developers’ public key in your local keyring, then the verification step is easy:

gpg --verify crucial.tar.gz.asc crucial.tar.gz

Creating a detached signature is similarly easy. The following example will create a signature for called

gpg --armor --detach-sign

People who have imported your public key into their keyrings can then verify that their version of your file is identical to theirs.

Basic Key Management

After a while, you will probably have several keys in your ring. It’s easy to list them all:

gpg --list-keys

Should you lose trust in or contact with a person with a key in your ring, you’ll want to delete it:

gpg --delete-key ''

For further reading

To move beyond these simple instructions, consult the GnuPG Documentation.


GPG Quick Start

How to backup LXC containers

Moving LXC containers between host systems

This is how I migrate LXC containers between systems. I’ve successfully moved ubuntu based 12.04 containers to a 14.04 host, and they work great.

  • Shutdown the container
    # lxc-stop -n $NAME
  • Archive container rootfs & config
    # cd /var/lib/lxc/$NAME/
    # tar --numeric-owner -czvf container_fs.tar.gz ./*

    The ‘–numeric-owner’ flag is very important! Without it, the container may not boot because the uid/gids get mangled in the extracted filesystem. When tar creates an archive, it preserves user / group ownership information. By default, when extracting, tar tries to resolve the archive user/group ownership names with the ids on the system running tar. This is intended to ensure that user ownership is resolved on the new system, in case the UID numeric values differ between systems.

    This is bad for an LXC filesystem because the numeric uid/gid ownership is intended to be preserved for the whole filesystem. If it gets resolved to a different value, bad things happen.

  • Copy the file to your new server
    # rsync -avh container_fs.tar.gz user@newserver:/var/lib/lxc/
  • Extract rootfs
    # mkdir /var/lib/lxc/$NAME/
    # cd /var/lib/lxc/$NAME/
    # tar --numeric-owner -xzvf container_fs.tar.gz ./*

If you’re using an overlay backed container, you’ll also need to migrate the container this new one is based off of. Lastly, you might see a few warnings about skipped socket files:

tar: /var/lib/lxc/$NAME/rootfs/dev/log: socket ignored

I’ve ignored this error, and haven’t had any issues with any of the containers I manage. If you have further issues, add your error messages to the original post and I’ll elaborate.



How to backup LXC containers

LXC share folder

Exposing a directory on the host machine to an LXC container

  1. Log into the container and create an empty directory, this will be the mount point
  2. Log out and stop the container.
  3. Open to your container’s config file
    • For regular LXC containers: /var/lib/lxc/mycontainer/config
    • For unprivileged LXC containers: $HOME/.local/share/lxc/mycontainer/config
  4. Add a new line above the lxc.mount directive, that follows the format below. Substitute proper paths as necessary:
    • lxc.mount.entry = /path/to/folder/on/host /path/to/mount/point none bind 0 0
    • Both of these paths are relative to the host machine.
    • Location of the root fs in the container can be found at:
      • For regular LXC containers: /var/lib/lxc/mycontainer/rootfs/
      • For unprivileged LXC containers: $HOME/.local/share/lxc/mycontainer/rootfs

Note: If the host’s user does not exist in the container, the container will still be mounted, but with nobody:nogroup as the owner. This may not be a problem unless you need to write to these files, in which case you’ll need to give everybody write permission to that folder. (i.e. chmod -R go+w /folder/to/share)


I want to share /home/julianlam/foobar to my unprivileged container bazquux. In bazquux, I want this folder to be found at /mnt/baz.

In the container:

$ cd /mnt
$ sudo mkdir baz
$ logout

In the host, I will add the following line above lxc-mount in /home/julianlam/.local/share/lxc/bazquux/config:

lxc.mount.entry = /home/julianlam/foobar /home/julian/.local/share/lxc/bazquux/rootfs/mnt/baz none bind 0 0


LXC share folder

Bridge interface for lxc-containers

Script for creating bridge interface and applying  iptable routing rule:



echo 1 > /proc/sys/net/ipv4/ip_forward

Edit the container config:

# Network configuration = veth = up = lxc-br0 = eth0 = 00:FF:AA:00:00:01 = =

Edit the container interfaces:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static

Enjoy the working network inside your lxc-container!

Bridge interface for lxc-containers