Conveniently timed to my previous entry I recently upgraded my laptop to Debian Wheezy. This involved redoing my backup boot drive to contain bootloader updates, so I can detail the process I used.

Partition the USB drive

Use whatever partition manager you're comfortable with. cfdisk, fdisk, gparted, whatever.

# cfdisk /dev/sdb

If you want to use the USB stick on Windows normally, note that Windows will only see the first partition of a thumbdrive. This is great for hiding the fact it's a bootable drive!

# fdisk -lu /dev/sdb
...
Sector size (logical/physical): 512 bytes / 512 bytes
...
DeviceBootStartEndBlocksIdSystem
/dev/sdb18064142598157125876bW95 FAT32
/dev/sdb2*142598161524057549038083Linux

Don't start the first partition at the very beginning. Here I've got it started about 4k in. This gap is important: grub will install itself into the gap--if there isn't enough room, grub won't install.

You'll also notice that I've allocated 512MB to what will become /boot (sdb2). This is serious overkill, but also means I don't have to be particularly cautious about uninstalling old kernel versions to avoid running out of room.

Format the Partitions

Naturally, we should format these partitions:

# mkfs -t vfat /dev/sdb1
# mkfs -t ext3 /dev/sdb2

Install grub

Then mount our soon-to-be /boot drive into /boot (if you're familiar with grub-install, you can mount it elsewhere):

# mount /dev/sdb2 /boot

And install grub:

# grub-install /dev/sdb

Naturally, your next step should be to test that it boots. And maybe even test that it appears as a normal thumbdrive on a Windows computer.

When Doing a Fresh Install

NB: This is from-memory. I have not done this recently.

If you're doing a fresh install, partition the USB drive from another computer. Make sure the thumbdrive is plugged in during the install process, and when configuring drive partitions and directory locations, simply select /dev/sdb2 (or whichever is appropriate for the USB drive's second partition) as the device on to which to put /boot.

In order to protect any sensitive data on my work laptop, I use full-drive encryption. To aid recovery in case of theft, it normally boots to a honeypot installation of Windows with Prey installed. To boot into Linux, one must use a USB boot disk[1] which contains the contents of /boot.

Once in a while, it is necessary to upgrade the kernel. I don't do this very often, so it seems like the sort of process which should be documented.

  1. Mount /boot read-write: `mount -o rw /boot`
    I generally have /boot mounted read-only, in part because I don't usually have the thumbdrive plugged in (I don't boot very often, after all), and to ensure I don't accidentally make changes to it without being prepared to undergo this full process.
  2. Install kernel updates: `sudo aptitude full-upgrade`
  3. Reboot. Pray it works.
  4. Insert backup boot disk. (Just in case the thumbdrive on my keychain goes bad or gets lost.)
  5. Copy files from the updated boot disk to the backup: `rsync -av /boot /media/usb2`
  6. Remove the original boot disk. This will help prevent unfortunate mistakes.
  7. Alter grub.cfg of backup boot disk to refer to the proper UUID: `sudo sed -i s/$UUID_OF_BOOT/$UUID_OF_BACKUP/ grub/grub.cfg`
    `blkid` comes in handy for finding the relevant UUIDs.
  8. Reboot. Pray it works.

Assuming both boot disks successfully boot the machine with the updated kernel, congratulations! You have successfully updated the kernel!

[1] It's not quite as much a waste of a thumbdrive as you might think. The sticks have a FAT partition of ~90% or so of the advertised capacity, so they can still be used to transfer files between computers or for data storage.

If you happen to be lax in upgrading software, you might have an older version of magit where if M-x magit-status is allowed to initialize a git repository where none was before, it has a tendency to create said repository in the directory '$HOME/repo/~/repo'[1].

If this happens, and one wishes to remove that annoying and non-useful '~' directory, do not, I repeat, do not run the command:

rm -r ~

That is bad. Remember shell expansion! You need to quote the tilde:

rm -r '~'

But also note that even the latter should not be done within eshell, as it seems to be intent on expanding the tilde anyway. Use a real shell.

Also, always do `ls $dir` before you do `rm $dir`, just to double-check what you're deleting. Even if you're sure, check anyway.

Because otherwise, you might accidentally delete your home directory.

On the bright side, I can now confirm my backups work.

[1] see bug 383

November 2021

S M T W T F S
 123456
78910111213
14151617181920
212223 24252627
282930    

Syndicate

RSS Atom

Most Popular Tags