home | codereading | contact | math | misc | patches | tech

NetBSD tips

Adding a Linux partition and making it appear in the disklabel

You can easily add a Linux partition to your HD using the fdisk(8) program, or using a Linux partition program during your distro installation. They will not show up automatically in the disklabel(8), in NetBSD, but they will appear when using the mbrlabel(8) and fdisk(8) commands.

To update disklabel according to mbrlabel, type the following command:

# mbrlabel -rw wd0

Mount pen-drive (USB stick)in NetBSD

USB pendrivers are usually attached to the sd* devices. To get the exactly location what devices are active and can be mounted, type:

$ dmesg | tail

This will output the current disks. The pendrive will be one of the sd* devices. To discover the exactly device where it is attached, run disklabel on it:

# disklabel sd0

Then, mount the device:

$ mount -t msdos -o -l  /dev/sd0e mnt/pendrive/

A reference here.

Suspend/resume in amd64

In i386 we used to have apm(8) and zzz(8) to enter suspend mode. In amd64 it is:

# sysctl -w hw.acpi.sleep.vbios=2
# sysctl -w hw.acpi.sleep.state=3

Unfortunatelly it is not well documented at the time I write this tip.

The documentation for these sysctl variables are in acpi(4).

Thanks medfly @ freenode for this tip.

LVM in NetBSD in one partition

There is a chapter on the NetBSD Guide about LVM. There is also a wiki page about LVM with good information. The interface is very similar to the GNU/Linux one.

The guides normally focus on advanced features of LVM, like using several disks to make a logical volume, but I just want to use a separated partition as LVM. I have the following partitions:

root filesystem
allocated via disklabel(8) but not formatted (with newfs(8)

So, if we want to use /dev/sd0e as the home for our LVM (in LVM parlance, it is our only Physical Volume - PV), we do:

# lvm pvcreate /dev/rsd0e
  Physical volume "/dev/rsd0e" successfully created

Then, it is now necessary to create the Volume Group. In this case, it will hold the only partition we have (you could add more Physical Volumes if you have had):

# lvm vgcreate vg0 /dev/rsd0e
  Volume group "vg0" successfully created

Finally, you can now create your logical volumes over your VGs. Let's create a small 20 MB partition:

# lvm lvcreate -L20M -n lv0 vg0
  Logical volume "lv0" created

You can now use the device created in /dev/vg0/lv0:

# newfs /dev/vg0/lv0
/dev/mapper/rvg0-lv0: 20.0MB (40960 sectors) block size 8192, fragment size 1024
        using 4 cylinder groups of 5.00MB, 640 blks, 1280 inodes.
super-block backups (for fsck_ffs -b #) at:
32, 10272, 20512, 30752,

And you can mount it:

# mount /dev/vg0/lv0 /mnt
mount_ffs: "/dev/vg0/lv0" is a non-resolved or relative path.
mount_ffs: using "/dev/mapper/vg0-lv0" instead.

See the lvm(8) man page for other commands to handle LVM.