Skip to content

Instantly share code, notes, and snippets.

@sarcasticadmin
Last active December 7, 2018 07:12
Show Gist options
  • Save sarcasticadmin/45929db6a413954a9fb56216b14115e6 to your computer and use it in GitHub Desktop.
Save sarcasticadmin/45929db6a413954a9fb56216b14115e6 to your computer and use it in GitHub Desktop.
######
# Moving single disk zroot to new, larger SSD via temporarily adding new disk as mirror
# Done on FreeBSD 10.2
#
# Sources:
# https://forums.freebsd.org/threads/zfsroot-without-mirror-how-to-replace-disk-migrate-to-bigger.57916/
# http://www.wonkity.com/~wblock/docs/html/disksetup.html
#####
# Look up paritions from previous disk
# Align with 4k
# This assumes new disk is at /dev/da0
gpart add -t freebsd-boot -l gpboot -b 40 -s 512K da0
gpart create -s gpt da0
# FreeBSD boot parition (might not longer be needed)
gpart add -t freebsd-boot -l gpboot -b 40 -s 512K da0
# Copy bootloader
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da0
# Swap
gpart add -t freebsd-swap -l gprootfs -b 1M -s 2G da0
# Rest of disk is for zfs
gpart add -t freebsd-zfs -a 1M da0
# Attach to existing pool
zpool attach zroot ada0p3 da0p3
# Copy over existing freebsd-boot partition
dd if=/dev/ada0p1 of=/dev/da0p1 bs=64k
# Shutdown and remove old drive
init 0
# After new boot remove old disk from mirror
# This might change since new disk could be at ada0
zpool detach zroot <diskID>
# Add the following to /boot/loader.conf is gptid are present
# but normal disk names are desired
kern.geom.label.gptid.enable="0"
kern.geom.label.disk_ident.enable="0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment