Using lofiadm within a Solaris zone

From Docupedia

Written By: Steve Ayotte

Date: 4/30/2007

Contents

Overview

The goal of this how-to is to show you how you can allow 'root' within a zone to use the 'lofiadm' command to create loopback devices which can be used/mounted/etc. like other devices, e.g. disks or CD-ROMs.

The method, in short, is to map all of the necessary devices into the guest zone, so that the 'lofiadm' command can work on them. This does not create zone-specific devices, but allows the guest zone to operate as root on the ones that exist in the global zone. Any lofi devices created in this fashion will be visible to and accessible by any and all other local zones on the machine that have been similarly configured.

An alternative method would be to mount the lofi device within the global zone and map only that one device into the local zone. This would require the intervention of someone with root access on the global zone every time it needs to be done though, which could swiftly become annoying. You make the call on what will work best for you, after reading the instructions below you should be able to do either.

The good stuff

These are the discrete steps you'll follow:

  1. Shutdown the zone that you want to be able to create lofi devices in.
  2. Configure the zone appropriately
  3. Boot the zone back up
  4. Test creating and mounting a lofi device

Shutdown the zone

root@globalzone# zlogin myzone shutdown -i5 -g0 -y

Configure the zone

root@globalzone# zonecfg -z myzone
zonecfg:myzone> add device
zonecfg:myzone:device> set match=/dev/lofictl
zonecfg:myzone:device> end
zonecfg:myzone> add device
zonecfg:myzone:device> set match=/dev/lofi/*
zonecfg:myzone:device> end
zonecfg:myzone> add device
zonecfg:myzone:device> set match=/dev/rlofi/*
zonecfg:myzone:device> end
zonecfg:myzone> exit

Boot the zone back up

root@globalzone# zoneadm -z myzone boot
root@globalzone# zlogin myzone
[Connected to zone 'myzone' pts/2]
Last login: Mon Apr 30 18:14:37 on pts/2
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
root@myzone#

Test creating and mounting a lofi device

root@myzone# lofiadm -a /root/sampleISO.iso
/dev/lofi/1
root@myzone# mount -F hsfs /dev/lofi/1 /mnt
root@myzone# ls /mnt
somefile.txt somefile.bin somedir/
root@myzone#