Allen Pomeroy

Blog of an IT security specialist .: beta :.

Building a web security lab (with VMware Fusion)

Tags: , , , ,

Problem: VMware machines load boot loader immediately, no BIOS banner, so can’t get into BIOS to alter boot settings.
Solution: Edit the vm’s .vmx file and add the line:

bios.bootDelay = "5000"

which adds a 5000 millisecond (5 second) delay to the boot, or add:

bios.forceSetupOnce = "TRUE"

to make the VM enter the BIOS setup at the next boot.

Problem: VMware Fusion 3.0 doesn’t give a way to edit the virtual network settings via the GUI.
Solution: To change the subnet used by the NAT or HostOnly networks, go root in Mac OS X and edit

/Library/Application Support/VMware Fusion/networking

and set the following lines to the subnets desired:

answer VNET_1_HOSTONLY_SUBNET 192.168.35.0
answer VNET_8_HOSTONLY_SUBNET 10.10.1.0

To add additional custom isolated host only VLANs, also edit the networking file and add additional VNET definitions. There can apparently only be 8 VLANs with VLAN 1 and 8 already pre-defined.

answer VNET_2_DHCP no
answer VNET_2_HOSTONLY_NETMASK 255.255.255.0
answer VNET_2_HOSTONLY_SUBNET 10.10.21.0
answer VNET_2_VIRTUAL_ADAPTER yes
answer VNET_3_DHCP no
answer VNET_3_HOSTONLY_NETMASK 255.255.255.0
answer VNET_3_HOSTONLY_SUBNET 10.10.22.0
answer VNET_3_VIRTUAL_ADAPTER yes
answer VNET_4_DHCP no
answer VNET_4_HOSTONLY_NETMASK 255.255.255.0
answer VNET_4_HOSTONLY_SUBNET 10.10.23.0
answer VNET_4_VIRTUAL_ADAPTER yes

Now create your vm with as many network interfaces as you have separate VLANs (vnet) then edit the node.vmx vm configuration file and change the interfacename.connectionType to custom, and define the VLAN (vnet) that interface will attach to:

#ethernet0.connectionType = "nat"
ethernet0.connectionType = "custom"
ethernet0.vnet = "vmnet3"

Also realize that VMware will take the .1 host address on each vmnet – so you cannot assign .1 to any of your VMs.

Problem: Ubuntu 9.10 persistent network configuration (stores the MAC address of network adapters), so if you copy a machine, by default Ubuntu will setup a new logical adapter (eth1) since the MAC address has changed (when you answer I Copied It in VMware).
Solution: Tell VMware you copied the machine, so it will chose a unique MAC address. Boot Ubuntu into single user mode (another article on that to follow) then edit the MAC address associated with eth0.

sudo vi /etc/udev/rules.d/70-persistent-net.rules

find the stanza of the network interface in question (NAME=”eth0″) and set the following ATTR tag to the new MAC address:

ATTR{address}=="new-mac-address-here"

MythTV FC7 LVM on RAID1 Configuration

Tags: , , ,

MythTV PVR HDD Mirroring 2008/07/24
Host: n43 (mythtv)
- Two SATA 500GB drives sda sdb
- current production drive is sdb

Problem: I’ve done migrations of LVM2 volumes from 320GB SATA to 500GB SATA and added
a redundant 500GB SATA. Now I want to get software RAID 1 setup to protect the
root, swap and /storage filesystems from damage if/when one of the shiny new 500GB SATA
disks bite the dust.

Followed howtoforge.com linux_lvm_p1 (start of article) to free up sda from LVM
volume group VolGroup00 .. http://www.howtoforge.com/linux_lvm_p7

0. Did a file level backup to the fileserver:
[root@n59 20080724]# ssh root@192.168.1.2This e-mail address is being protected from spambots, you need JavaScript enabled to view it “tar cf – /lib” | dd of=mythtv-lib.tar
(repeat for /boot /storage /var /etc /home)

1. Free up sda2 LVM volume. I know this volume is not used anymore,
but it still has same-disk backup of /storage from when I was tweaking
MythTV.

[root@mythtv ~]# pvmove /dev/sda2
[root@mythtv ~]# vgreduce /dev/VolGroup00 /dev/sda2
[root@mythtv ~]# pvremove /dev/sda2

- now running on sdb only -

Setup RAID 1 mirroring (md)

2. Partition sda for mirroring (Auto RAID label)
[root@mythtv ~]# fdisk /dev/sda
<delete partitions>
<add primary 1 whole disk>
<set flag to fd – Auto RAID>

[root@mythtv ~]# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 60801 488231415 fd Linux raid autodetect

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 19 152586 83 Linux
/dev/sdb2 20 60801 488231415 8e Linux LVM

Notice that sdb is still using only LVM, not RAID.

3. Setup md devices – sdb is ‘missing’ – its still in use for LVM so ‘missing’
keyword is used.

[root@mythtv ~]# mdadm –create /dev/md0 –auto=yes -l 1 -n 2 /dev/sda2 missing
mdadm: array /dev/md0 started.

