Auto partitioning multiple drives on an LVM using Ubuntu Preseed

My goal: format and partition two separate drives using LVM during an automated Ubuntu install.

The Debian preseed file isn’t, at first glance, as flexible as kickstart files but as with almost everything, once you dig a bit deeper you find out that they just do things differently. I couldn’t find a good reference on formatting multiple drives and I did find a few people saying it wasn’t possible so that was discouraging. In the end, it’s actually quite straightforward.

Generally you need to:

  1. Define your physical volumes and create volume groups
  2. Define your volumes and place them into volume groups
  3. Define sizing parameters to make sensible partition sizes for your expected usage

The working partman configuration is shown below, including some helpful comments. Probably the most confusing thing is what the three numbers do in the logical volume definition. In short, they are minimum size, priority and maximum size. A calculation is performed that assigns space based on an algorithm. I found Tim Bishop’s partman-auto/expert-recipe explanation to be the best explanation out there. Be warned – there is a lot of misinformation floating around about these values.

Here’s the working configuration:

d-i partman-auto/method string lvm

# These options remove any existing LVM and deploy a new system
# Without all of these set like this you can end up with errors
# when you try to reinstall a machine with existing volume groups
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true

d-i partman-auto/expert_recipe string                         \
      pvs ::                                                  \
              20480 750000 750000 ext4                        \
                      $primary{ }                             \
                      method{ lvm }                           \
                      device{ /dev/sda }                      \
                      vg_name{ system }                       \
              .                                               \
              1000000 1000000000 1000000000 ext4              \
                      $primary{ }                             \
                      method{ lvm }                           \
                      device{ /dev/sdb }                      \
                      vg_name{ data }                         \
              .                                               \
      system ::                                               \
              20480 20498 5000000 ext4                        \
                      $lvmok{ }                               \
                      lv_name{ root }                         \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext4 }    \
                      mountpoint{ / }                         \
                      in_vg{ system }                         \
              .                                               \
              2048 2050 8192 linux-swap                       \
                      $lvmok{ }                               \
                      lv_name{ swap }                         \
                      method{ swap } format{ }                \
                      in_vg{ system }                         \
              .                                               \
      data ::                                                 \
              1000000 1000009 -1  ext4                        \
                      $lvmok{ }                               \
                      lv_name{ var }                          \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext4 }    \
                      mountpoint{ /data }                     \
                      in_vg{ data }                           \
              .                                               \
              100000 100001 500000 ext4                       \
                      $lvmok{ }                               \
                      lv_name{ datasnapshots }                \
                      \$defaultignore                         \
                      in_vg{ data }                           \
              .

The expected behaviour from my configuration is:

# '/' = Min size 20GB, max 5,000GB, percentage(18/20) 90%
# 1TB drive = everything apart from swap
20480 20498 5000000 ext4

# 'swap' = Min size 2GB, max 8GB, percentage(2/20) 10%
# 1TB drive = 8GB
2048 2050 8192 linux-swap

# '/data' - Min size 1TB, max unlimited, percentage(9/10) 90%
# 5TB drive = 4.5TB
1000000 1000009 -1 ext4

# '/data snapshots' - Min size 100GB, max 500GB, percentage(1/10) 10%
# 2TB drive = 500GB
100000 100001 500000 ext4

 

Adding all ssh keys automatically to MacOS High Sierra

Since upgrading to High Sierra, I’ve had to manually add keys after every reboot using ssh-add like this:

ssh-add -K

I don’t reboot often but for a while I was rebooting often enough to make it annoying. So I found that you can link ssh with MacOS keychain using your .ssh/config file, add all the keys to your agent, and everything works smoothly.

Host *
UseKeychain yes
AddKeysToAgent yes

Then add all your keys to the keychain using

ssh-add -KA

Change default VPN host in Cisco AnyConnect Mobility Client for OSX

I was constantly annoyed at changing the hostname in my Cisco VPN client. I found a few resources on how to change the default host to connect to on Windows but OSX proved harder. So hopefully, this will help somebody else. It’s actually pretty simple when you know where to look:

vi ~/.anyconnect # Then edit the XML entry for DefaultHostName

If you are a consultant who works with multiple companies and VPNs then you’ll probably find this useful one day too.

2010 13″ MacBook Air cannot create bootable USB stick

After hours of banging my head against the wall trying to create bootable USB sticks on my laptop, I stumbled across this useful titbit of information:

Please notice: While all of the info and above commands are executed properly on a MacBook Air 3,2 (that is the 2010 version 13″ version of the Air) the end result will not produce a bootable USB device, at least not with the image for Ubuntu 10.10 64-bit. When booting of the USB device the following message or something similar will appear: “Missing operating system” and the process is auto-magically halted.

May be useful to somebody. They have a series of steps on the How to install Ubuntu on MacBook using USB Stick page to workaround this but it’s much easier to just find and use another Mac.

Sublime Text / Package Control: error executing: /usr/bin/security dump-trust-settings -d

