Friday, May 17, 2013

5.3 AMD64 X200: Creating USB Flashdrive installer.

Heyya,

I've been thinking about some sort of installation method without using CDs. As OpenBSD release new version every 6 month, burning CDs for new ISO is just wasting CD. Currently I still hang on with my 5.0 installation CD and have all the installation files of 5.1 to 5.3 in an external drive. So, if my X200 went crazy, I need to install 5.0 then upgrade all the way to 5.3.

I thought of creating another partition in my X200, just to hold installation files. It will be something like an OS Recovery partition. It's a nice idea to play with, but then Recovery Partition is useless if my hard disk have hardware issue.

So I thought of using a thumbdrive as OpenBSD installation media. Good thing is, I can just update the OpenBSD version on the thumbdrive when new version is released.

I have a Kingston DataTraveler 2.0 USB thumbdrive, 2Gb capacity. 2Gb for OpenBSD installation media is too much, so I think of creating 2 partition on it, 600Mb for OpenBSD installer + all the installation files and the rest for normal thumbdrive usage (FAT32 filesystem).

After searching for relevant informations, this is how I did it. First, I need to clear the thumbdrive. The thumbdrive I want to use is identified as sd1 so yours might be different. Do take note as you don't want to wipe the wrong drive. So I booted my X200 into 5.3, then get to the console. I plugged in my thumbdrive and proceed with this command (bold is my input):

$ sudo fdisk -iy sd1
Writing MBR at offset 0.


Then I proceed to edit the thumbdrive's slice (partition) using fdisk.

$ sudo fdisk -e sd1
Enter 'help' for information


You can check your thumbdrive's slice but mine have 4 (0 to 3) with number 3 for OpenBSD. So I edit the slice's information for OpenBSD part.

fdisk: 1> e 3
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
*3: A6      0   1   2 -    241 254  63 [          64:     3887666 ] OpenBSD     Partition id ('0' to disable) [0 - FF]: [A6] (? for help) ENTER
Do you wish to edit in CHS mode? [n] ENTER
Partition offset: [64] ENTER
Partition size: [3887666] 600m


Take note that I didn't use the CHS mode. For the OpenBSD slice, it's ok. But I need to use the CHS mode for the FAT32 slice or else I won't get the 2 partitions I needed.

fdisk: 1> e 0
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: 00      0   0   0 -      0   0   0 [           0:           0 ] unused     
Partition id ('0' to disable) [0 - FF]: [0] (? for help) 0B
Do you wish to edit in CHS mode? [n] y
BIOS Starting cylinder [0 - 241]: [0] 76
BIOS Starting head [0 - 254]: [0] 125
BIOS Starting sector [1 - 63]: [1] 49
BIOS Ending cylinder [0 - 241]: [0] 241
BIOS Ending head [0 - 254]: [0] 254
BIOS Ending sector [1 - 63]: [1] 63


As you can see, slicing the FAT32 part is a bit tricky. I need to verify my OpenBSD's slice CHS information (Ending) and adjust the FAT32 CHS informations (Starting - Ending) accordingly. As you can see, my OpenBSD's CHS ended at 241 - 254 - 63 so I used that info as Starting CHS detail for the FAT32 slice. The Ending part should be the maximum of the CHS available.

Now I flag the OpenBSD slice to make it active.

fdisk:*1> flag 3
Partition 3 marked active.

Then quit and save changes.

fdisk:*1> quit

That was only the slicing part. In Window's world it's called partitioning. But now I need to partition the OpenBSD slice created. For this I need to use disklabel.

$ sudo disklabel -E sd1
Label editor (enter '?' for help at any prompt)
> a
partition: [a] ENTER
offset: [64] ENTER
size: [1228799] *
FS type: [4.2BSD] ENTER
Rounding size to bsize (32 sectors): 1228768

As the thumbdrive will just be an installation media, no need to create SWAP or any other partition. To confirm, I need the partition info.

> p m
OpenBSD area: 64-1228864; size: 600.0M; free: 0.0M
#                size           offset  fstype [fsize bsize  cpg]
  a:           600.0M               64  4.2BSD   2048 16384    1
  c:          1906.0M                0  unused                  
  i:          1298.3M          1228863   MSDOS

Looks good. Remember that sd1a is the a (OpenBSD) partition and sd1i is for the FAT32. Now quit and save changes.

> q
Write new label?: [y] ENTER

Sliced and partitioned, the thumbdrive is ready to be formatted. I use newfs.

$ sudo newfs /dev/rsd1a
$ sudo newfs /dev/rsd1i

It might take a while depending on how big your thumbdrive's capacity is. When done, I mount the OpenBSD's slice sd1a.

$ sudo mount /dev/sd1a /mnt

Then I copy my X200's /boot file to that thumbdrive.

$ sudo cp /boot /mnt

After that I make the slice bootable.

$ sudo /usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot sd1

Then I need to create a folder named 5.3 and copy all 5.3 installation files (bsd* & *tgz) into it.

$ sudo mkdir /mnt/5.3

Then I need to create an etc folder, create a boot.conf file inside it.

$ sudo mkdir /mnt/etc
$ sudo touch /mnt/etc/boot.conf

Edit /mnt/etc/boot.conf and add:

set image /5.3/bsd.rd

Finally, I unmount the thumbdrive, reboot to test. The bsd.rd got booted nicely but I haven't tested the installation or upgrade procedure. Didn't want to mess with my current installation. If you tried this, do comment on how it goes. Later.

Update: Here's my experience on Upgrading OpenBSD using USB Flashdrive that I've created above.

No comments:

6.5 amd64: Modify existing certbot certificates.

Hi, It's been quite some time eh. As you can see, I still upgrade my OpenBSD system regularly but currently I do not have the time to ...