Mounting FreeBSD partitions inside a LVM volume in linux

No need for kpartx in this case. Just check the FreeBSD disklabels inside the logical volume. This can be done using fdisk:

#fdisk /dev/vg0/backup 

Command (m for help): b

Reading disklabel of /dev/vg0/backup1  at sector 64.

BSD disklabel command (m for help): u
Changing display/entry units to sectors

BSD disklabel command (m for help): p

8 partitions:

#       start       end      size     fstype   [fsize bsize   cpg]
  a:  4194367  25165886  20971520     4.2BSD     2048 16384 28552 
  b:       63   4194366   4194304       swap                      
  c:       63  146785904  146785842     unused        0     0       
  d: 25165887  46137406  20971520     4.2BSD     2048 16384 28552
  e: 46137407  146785904  100648498     4.2BSD     2048 16384 28552 

Easier and faster with sfdisk:

#sfdisk -d /dev/vg0/backup# partition table of /dev/vg0/
backupunit: sectors
/dev/vg0/backup1 : start=       63, size=146785842, Id=a5, bootable
/dev/vg0/backup2 : start=        0, size=        0, Id= 0
/dev/vg0/backup3 : start=        0, size=        0, Id= 0
/dev/vg0/backup4 : start=        0, size=        0, Id= 0
/dev/vg0/backup5 : start=  4194367, size= 20971520
/dev/vg0/backup6 : start=       63, size=  4194304
/dev/vg0/backup7 : start= 25165887, size= 20971520
/dev/vg0/backup8 : start= 46137407, size=100648498

Now multiply the start sectors by 512 and use the result as an offset in the mount options:

#mount -t ufs -o ufstype=ufs2,offset=23622352384,ro /dev/vg0/backup /mnt/backup/

Notice the ro (read-only) flag, as most linux distributions don’t come with UFS write support.

Changing a failed Disk in Software RAID-1

You know something’s wrong when you see this:

# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid10]
md2 : active raid1 sdb3[2] sda3[0]
      1458830400 blocks [2/1] [U_]
     
md0 : active raid1 sdb1[1] sda1[0]
      4200896 blocks [2/2] [U_]
     
md1 : active raid1 sdb2[2] sda2[0]
      2104448 blocks [2/1] [U_]
     
unused devices: <none>

U_ means, that one disk is gone. UU would mean, everything’s alright. In this example /dev/sdb failed. Just replace it with your own device.

Now to remove the physical disk you first have to remove every partition of that disk from the software raid:

#mdadm /dev/md0 -r /dev/sdb1
#mdadm /dev/md1 -r /dev/sdb2
#mdadm /dev/md2 -r /dev/sdb3

If one of the partitions is still fine and only part of the disk is damaged, you might have to flag that partition as failed before being able to remove it:

#mdadm —manage /dev/md0 —fail /dev/sdb1

Now shut down your computer and replace the disk (or simply replace the disk if it is hot swappable). The new disk has to be of the same size of course.

Copy the partition table from the working disk:

#dd if=/dev/sda of=/dev/sdb count=1 bs=512

Check if it worked by using fdisk on /dev/sdb. IMPORTANT: write out the partition table, this way the system syncs the disk changes.

Now all you have to do is add the partitions to the raid again:

#mdadm /dev/md0 -a /dev/sdb1
#mdadm /dev/md1 -a /dev/sdb2
#mdadm /dev/md2 -a /dev/sdb3

If you get an error message that your partition is “not large enough to join array”, you probably forgot to resync the partition table. In this case, remove the already added partitions from the raid (using the failed flag described above), enter fdisk again and write the changes to disk. Alternatively you could run

#sfdisk -R /dev/sdb

to resync the partition table.

Short Xen w/ Ubuntu Routed Hostonly Network HowTo

- install latest Ubuntu server
- install Xen 3.3
- get Xen kernel from Ubuntu Hardy Heron repos
- add hostonly network:

brctl addbr hostonly

- set dom0 IP for hostonly network:

ifconfig hostonly 10.0.0.1 netmask 255.255.255.0

- start Xen daemon:

/etc/init.d/xend start

- start domU:

xm create xxxx.xen [-c]

- access console on paravirtualized domU:

xm console domU-name

- close Xen console: “Ctrl”+”]” (on german macbook pro keyboard: ctrl+alt+6, on german windows keyboard: Ctrl+Alt Gr+9)

- forward Microsoft Windows Remote Desktop using iptables:

echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -p tcp -i eth0 -d 78.46.104.242 --dport 3389 -j DNAT --to 10.0.0.10:3389
iptables -A FORWARD -p tcp -i eth0 -d 10.0.0.10 --dport 3389 -j ACCEPT

- to allow ping to Windows domU, check ICMP settings in Windows Firewall