4. Prepare new md volume for LVM

[root@mythtv ~]# pvcreate /dev/md0
Physical volume “/dev/md0″ successfully created

5. Now extend the VolGroup00 vg to include the new md LVM volume

[root@mythtv ~]# vgextend VolGroup00 /dev/md0
Volume group “VolGroup00″ successfully extended

6. Now move data from /dev/sdb2 to LVM volume md0
[root@mythtv ~]# pvmove /dev/sdb2 /dev/md0

<long time>

7. Now we remove the sdb2 volume from LVM
[root@mythtv ~]# vgreduce VolGroup00 /dev/sdb2
[root@mythtv ~]# pvremove /dev/sdb2

8. Now we format /dev/sdb with fd (Linux RAID autodetect): (make it sdb1)
Same as sda.

9. Next add /dev/sdb2 to /dev/md0

[root@mythtv ~]# mdadm –manage /dev/md0 –add /dev/sdb2

10. Now the RAID array will be synchronized. This will take some time, you can check with

[root@mythtv ~]# cat /proc/mdstat

11. Update initrd BEFORE you reboot
If no /etc/mdadm.conf exists, you may choose to create it. It appears that I needed to
do that AND rebuild my initrd to support LVM on RAID1 during boot.

echo “DEVICE /dev/hd*[0-9] /dev/sd*[0-9]” > mdadm.conf
mdadm –detail –scan >> mdadm.conf

mkinitrd -f /boot/initrd-`uname -r`.img `uname -r`

12. Copy /boot over to sda – gets the new initrd (although /dev/sdb1 is still
labeled BOOT, so it is the partition that will be mounted as /boot)
[root@mythtv ~]# mke2fs /dev/sda1
mke2fs 1.40.2 (12-Jul-2007)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
38152 inodes, 152584 blocks
7629 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
19 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@mythtv ~]# mkdir /tmp/newboot
[root@mythtv ~]# mount /dev/sda1 /tmp/newboot/
[root@mythtv ~]# cd /boot
[root@mythtv boot]# find . -print | cpio -pvmd /tmp/newboot
/tmp/newboot/./vmlinuz-2.6.22.4-65.fc7
/tmp/newboot/./config-2.6.22.4-65.fc7
/tmp/newboot/./initrd-2.6.21-1.3194.fc7.img
/tmp/newboot/./System.map-2.6.21-1.3194.fc7
/tmp/newboot/./initrd-2.6.22.4-65.fc7.img
/tmp/newboot/./System.map-2.6.22.4-65.fc7
/tmp/newboot/./lost+found
/tmp/newboot/./grub
/tmp/newboot/./grub/device.map.old
/tmp/newboot/./grub/jfs_stage1_5
/tmp/newboot/./grub/device.map
/tmp/newboot/./grub/ufs2_stage1_5
/tmp/newboot/./grub/e2fs_stage1_5
/tmp/newboot/./grub/xfs_stage1_5
/tmp/newboot/./grub/stage2
/tmp/newboot/./grub/splash.xpm.gz
/tmp/newboot/./grub/grub.conf
/tmp/newboot/./grub/fat_stage1_5
/tmp/newboot/./grub/vstafs_stage1_5
/tmp/newboot/./grub/grub.conf.dist
/tmp/newboot/./grub/stage1
/tmp/newboot/./grub/menu.lst
/tmp/newboot/./grub/reiserfs_stage1_5
/tmp/newboot/./grub/iso9660_stage1_5
/tmp/newboot/./grub/minix_stage1_5
/tmp/newboot/./grub/ffs_stage1_5
/tmp/newboot/./config-2.6.21-1.3194.fc7
/tmp/newboot/./vmlinuz-2.6.21-1.3194.fc7
25716 blocks
[root@mythtv boot]# cd /
[root@mythtv /]# umount /tmp/newboot

13. If you’ve mucked around with the hd ordering in grub, undo it now:
Grub configuration:
# grub
grub> device (hd0) /dev/sda
grub> device (hd1) /dev/sdb
grub> root (hd0,0)
grub> setup (hd0)

14. Reinstall grub to ensure initrd references in grub are updated
[root@mythtv ~]# /sbin/grub-install /dev/sda
[root@mythtv ~]# /sbin/grub-install /dev/sdb

NOTE: I haven’t taken this to the fall back filesystems or having the
/boot filesystem on a RAID1 volume yet, but one should be able to enable
RAID1 for /boot now (create md1 == /dev/sda1 and /dev/sdb1 and setup an ext2 fs
on md1 to hold the RAID1 protected /boot fs). Haven’t tested
that yet, but did get that to work in earlier 2.6.x kernels (Debian and Fedora).

15. Hold breath, have Fedora Core 7 Rescue disk ready, Reboot

16. Celebrate.

© 2009 Allen Pomeroy. All Rights Reserved. This is the personal website of Allen Pomeroy. Opinions expressed are not necessarily those of my employer.