Hi!

After solving a recent problem on a VM where the /usr/local was full I was left 
with a disklabel that had a hole of unused space in it (see below for details). 
I was wondering if there is a way to compact the partitions, i.e. move the 
partitions following the deleted one up to fill the hole, potentially leaving 
corresponding free space at the end.

I’d prefer to not have to use dd(1) on the raw device to move the data? I’d 
hope for something that is smart enough to adjust the disklabel after moving 
the bytes. Wishful thinking?


Details:
Partition sd0h, ≈2.42 GB in size, containing /usr/local was full on a 20 GB 
virtual disk in VMWare Fusion, used for OpenBSD 7.1 stable, amd64. The 
partitions where originally created using the defaults in OpenBSD 6.8 IIRC. I 
enlarged the virtual disk in VMWare by 5 GB to 25 GB and then in single user 
mode I added a new sd0l partition using disklabel(8), created a file system on 
it, mounted the new file system and used dump(8)/restore(8) to copy the data. 
Then I modified /etc/fstab to use sd0l instead of sd0h and rebooted. Lastly I 
used disklabel(8) to delete sd0h. This left the aforementioned hole of unused 
data on disk. (For completeness sake I also adjusted the MBR using fdisk(8) to 
make the OpenBSD partition reflect the new size. But I’m not sure if that was 
even required. Seemed to work fine without that change.)

The current disklabel looks like this:
# disklabel sd0           
# /dev/rsd0c:
type: SCSI
disk: SCSI disk
label: VMware Virtual S
duid: e592eaa53f566380
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 2610
total sectors: 52428800
boundstart: 64
boundend: 52428800
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  a:          1299584               64  4.2BSD   2048 16384 10153 # /
  b:          2148640          1299648    swap                    # none
  c:         52428800                0  unused                    
  d:          1833600          3448288  4.2BSD   2048 16384 12960 # /tmp
  e:          2744064          5281888  4.2BSD   2048 16384 12960 # /var
  f:          5056800          8025952  4.2BSD   2048 16384 12960 # /usr
  g:          1381856         13082752  4.2BSD   2048 16384 10710 # /usr/X11R6
  i:          3059360         19538944  4.2BSD   2048 16384 12960 # /usr/src
  j:         11279680         22598304  4.2BSD   2048 16384 12960 # /usr/obj
  k:          8051648         33877984  4.2BSD   2048 16384 12960 # /home
  l:         10499168         41929632  4.2BSD   2048 16384 12960 # /usr/local
# 
So partitions i through l would need to move.


Thanks!

Mike

Reply via email to