Blog
Cloning Logical Volumes on Linux
27 December 2015
I recently damaged my Windows 7 installation upgrading to Windows 10. The root cause was my dual-boot configuration with Gentoo Linux. Due to having the EFI partition on a drive separate from the drive containing the Windows (C:\), the installation failed. The error message was entitled "Something Happened" with the contents "Windows 10 installation has failed." This took a lot of time to debug, and unfortunately, using Bootrec and other provided tools on the Windows 10 installation medium did not resolve the issue.
Here are the steps I followed to back up my Linux data.
Created a LVM (Logical Volume Management) snapshot volume proving a stable image for the back up. The L parameter specifies how much space to set aside for filesystem writes that happen during the back up. # lvcreate -L512M -s -n bk_home /dev/mapper/st-home
Mounted the snapshot volume. As I was using XFS, I needed to specify the nouuid option or the mount would fail with a bad superblock. # mount /dev/st/bk_home /mnt -onouuid,ro
Used tar to back up the directory and piped the output to GPG to encrypt the contents (as this will be going to a external HDD not covered under my LUKS encrypted volume). Because this back up was only stored temporarily, I opted for symmetric encryption to simplify the process. # tar -cv /mnt | gpg -c -o /media/HDD/st-home.tar.gpg
The above was repeated for each of my logical volumes.
After the backup completed, I removed the snapshot volumes. # umount /mnt # lvremove /dev/st/bk_home
I then created a checksum to be used later.
$ sha1sum /media/HDD/*.xz.gpg > checksum.txt
Next, I formatted both of my harddisks and let Windows partition my SSD as appropriate. According to this Microsoft article, Windows by default will create a partition layout as follows.
1. EFI partition [> 100MB]
2. Microsoft reserved partition [16MB]
3. Placeholder for utility partitions
4. Windows partition [> 20GB]
5. Recovery tools partition [300MB]
Because I wanted both Windows and the Linux root filesystem to exist on the same drive, I added a boot partition and a large LVM partition in the placeholder, resulting in the following scheme:
512Gb SSD 1. [256MB] EFI2. [16MB] Microsoft reserved
3. [256MB] /boot
4. [192GB] LVM
5. [8GB] Free space
6. [192GB] Windows partition
7. [300MB] Recovery tools
8. Free space
Recovering my Linux configuration was as simple as booting from the Gentoo live CD, installing Grub to the EFI partition, and restoring the partitions from the snapshot.
Google public WiFI 29 August 2015
Short post: when you agree to the terms and conditions of Google sponsored WiFi (e.g. at Starbucks) your DNS resolution settings are updated to point to Google's DNS servers. While this does result in hands-off protection from malicious websites it also enables Google to track your browsing habits and gather a large representative sample of the habits of people that use that particular WiFi network.
In Linux, look at your /etc/resolv.conf to determine if your DNS server has changed. Google's servers are: 8.8.8.8 and 8.8.4.4.
I recommend checking this file each time you connect to a public WiFi network.
Arch Linux on Dell M6800 29 August 2015
I have not upgraded my computer systems for a while and have been using a combination of Windows 7 and Mac OS X as my main OSes. Recently, I had the opportunity to purchase a Dell M6800. Below is a walkthrough of how I got Arch Linux configured on this monster of a machine.
Summary Pros - Blazing fast machine, faster than a top-of-the-line Macbook Pro (mid-2015) Retina model tested at the Apple Store on loading webpages (tested NYT, The Verge, BBC, and Engadget).
Cons - Too large to conveniently lug around - Heavy
Applications Used: Mutt (email), Firefox (web browsing), rxvt-unicode (terminal), dwm (window manager), irssi (irc)
Partitioning
This computer was configured with two hard discs: a 512GB SSD and a 512GB HDD. The first was used as the boot drive. It has been a long time since I configured a hardware (not VM) Linux machine from scratch and spent several hours selecting the optimal partition layout to set me up for the next 5 years. I wanted a partition layout that was easy to reconfigure, hard to configure improperly, and encryptable.
Before even considering the layout, I had to choose which partition table format I would go for. In the past, I would opt for the Master Boot Record (MBR) format which gave me interoperability with Windows. Now, with Windows 8 and beyond requiring UEFI support for Windows 8 certified PCs, there is no real reason to stick with MBR. For this machine, I selected the GUID partition table (GPT).
With that in mind, I considered the following scenarios:
(1) Simple scheme using GPT In the past, due to the requirement of dual-booting for university, I had opted for a MBR configuration. I considered for this machine the following layout.
Partition 0: EFI boot, 256MBPartition 1: Windows, 256GB
Partition 2: /boot, 256MB
Partition 3: / (root), 64GB
Partition 4: /home, remainder of space
Benefits of this layout was that it was simple. Drawbacks: could not easily modify in the future without copying data to an external disc and copying back. Also, it would be a waste of space if I did not use Windows.
Furthermore, with /home and / separated, I would have to set up encryption twice so I could make mistakes that would render encryption useless or open up attack opportunities.
(2) Linux Unified Key Setup upon Logical Volume Management (LUKS upon LVM) This setup would give me all the flexibility of LVM with the added benefit of encryption. This means, I could extend a logical volume within Linux across multiple drives in the event my SSD ran out of space or, say, I wanted to implement a RAID configuration. Unfortunately, again, this would require multiple partitions and key configurations which would be cumbersome to manage.
(3) LVM upon LUKS This setup would prohibit me from doing the above in (2), namely, spreading out partitions across physical media. However, it would be the easiest to configure and would give me encryption across my entire drive. Because I had an SSD, I was not too concerned about any r/w performance penalty that I would likely encounter having all these abstractions in place. Here is the partition scheme I opted for, using the GPT.
Partition 0: EFI system, 256MBPartition 1: Linux boot, 256MB
Partition 2: Linux LVM, remainder of space, encrypted
You will notice that a Windows partition isn't included here. Because I am using LVM, I can create space for it if I do decide to install Windows upon a separate partition.
I configured the above with the following commands (after booting into the Arch Linux setup disc).
Using GDisk, performed as root
#> gdisk /dev/sda #configure my SSD(gdisk)> o # create a new GPT
(gdisk)> n # create the EFI partition
(gdisk)> [enter] # default partition number
(gdisk)> [enter] # default sector
(gdisk)> +256M # make the partition size 256MB
(gdisk)> ef00 # make the filesystem type EFI
(gdisk)> n # create the boot partition
(gdisk)> [enter] # default partition number
(gdisk)> [enter] # default sector
(gdisk)> +256M # make the partition size 256MB
(gdisk)> 8300 # make the filesystem type Linux FS
(gdisk)> n # create the LVM partition
(gdisk)> [enter] # default partition number
(gdisk)> [enter] # default sector
(gdisk)> [enter] # up to last sector
(gdisk)> 8e00 # Linux LVM filesystem type (gdisk)> w # write changes to disc Using LVM, performed as root #> lvmdiskscan # list available disks found by lvm
/dev/sda1 [ 256.00MiB]
/dev/sda2 [ 256.00MiB]
/dev/sda3 [ 465.26MiB]
0 disks
3 partitions
0 LVM physical volumes
#> pvcreate /dev/sda3
#> vgcreate root /dev/sda3
#> lvcreate -L 32GB vg0 -n root
#> lvcreate -L 8GB vg0 -n tmp
#> lvcreate -L 8GB vg0 -n swap
#> lvcreate -L 64GB vg0 -n home
Create the file systems In the past, I would have went for ext4, but wanted to really make sure I was taking advantage of my SSD (despite the performance penalty from LVM and encryption), so I went with XFS.
#> mkfs.xfs /dev/vg0/root#> mkfs.xfs /dev/vg0/home
#> mkfs.xfs /dev/vg0/tmp
So, now I have achieved my initial scenario. The Arch Linux Installation guide shows how to mount the file system and install packages as appropriate.
A few motos that we live by...
“Be a yardstick of quality. Some people aren’t used to an environment where excellence is expected.”— Steve Jobs
“The bitterness of poor quality remains long after the sweetness of low price is forgotten.”— Benjamin Franklin
“Quality is not an act, it is a habit.”— Aristotle