Thursday, April 14, 2011

Hack - Export existing volume on a physical drive via Openfiler VM

I have a piece of relatively old 150GB HDD with Linux file system, lying around for quite some time. Having installed Windows 7 64-bits as my primary OS, I hardly have a chance to make good use of that disk. To read Linux file system from Windows OS, there are a few good options out there, such as the one by Disk Internal and this opensource one.

But if you are like me, running a bunch of Linux virtual machines on a Windows 7 host, you might find this article helpful.

What we are going to do is to export the entire existing filesystem on this hard disk from the Openfiler virtual machine. But Openfiler uses Logical Volume Manager and does not give you an option to expose existing file systems without destroying the existing partition table. Well, I must say I haven't search hard enough on how to do that officially in Openfiler, but am happy with my workaround, which has been completed in 5 minutes.

This is what we will do.

1) Attach the physical volume to the Openfiler VM.

I assume you know how to figure out which physical drive is the one that you want to attach to your Openfiler VM. Be extremely careful not to attach the wrong one. Your Linux formatted disk drive will not appear in the Windows file explorer. To find out which one is your disk, try device manager, or Google is your friend.

On my Windows host, my linux harddrive is the Disk 3.


Once you have attached your physical disk to the VM, boot it up.

2) Create a share folder in Openfiler under one of your existing shares.




3) Mount the raw device to the new share folder created in step 2.

- Locate your raw device on the Openfiler server by using fdisk command.

[root@openfiler01 physical]# fdisk -l
Disk /dev/hda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000e329f

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1       19457   156288321   83  Linux

To mount,

#mount -t ext4 -o rw /dev/hda1 /mnt/home_shared/sharedvol/physical

Note: My HDD was formatted with ext4 fs.

You might need to re-export your filesystem

#exportfs -rv

Inspect the /etc/exports file in the Openfiler server.

/mnt/home_shared/sharedvol/physical 192.168.0.0/255.255.255.0(rw,anonuid=96,anongid=96,secure,root_squash,wdelay,sync)  192.168.19.0/255.255.255.0(rw,anonuid=96,anongid=96,secure,root_squash,wdelay,sync)  192.168.50.0/255.255.255.0(rw,anonuid=96,anongid=96,secure,root_squash,wdelay,sync)

Go to your client Windows OS (assuming it is on the same network as the Openfiler server, in my case 192.168.50.0/24), map to \\openfiler\home_shared\sharedvol\physical, you should see your existing files and should be able to copy into the drive as Samba mount.

Or from the command prompt

net use drive_letter: \\openfiler\home_shared\sharedvol\physical


Go to your NFS client Linux OS and create a mount point

#mkdir /mnt/physical

Mount with the following options

mount -o rw openfiler:/mnt/home_shared/sharedvol/physical /mnt/physical

Look at the new mounted folder, it works!

root@tibems01:/mnt/physical# df -m .
Filesystem           1M-blocks      Used Available Use% Mounted on
192.168.50.100:/mnt/home_shared/sharedvol/physical
                        150230     78025     64574  55% /mnt/physical
root@tibems01:/mnt/physical# 

Don't forget to make a backup of your openfiler /etc/exports, just in case.

Well, a hack that works and will survive Openfiler boot cycle.

Cheers,

No comments:

Post a Comment