Archived entries for FreeBSD hacks

gstat !! FreeBSD disk overview

Call me stupid but I accidentally found the gstat utility.

It gives you a super-cool overview of what your disks are doing.

Very useful in multiple disk ZFS…
was using iostat beforehand.

dT: 1.001s w: 1.000s
L(q) ops/s r/s kBps ms/r w/s kBps ms/w %busy Name
1 17 12 14 14.0 4 4 0.2 28.0| da0
1 17 12 22 14.8 4 4 0.2 26.7| da1
1 13 8 6 16.8 4 4 0.2 26.2| da2
1 17 12 22 11.9 4 4 0.2 20.3| da3
1 18 13 15 11.8 4 4 0.2 20.9| da4
1 18 13 15 12.0 4 4 0.2 21.8| da5
1 19 14 32 12.6 4 4 0.2 24.0| da6
1 24 17 31 12.2 5 4 0.2 138.3| da7
1 18 12 20 13.1 5 4 0.2 21.4| da8
1 15 9 18 15.0 5 4 0.2 25.1| da9
1 7 2 2 160.7 4 4 0.2 48.9| da10
1 16 10 21 12.3 5 4 0.2 19.6| da11
0 0 0 0 0.0 0 0 0.0 0.0| da12
0 0 0 0 0.0 0 0 0.0 0.0| da13
0 0 0 0 0.0 0 0 0.0 0.0| da14
0 0 0 0 0.0 0 0 0.0 0.0| da15
0 0 0 0 0.0 0 0 0.0 0.0| da16
0 0 0 0 0.0 0 0 0.0 0.0| da17
0 0 0 0 0.0 0 0 0.0 0.0| da18
0 0 0 0 0.0 0 0 0.0 0.0| da19
0 0 0 0 0.0 0 0 0.0 0.0| da20
0 0 0 0 0.0 0 0 0.0 0.0| da21
0 0 0 0 0.0 0 0 0.0 0.0| da22
0 0 0 0 0.0 0 0 0.0 0.0| da23
0 0 0 0 0.0 0 0 0.0 0.0| da24
0 0 0 0 0.0 0 0 0.0 0.0| da25
0 0 0 0 0.0 0 0 0.0 0.0| da26
0 0 0 0 0.0 0 0 0.0 0.0| da27
0 0 0 0 0.0 0 0 0.0 0.0| da28
0 0 0 0 0.0 0 0 0.0 0.0| da29
0 0 0 0 0.0 0 0 0.0 0.0| da30
0 0 0 0 0.0 0 0 0.0 0.0| da31
0 0 0 0 0.0 0 0 0.0 0.0| da32
0 0 0 0 0.0 0 0 0.0 0.0| da33
0 0 0 0 0.0 0 0 0.0 0.0| da34
0 0 0 0 0.0 0 0 0.0 0.0| da35
0 0 0 0 0.0 0 0 0.0 0.0| da36
0 0 0 0 0.0 0 0 0.0 0.0| da37
0 0 0 0 0.0 0 0 0.0 0.0| da38
0 0 0 0 0.0 0 0 0.0 0.0| cd0
0 0 0 0 0.0 0 0 0.0 0.0| da38p1
0 0 0 0 0.0 0 0 0.0 0.0| da38p2
0 0 0 0 0.0 0 0 0.0 0.0| da38p3
0 0 0 0 0.0 0 0 0.0 0.0| label/root
0 0 0 0 0.0 0 0 0.0 0.0| gptid/00e3191c-5b83-11e2-a6e9-00215acea494
0 0 0 0 0.0 0 0 0.0 0.0| label/rootfs
0 0 0 0 0.0 0 0 0.0 0.0| label/swap

FreeBSD disk labeling

I noticed that I’m a big user of my blog, simply because I forget things. So it is becoming “Note to self” blog 🙂

Recently I came to a stupid problem when the first controller in the server – the boot one – came numbered last on FreeBSD.

So the boot disk came to a /dev/da24.

The problem was that this server is changing the number of disk, so the boot device would always change, leaving a non bootable OS because of the /etc/fstab mount file.

