
Advanced Tasks
66
Accessing Devices from Inside
Virtual Private Server
It is possible to grant a Virtual Private Server read, write, or read/write access to a character or
block device. This might be necessary, for example, for Oracle database software if you want to
employ its ability to work with raw disk partitions.
In most cases, providing access to the file system hierarchy for a Virtual Private Server is
achieved by using bind mounts. However, bind mounts do not allow you to create new
partitions, format them with a file system, or mount them inside a Virtual Private Server. If you
intend to delegate disk management to a Virtual Private Server administrator, you shall use
either the
–-devices
or the
--devnodes
option of the
vzctl set
command.
The example session below illustrates the following situation: you want to allow the root user of
Virtual Private Server 101 to take responsibility for administering the
/dev/sdb
,
/dev/sdb1
and
/dev/sdb2
devices. In other words, you allow the VPS 101 system
administrator to repartition the
/dev/sdb
device and create file systems on the first two
partitions (or use them with any software capable of working with raw block devices, such as
Oracle database software).
First, we are going to grant the Virtual Private Server the permissions to work with the needed
block devices:
# vzctl set 101 --devices b:8:16:rw --devices b:8:17:rw --devices
b:8:18:rw --save
Setting devperms
Saved parameters for VPS 101
This command sets the read/write permissions for block devices with major number 8 and minor
numbers 16, 17 and 18 (corresponding to
/dev/sdb
,
/dev/sdb1
, and
/dev/sdb2
). If you
are not sure which major and minor numbers correspond to the necessary block devices, you
may issue the following command:
# ls -l /dev/sdb{,1,2}
brw-rw---- 1 root disk 8, 16 Jan 30 13:24 /dev/sdb
brw-rw---- 1 root disk 8, 17 Jan 30 13:24 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Jan 30 13:24 /dev/sdb2
Now let us create a 100-Mb Linux partition in addition to an already existing 2 GB partition on
/dev/sdb1
from VPS 101.
[root@vps101 root]# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 255 heads, 63 sectors, 2231 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 255 2048256 83 Linux
Command (m for help): n
Command action
e extended