Renovating an old media PC
· 4 min read · August 28, 2020 · #old #linux #rescueSome 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:
- https://en.wikipedia.org/wiki/Cylinder-head-sector
- https://en.wikipedia.org/wiki/FAT_boot_sector
- https://en.wikipedia.org/wiki/Logical_Block_Addressing#CHS_conversion
- https://en.wikipedia.org/wiki/Master_Boot_Record
- https://en.wikipedia.org/wiki/Volume_boot_record
- https://wiki.archlinux.org/index.php/Syslinux
- https://wiki.syslinux.org/wiki/index.php?title=Common_Problems#Failed_to_load_ldlinux
- https://wiki.syslinux.org/wiki/index.php?title=Hardware_Compatibility#USB_related_problems
- https://wiki.syslinux.org/wiki/index.php?title=Hdt_(Hardware_Detection_Tool)
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/sdd1One 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/sddObtaining 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/syslinuxsudo 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
EOFUnfortunately, 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-devGRUB
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=4MTo 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
EOFTo 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/sddAt 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
}
EOFInstall 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:
- find where disk is mounted:
sudo lshw -C disk -shortassume new disk is/dev/sdX, flash disk is/dev/sdF - partition disk:
sudo parted /dev/sdX mkpart primary ext4 1 -1 - format disk:
sudo mkfs.ext4 -m0 /dev/sdX1 - label disk:
sudo e2label /dev/sdX1 Harddisk - remount flash disk rw:
mount -o remount,rw /dev/sdF - edit
/boot/extlinux.confso APPEND line reads:APPEND boot=LABEL=System disk=LABEL=Harddisk quiet
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.
- download ISO: http://ubuntu-rescue-remix.org/
- boot
ubuntu-rescue-remix-12-04.isovia virtualbox - mount USB stick on
/dev/sdXat/mnt:mount /dev/sdX /mnt - format the stick:
mkfs.vfat -n multiboot /dev/sdX1 cd /mnt && mkdir boot isogrub-install --force --no-floppy --boot-directory=/mnt/boot /dev/sdX- create ISO from mounted cd:
dd if=/dev/cdrom of=/mnt/iso/ubuntu-rescue-remix-12-04.iso - create
/boot/grub/grub.cfgwith
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