So the tool for the action is Disk labeling: (old stuff)
FreeBSD disk labeling

Simply, boot into the single user mode and do a:
glabel label root /dev/da24a (root device or whatever is with you)
glabel label swap /dev/da24b (swap device number)

and change /etc/fstab devices to boot from /dev/label/root and /dev/label/swap for swap.

for example:
# cat /etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/label/root / ufs rw 1 1
/dev/label/swap none swap sw 0 0

FreeBSD view bandwidth and total bytes transferred for interface

Always installed nload on the server for which I wanted to view the bandwidth usage on.

But there’s preinstalled not-so-fancy-but-usable utility for FreeBSD:

systat -ifstat 1

S.

SSH bouncing update – getting rid of Killed by signal 1

If you read my article on ssh bouncing, you surely use it.

One annoying thing is “Killed by signal 1” when exiting the bounced session.

dolfi:~ simon$ ssh supercoolserver
Permission denied (publickey,keyboard-interactive).
Killed by signal 1.

So the solution is to change the ~/.ssh/config file and add the “2>/dev/null” to the very end of the ProxyCommand line.

Host hostalias
User root
ProxyCommand ssh bouncer.server -p 2222 'nc destination.server 2222' 2>/dev/null

Found the solution here. Thanks to merdely.

S.

FreeBSD disk/partition resize – grow on version 8.2 and newer under vmware vSphere / ESXi

This one is easier than previous (FreeBSD 7.x or older).

It may be possible to do it all live but you need to find a way for FreeBSD to see the growed disk size.

  • Shut down the server
  • Grow the disk size
  • Boot FreeBSD in single user mode (number 4 at boot)
Check the partitions layout:

gpart show

Set the system in evil mode that will allow gpart to change live filesystem:

sysctl kern.geom.debugflags=16

Grow the whole disk – consumer. Number 1 is the consumer index shown with gpart show

gpart resize -i 1 da0

Grow desired provider – partition. Number 6 is the provider index shown with gpart show

gpart resize -i 6 da0s1

Now with partition resized you can growfs

growfs /dev/da0s1f

Reboot for a clean feeling and you’re done.

S.

FreeBSD disk/partition resize – grow on version 7.x or older under vmware ESXi

I’ve tried this on vmware ESXi4.1.

First, shut down the server and enlarge the disk size in the VM config.

Boot into single user mode (press 4 and boot).

Check the block count of the new disk (seen at boot – dmesg) – in our case 419430400.

Update the partition size with fdisk -u /dev/da0

when asked, the start of the updated partition stays the default but the end of the partition you can write the block count of the new disk (419430400). Actual end is less that this size, but fdisk sees that and it suggests the correct number which you can agree on.

you can check if all went well with fdisk -s. It should be the new block size (little less that the block cound of the disk) – write down this number.

fdisk -s

time to update the slice table. This is done by:

bsdlabel -e da0s1

There you edit the number under “# “raw” part, don’t edit”. Funny 🙂 You must change the number here to the block count seen with “fdisk -s” after updating partition.

And then change last line – usually entry “f” which is by default “/usr”. Remember that you can only grow the last partition !!.

Change the first number of the “f” entry with the number which is number of blocks seen via “fdisk -s” minus the offset of the f entry (next number in line).

Save this config.

Now the partition is bigger but the filesystem doesn’t know about it. This is where growfs comes in (was surprised to see that it has been introduced in BSD 3.x).

growfs /dev/da0s1f

resize growfs

and there, you have resized partition.

type CTRL+D to boot into the new – grown partition.

I noticed that this procedure works only for version smaller than FreeBSD 8.
It should work on higher versions but I’ve seen very unstable behaviour – kernel crashes… after using fdisk/diskabel.

For versions FreeBSD 8+ the utility gpart (don’t confuse with gparted !!!t) is used which will be described in next post.



Copyright © 2004–2009. All rights reserved.

RSS Feed. This blog is proudly powered by Wordpress and uses Modern Clix, a theme by Rodrigo Galindez.