Recovery HFS partition table

First think, scan your damage disk with a tool like “testdisk” ( look for lost partitions, unfortunately HFS is not fully supported by this great tool, then you need to use pdisk or other partition software.

Disk /dev/rdisk3 – 1000 GB / 931 GiB – CHS 121601 255 63
Partition Start End Size in sectors
>P HFS 262208 1953525151 1953262944

In my case, I’ve used pdisk directly on OS X:

leobook4-w:~ root# pdisk /dev/rdisk3
pdisk: No valid block 1 on ‘/dev/rdisk3’
Edit /dev/rdisk3 –
Command (? for help): i
A physical block is 512 bytes:
A logical block is 512 bytes:
size of ‘device’ is 1953525168 blocks (512 byte blocks):
new size of ‘device’ is 1953525168 blocks (512 byte blocks)
Command (? for help): c
First block: 262208
Length in blocks: 1953262944
Name of partition: recover_leo
Command (? for help): w
Writing the map destroys what was there before. Is that okay? [n/y]: y
The partition table has been altered!

Command (? for help): q

Solaris – Add swap to ZFS disk

I installed Solaris 10 05/09 on a machine and I used whatever the default swap space setting when I built the box. Now I need to increase the swap space and I can’t add a swap file, like was possible under UFS.

If your swap device is in use, then you might not be able to delete it. Check to see if the swap area is in use. For example:

$ swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 182,2 8 4194296 4194296

In the above output, blocks == free, so the swap device is not actually being used.

If the swap area is not is use, remove the swap area. For example:

$ swap -d /dev/zvol/dsk/rpool/swap

Confirm that the swap area is removed.

$ swap -l

No swap devices configured

Resize the swap volume. For example:

$ zfs set volsize=1G rpool/swap

Activate the swap area.

$ swap -a /dev/zvol/dsk/rpool/swap

$ swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 182,2 8 2097144 2097144

Securing “tmp” without repartition

1. First you should secure /tmp:

Make a 1GB file for /tmp parition and an ext3 filesystem for tmp:

# dd if=/dev/zero of=/dev/tmpFS bs=1024 count=1000000
# /sbin/mkfs.ext3 /dev/tmpFS

Create a backup copy of your current /tmp drive:

# cp -Rpf /tmp /tmpbackup

Mount our new tmp parition and change permissions:

# mount -o loop,noexec,nosuid,rw /dev/tmpFS /tmp
# chmod 1777 /tmp

Copy the old data:
cp -Rpf /tmpbackup/* /tmp/

If you run the mount command and you should get something like this:
/dev/tmpMnt on /tmp type ext3 (rw,noexec,nosuid,loop=/dev/loop0)

Edit /etc/fstab and add this:

/dev/tmpMnt /tmp ext3 loop,nosuid,noexec,rw 0 0

Test your fstab entry:

# mount -o remount /tmp

You can test it runnig a script on /tmp partition, if you get “permission denied” it is fine :)

2. Secure /var/tmp:

It should be done because some applications use /var/tmp as the temporary folder, and anything that’s accessible by all, needs to be secured.

Rename it and create a symbolic link to /tmp:

# mv /var/tmp /var/tmp1
# ln -s /tmp /var/tmp

Copy the old data back:

# cp /var/tmpold/* /tmp/

Note: you should restart and services that uses /tmp partition