Sunday, February 12, 2017

Transfer openbsd from one disk to another

Print out the current partition setup and size. This setup is very important.
pf:~$ df -h |sort
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/sd0a     1008M   55.2M    903M     6%    /
/dev/sd0d      7.9G    4.0K    7.5G     0%    /tmp
/dev/sd0e     78.7G   20.6M   74.8G     0%    /var
/dev/sd0f      3.9G    1.0G    2.7G    27%    /usr
/dev/sd0g     1001M    2.0K    951M     0%    /usr/X11R6
/dev/sd0h      9.8G   63.9M    9.3G     1%    /usr/local
/dev/sd0i      2.0G    2.0K    1.9G     0%    /usr/src
/dev/sd0j      2.0G    2.0K    1.9G     0%    /usr/obj
/dev/sd0k      1.7T   30.4M    1.6T     0%    /home

Assume the current drive is sd0 and the new drive is sd1.
# fdisk -i sd1
Do you wish to write new MBR and partition table? [n] y
Writing MBR at offset 0.

Repeat adding all partitions (a, d, e, f, g, h, i, j, k)
pf:~# disklabel -E sd1
Label editor (enter '?' for help at any prompt)

> a a
offset: [226468288] 
size: [3680555777] 
FS type: [4.2BSD] 
Rounding offset to bsize (128 sectors): 226468352
Rounding size to bsize (128 sectors): 3680555648
(...)

> w
> q

Repeat formatting all partitions
pf:~# newfs sd1k      
/dev/rsd1k: 1797146.2MB in 3680555648 sectors of 512 bytes
551 cylinder groups of 3266.88MB, 52270 blocks, 104704 inodes each

# shutdown -h now
Shutdown NOW!


Now boot your system in single-user mode and clone the data from the current drive to the new drive
boot> boot -s
(...)
Enter pathname of shell or RETURN for sh:
# mount_mfs -s 4096m swap /tmp

Repeat the following for each partition
# mount /dev/sd1a /mnt
# cd /mnt
# dump -0f - /dev/sd0a  | restore -rf -
# cd /
# umount /mnt

If dump failed because of drive problem, try using tar instead
# mount /dev/sd1a /mnt
# tar cpXf - / | tar xpf - -C /mnt

Test boot the new drive
# reboot
boot> boot hd1a:/bsd -s
(...)
Enter pathname of shell or RETURN for sh: 
#

Boot your system in single-user mode using the original drive and install boot loader on the new drive
boot> boot -s
(...)
Enter pathname of shell or RETURN for sh:
# mount /dev/sd0f /usr
# mount /dev/sd1a /mnt
# installboot -r /mnt sd1 /usr/mdec/biosboot /usr/mdec/boot

Fix duid in /etc/fstab
pf:root# disklabel sd1
# /dev/rsd1c:
type: SCSI
disk: SCSI disk
label: ST2000VN000-1H31
duid: 85d0b835a275e8ee
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 243201
total sectors: 3907029168
boundstart: 64
boundend: 3907024065
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize  cpg]
a:          2104448               64  4.2BSD   2048 16384    1 # /
c:       3907029168                0  unused                   
d:         16771840          2104512  4.2BSD   2048 16384    1 # /tmp
e:        167766784         27262304  4.2BSD   2048 16384    1 # /var
f:          8385952         18876352  4.2BSD   2048 16384    1 # /usr
g:          2088448        195029088  4.2BSD   2048 16384    1 # /usr/X11R6
h:         20964832        197117536  4.2BSD   2048 16384    1 # /usr/local
i:          4192960        218082368  4.2BSD   2048 16384    1 # /usr/src
j:          4192960        222275328  4.2BSD   2048 16384    1 # /usr/obj
k:       3680555648        226468352  4.2BSD   8192 65536    1 # /home

Edit /mnt/etc/fstab, replace the original duid with the one we found above
pf:root# cat /etc/fstab 
85d0b835a275e8ee.b none swap sw
85d0b835a275e8ee.a / ffs rw 1 1
85d0b835a275e8ee.k /home ffs rw,nodev,nosuid 1 2
85d0b835a275e8ee.d /tmp ffs rw,nodev,nosuid 1 2
85d0b835a275e8ee.f /usr ffs rw,nodev 1 2
85d0b835a275e8ee.g /usr/X11R6 ffs rw,nodev 1 2
85d0b835a275e8ee.h /usr/local ffs rw,nodev 1 2
85d0b835a275e8ee.j /usr/obj ffs rw,nodev,nosuid 1 2
85d0b835a275e8ee.i /usr/src ffs rw,nodev,nosuid 1 2
85d0b835a275e8ee.e /var ffs rw,nodev,nosuid 1 2

All done. Power off the system, remove the original drive and boot again from the new drive.

No comments:

Post a Comment