I received this error when starting Sublime Text after upgrading to El Capitan. The author of package control is aware of the issue (https://github.com/wbond/package_control/issues/1002) and is working on it but if it annoys you enough to do a workaround, here it is.  Remove all of the certificates from your Keychain that are shown when you run the same command: `/usr/bin/security dump-trust-settings -d`

My output looked something like this:

Number of trusted certs = 5
Cert 0: stuff.co
Number of trust settings : 1
Trust Setting 0:
Policy OID : Apple X509 Basic
Allowed Error : CSSMERR_TP_CERT_EXPIRED
Result Type : kSecTrustSettingsResultTrustRoot
Cert 1: GTE CyberTrust Global Root
SecTrustSettingsCopyTrustSettings: The specified item could not be found in the keychain.
Cert 2: Class 3 Public Primary Certification Authority
SecTrustSettingsCopyTrustSettings: The specified item could not be found in the keychain.
  1. Open Keychain
  2. click on your login keychain
  3. Go to the search box
  4. Type in the name shown in the Cert <n>: field (in this case stuff.co)
  5. Select the Certificate entry that is shown in the results
  6. Right-click -> Delete “…”
  7. Enter your password (twice for me)

Continue until you run the dump-trust-settings command and get

SecTrustSettingsCopyCertificates: No Trust Settings were found.

Down to one remote with HDMI-ARC and HDMI-CEC functionality

One of my biggest complaints about getting a home theatre system was the need for multiple remotes.  I know you can buy an all-in-one remote that will manage everything for you but for whatever reason I didn’t do that. I just bought a Samsung Smart TV and decided to look into the state of TV remotes again.

228550581

Last night I learned that I was just ignorant of some progress that had been made in this area by two standards: HDMI Audio Return Channel (HDMI-ARC) and HDMI Consumer Electronics Control (HDMI-CEC).  Using these two technologies, I have tied all of my devices together under one remote control.  I push one power button and everything turns on. I push the volume up button on the TV remote and my receiver volume increases.  I want to go to bed and I hit the power button on the TV and both the TV and receiver turn off.  This is the way things always should have been.

Let’s start with HDMI-ARC.  This is quite simple in concept but solves the persistent issue of how do you get audio from the TV back to your receiver.  Most setups I have done and seen involve Blu-ray players, cable STBs and PS3s sending their video and audio to your home cinema receiver then the receiver sends the video to the TV.  Basically, your TV is a dumb monitor.  This all changed when I got my Samsung Smart TV and tried to watch Netflix on it for the first time.  My picture quality was fine but all the audio was coming from my TV!  Enabling the HDMI-ARC on the TV and my Onkyo receiver solved that problem and now it makes no difference where the audio comes from, my receiver can find it.

Next is HDMI-CEC.  You will find this under various brand names like VIERA Link or Anynet+ but they are mostly compliant with the HDMI-CEC standard.  What it allows you to do is send commands over the HDMI cable so when your TV powers up and it’s on the cable input, it tells your cable box to power up too.  When you switch to Blu-ray, it turns that on for you.  My TV also automatically tied into my receiver’s volume control so when you change the volume on the TV it is actually changing the volume on my home cinema receiver.

Sounds like paradise, right?  Well, I have managed to get things gummed up a couple of times and had to reboot everything a couple of times already but I’m hoping that it’s because I don’t have it all hooked up correctly yet.  Also, you’ll probably still need your Tivo remote to do some Tivo things and your Blu-ray remote to do some BD things.  But I’m okay with that.  If I can use one remote 90% of the time then I’m happy.

Managing window.onbeforeunload in Javascript

I struggled with this quite a bit because there is a lot of information on the web that is conflicting. I wanted a way to tell the user that they had unsaved changes when they tried to leave an editing page but not get the warning when they hit the save button. This seems like a logical user experience to me!  The trick I found was to create a flag that the event handler checks to know whether you are in the middle of a save or not. To be slightly more generic, I called it showUnsavedChangesWarning and defaulted it to true. Here is the code I ended up with:


top.showUnsavedChangesWarning = true;
window.onbeforeunload = function (event)
{
if (top.showUnsavedChangesWarning) {
var e = event || window.event;

// If we have unsaved changes, tell the browser to show a confirmation window
var message = null;
var document = Editor.getActiveDocument();
if (document != null && document.hasUnsavedChanges()) {
message = 'You have not saved changes in your file.';
// Firefox 4 doesn't let you specify the text but does popup a warning.
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = message;
}
// For Safari
return message;
}
}

// otherwise just fall through and return nothing
};

You won’t have the Editor object unless you’re also working with Xopus but you get the idea. The interesting details here are:

  1. Don’t return anything if you want the browser to just continue on. Some sites recommended null, some the empty string. The only thing that works consistently for me is not returning anything.
  2. Safari seems to have different handling from everyone else
  3. Firefox4 doesn’t let you display a custom message anymore. You can of course display your own confirm dialogue but they’ve removed the ability for you to stick custom text into a Firefox application dialogue. I think this is a good decision.

Hopefully this helps you too.