Replacing a disk in a BTRFS RAID1 configuration

When your hard drive starts making the clicking sound of death, it’s time to act.

  1. Get a new hard drive.
  2. Run a BTRFS scrub, using btrfs scrub status -d /home to show which drive had the errors (and also to ensure that any errors were corrected on the good disk)
  3. Work out which hard drive is at fault. I had the following information:
    • /dev/mapper/home2 from BTRFS - this one had errors during a scrub, too.
    • ata2 from the kernel message log - the ATA interface kept getting reset.
    • /dev/sdb from GSmartControl - this was the drive with reallocated sectors.
    • Verify using blkid that the UUID for /dev/sdb was the same as the UUID for home2 in /etc/crypttab.
  4. Locate the physical drive. I was able to do this by following SATA cables to the various drives in the system and figuring out the ATA IDs for each SATA port.
  5. Put the new drive into the DVD drive position. (This is probably easier than having to replace a physically removed drive).
  6. Partition the new drive. Ensure you use the same tools, or at least end up with exactly the same partition table. That bit me.
  7. Set up crypto on the new drive
  8. Open the encrypted partition with a different name (e.g. home3). You can end up using the original name, but not while the original drive is mounted.
  9. Add the new drive to the BTRFS RAID array by replacing the old one.
    • Execute btrfs filesystem show /home and find the devid.
    • btrfs replace start <devid> /dev/mapper/home3 /home
    • btrfs replace status /home and watch it progress.
  10. While that’s going, write a blog entry and also update /etc/crypttab and /etc/fstab to use the new drive. Probably should use the nofail mount option in case you make a mistake, so the system still boots into a nice environment.
  11. When it’s all done, remove the old drive.

Posted Friday, June 18, 2021

NetworkManager problems

Just recently, probably after a system upgrade, my work laptop stopped configuring the WiFi interface properly. Manual settings worked, but DHCP and name resolution were broken more often than not. Having to manually running dhcpcd was not impressing me.

I came across these bugs in the Arch bugtracker that were informative.

I don’t know if the machine has gone crazy or if something recently changed in the NetworkManager / systemd worlds. I have disabled systemd-resolved since I don’t see why systemd should be replacing name resolution, so that might be causing trouble. The following fixes it.

First, add this to /etc/NetworkManager/NetworkManager.conf:


This adding the following to /etc/NetworkManager/conf.d/dhcp-client.conf may also be required, although the lack of it isn’t currently causing me problems:


Finally, enable dhcpcd:

% sudo systemctl enable dhcpcd
% sydo systemctl start dhcpcd

Posted Tuesday, January 7, 2020

Raspberry Pi video output

I’m in the process of setting up a Raspberry Pi as a media PC. The GUI configuration panel doesn’t contain a setting for the pixel format — I want to use the whole 8 bits and get proper blacks and whites — and /boot/config.txt wasn’t helping either, as Raspbian Noobs hasn’t put all the possible variables in there. It’s documented here. The variable in question is hdmi_pixel_encoding.

Posted Sunday, November 24, 2019

Record my desktop with ffmpeg

It seems that desktop recording is quite the pest. Not that I’ve tried much, but I also haven’t really found a “go-to” piece of software for X11 that just does it. So the last time I wanted to record my screen, I decided to have a go with just plain command-line tools.

It turns out that this is also ridiculously easy.

ffmpeg -f x11grab -s 500x300 -r 25 -i :0.0 foo.mp4

The -s option tells ffmpeg the pixel size of the region you want to grab; -r is the frame rate, -i is your X screen, and the video is written to foo.mp4.

If you don’t want to start the screen capture in the top-left, just use something like -i :0.0+100,200 to specify where to start and the resolution to capture.

The ffmpeg website has more info.

Posted Tuesday, February 19, 2019

Find and replace in geany

The other day I wanted to do a find-and-replace in geany using a regex in the find. I wanted to turn something like this

Field name: value


Field name: value plus some more

Since geany supports regex searching, I decided it was time to find out how to do regex replacements too. The way it works, is that you put parentheses around each match that you want to be able to use in the replacement string, and then reference these replacements using backslash-number. So the find string becomes

^Field name: (.*)

and the replacement string becomes

Field name: \1 plus some more

That was too easy.

Posted Monday, February 18, 2019

Blog contents