Skip to content

Partitioning with gpt

Sometime ago, I setup a ZFS system using glabel on FreeBSD. I recently stumbled across this FreeBSD diary entry, which describes to do almost the same thing using gpt. I like this method better, because it results in a partition that is on a 4kB boundary, which works better for some hard drives (whose sector size is 4kB).

Here’s what I did:

#gpart show da0
=>        63  1953525105  da0  MBR  (932G)
63  1953525105       – free –  (932G) 

OK: that’s the starting point. I have a MBR-style partition which is set up as one 932G partition and some free space.

I wasn’t sure exactly how to get rid of it, so I tried:

# gpart delete -i 1 da0
da0s1 deleted

I still have a MBR-style partition table. Next, as I read in the FreeBSD diary, I need to figure out how many sectors I have:

# dmesg | grep “da0”
da0 at umass-sim0 bus 0 scbus0 target 0 lun 0
da0: <Hitachi HDS721010CLA332 > Fixed Direct Access SCSI-2 device
da0: 40.000MB/s transfers
da0: 953869MB (1953525168 512 byte sectors: 255H 63S/T 121601C)

OK: 1953525168 sectors of 512 bytes each. However, for some reason, that isn’t what gpt shows:

# gpart show da0
=> 34 1953525101 da0 GPT (932G)
34 1953525101 – free – (932G)

I’m not sure if this smaller size is because 34 sectors are taken up by the partition table, or if it’s a cylinder-boundary thing.

As the article recommends, I want to leave the first 1MB free (Windows does this, too). I also want to leave around 200MB free at the end of the disk (to allow for some slack in case I want to replace this disk). So, I have 1953525168 sectors (total) – 2048 sectors (1MB) – 409600 (200MB) = 1953113453 sectors:

fbsd2# gpart add -b 2048 -s 1953113453 -t freebsd-zfs -l Hitachi_1TB da0
da0p1 added

# gpart show da0
=> 34 1953525101 da0 GPT (932G)
34 2014 – free – (1.0M)
2048 1953113453 1 freebsd-zfs (931G)
1953115501 409634 – free – (200M)

Looks good: the partition is 931GB large. I have 200MB of slack at the end, and it starts 1MB into the disk. Now, let’s replace the old glabel-based partition with this one:

# zpool replace tank label/hitachi_1tb gpt/Hitachi_1TB

# zpool status
pool: tank
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scrub: resilver in progress for 0h0m, 0.01% done, 95h54m to go

tank DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
label/fantom_500gb ONLINE 0 0 0 6.27M resilvered
replacing DEGRADED 0 0 0
label/hitachi_1tb OFFLINE 0 1.83K 0
gpt/Hitachi_1TB ONLINE 0 0 0 9.41M resilvered
label/fantom_1tb ONLINE 0 0 0 6.25M resilvered

Pretty cool.

Be the first to like.

Post a Comment

Your email is never published nor shared. Required fields are marked *