with apologies

Renovating an old media PC

Richard Mortier · August 28, 2020 · #old #linux #rescue

Some notes from my first attempt to renovate an old media PC that had a SYSLINUX install without any package management, and a crufty BIOS. Probably outdated now, but I may go back to it one day…

First, some background links:

I explored two ways forward: SYSLINUX and GRUB.

SYSLINUX

I found that getting SYSLINUX working required moving the partition to 0/1/1 – using sectors per track of 63 or 32, and heads per cylinder or 16 or 64 with appropriate cylinder values simply didn’t help.

Diagnosed by observing that console displayed only CRLF but no banner – SYSLINUX code ends up with the banner to be displayed just falling into the second sector on the disk, so it can’t be read unless the geometry is correct. Don’t ask why old fashioned whirling metal disk geometry needs to be set for a USB stick, you’ll be sad.

Formatting the USB stick

Some runes, use at your own risk.

sudo dd if=/dev/zero of=/dev/sdd status=progress bs=1M count=256
sudo fdisk /dev/sdd <<EOF
o
x
h
64
s
32
r
n
p
1


t
6
a
1
w

EOF
sudo mkfs.fat /dev/sdd1

One exciting gotcha: the fdisk utility in the util-linux package didn’t work – but the one in busybox did!

Putting MBR in place

sudo dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of=/dev/sdd

Obtaining and installing memtest86

cd
wget http://memtest.org/download/4.10/memtest86+-4.10.zip
unzip memtest86+-4.10.zip
sudo cp ~/memtest86+-4.10.bin /mnt/boot/

Putting locally built SYSLINUX in place

sudo mount /dev/sdd1 /mnt
sudo mkdir -p /mnt/boot/syslinux
sudo syslinux --directory boot/syslinux --install /dev/sdd1
sudo cp /usr/share/syslinux/*.c32 /mnt/boot/syslinux/
cd ~/syslinux
make bios
sudo cp ~/syslinux/bios/com32/hdt/hdt.c32 /mnt/boot/syslinux/
sudo cp /usr/share/hwdata/pci.ids /mnt/boot/syslinux
sudo sh -c "cat > /mnt/boot/syslinux/syslinux.cfg" <<EOF
# UI menu.c32
PROMPT 1
DEFAULT hdt

LABEL some_label
  LINUX memdisk
  INITRD ../alpine-standard-3.12.0-x86_64.iso
  APPEND iso-scan/filename=../alpine-standard-3.12.0-x86_64.iso

LABEL memtest
  LINUX ../memtest86+-4.10.bin

LABEL hdt
  COM32 hdt.c32

LABEL reboot
  COM32 reboot.c32

LABEL poweroff
  COM32 poweroff.c32
EOF

Unfortunately, getting hdt working required rebuilding as the Alpine package version doesn’t appear to statically link against libupload.a from SYSLINUX tree so doesn’t work. Fixing required make bios in the SYSLINUX tree after installing dependencies including:

sudo apk -U add nasm xzlinux-headers util-linux-dev

GRUB

Similar behaviour: GRUB2 displayed the GRUB message and nothing else, The Ubuntu wiki says this is the “can’t find MBR or euqivalent” information. In fact, it’s the same issue: subsequent progress requires reading the second sector, but I had a CHS/LBA mismatch meant it wasn’t reading from the right sector and so hanging.

To wipe the stick

sudo dd if=/dev/zero of=/dev/sdd status=progress bs=4M

To partition the stick

In this case, to be bootable with a single ext4 partition

sudo parted /dev/sdd
mklabel msdos
unit s
mkpart primary ext2 2048s 100%
set 1 boot on
set 1 lba off

…or alternatively, possibly

sudo fdisk /dev/sdd <<EOF
o
n
p
1


a
1

EOF

To format the partition, and install grub and the master boot record

sudo mkfs.ext4 /dev/sdd1
sudo mount /dev/sdd1 /mnt
sudo grub-install --recheck --boot-directory=/mnt/boot /dev/sdd

At this point, booting off the stick will bring htpc to GRUB error stage, indicating GRUB has loaded but doesn’t know anything about how to continue.

Install memtest

sudo cp memtest86+.bin /mnt
sudo cat >/mnt/boot/grub/grub.cfg <<EOF
set timeout=10
set default=0

menuentry "Memtest 86+" {
 linux16 /memtest86+.bin
}
EOF

Install Alpine ISO for booting

Add the following stanza to GRUB config, above:

insmod loopback

menuentry "alpine" {
  set isofile=/boot/alpine-standard-3.12.0-x86_64.iso
  loopback loop $isofile
  linux (loop)/boot/vmlinuz-lts iso-scan/filename=$isofile modules=loop,squashfs,sd-mod,usb-storage modloop=(loop)/boot/modloop-lts
  initrd (loop)/boot/initramfs-lts
}

Miscellaneous cribs

I did of course forget that the

Bluetooth keyboard requires a dongle to be plugged in which is stored inside the battery compartment. Doh. Making a note so I don’t forget again.

Adding internal hard-disk

Required partitioning and formatting:

I screwed up the first time by not correctly labelling the disk so had to make an Ubuntu rescue USB stick. Couldn’t get this to work using MacOS, though didn’t try putting GRUB on via MacOS.

menuentry 'Ubuntu Rescue Remix ISO ' {
  set isofile="/iso/ubuntu-rescue-remix-12-04.iso"
  loopback loop (hd0,N)$isofile
  linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject
  initrd (loop)/casper/initrd.gz
}

where N is partition number, typically 1.

Finally, for backup purposes, addons are stored in /storage/.xbmc/addons/packages, and the following Alpine packages were useful to install for some of the above, diagnostics, etc:

sudo apk add busybox-static apk-tools-static
sudo vi /etc/apk/repositories
sudo apk.static update
sudo apk.static upgrade --no-self-upgrade --available
sudo apk add lshw lshw-doc
sudo lshw -C storage -short -numeric
sudo apk add lsblk
sudo lsblk