forked from zfsonlinux/zfsonlinux.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-zvol.html
138 lines (111 loc) · 4.34 KB
/
example-zvol.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<html>
<head>
<title>ZVOL Example</title>
<meta name="keyword" content="zfs, linux"/>
<meta name="description" content="ZFS ZVOL Example." />
<meta name="robots" content="all" />
</head>
<body>
<center>
<a href="index.html"><img title="Native ZFS on Linux" alt="Native ZFS on Linux" src="images/zfs-linux.png"></a>
<table width=80%>
<tr>
<td>
<p>One of the interface layers available in the ZFS on Linux port
is the ZVOL. The ZVOL layer allows you to create a virtual block
device in a ZFS storage pool. While this may not immediately
seem like a big deal it does open up some interesting possibilities.
For example, your virtual block device is now backed by whatever
level of ZFS data replication you like (<em>mirror</em>, <em>raidz</em>,
<em>raidz2</em>, <em>etc</em>) all with online scrubbing. Your
virtual block device also has fast snapshots due to ZFS’s
copy on write transaction model. This allows you do some interesting
things like format an ext2 file system which uses a ZVOL based block
device and mount it on your system. Here’s an example how.</p>
<p>Create the <em>tank</em> zpool containing a raidz vdev spread
over 3 devices. It is recommended that you use the persistent
/dev/disk/by-id/* device names when creating your pool to avoid
any device reordering issues latter. Your device names will of
course be different.</p>
<pre>
$ sudo zpool create tank raidz scsi-SATA_Maxtor_7Y250M0_Y638RXME
scsi-SATA_Maxtor_7Y250M0_Y638S56E scsi-SATA_Maxtor_7Y250M0_Y638TJFE
$ sudo zpool status tank
pool: tank
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
tank ONLINE 0 0 0
raidz1-0 ONLINE 0 0 0
scsi-SATA_Maxtor_7Y250M0_Y638RXME ONLINE 0 0 0
scsi-SATA_Maxtor_7Y250M0_Y638S56E ONLINE 0 0 0
scsi-SATA_Maxtor_7Y250M0_Y638TJFE ONLINE 0 0 0
errors: No known data errors
</pre>
<p>Create a 100G block device named <em>fish</em> in the <em>tank</em>
zpool.</p>
<pre>
$ sudo zfs create -V 100G tank/fish
$ sudo zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 103G 356G 38.6K /tank
tank/fish 103G 459G 21.3K -
</pre>
<p>Each ZVOL block device will appear as a zd device in /dev/, a
symlink with the pool and dataset name will be automatically created
under /dev/zvol/. This behavior should be familiar because the
standard Linux /dev/disk/ symlinks are managed in fundamentally the
same way. Next we can partition the new <em>/dev/zvol/tank/fish</em>
block device.</p>
<pre>
$ sudo sfdisk -q /dev/zvol/tank/fish << EOF
0,
EOF
Disk /dev/zvol/tank/fish: 208050 cylinders, 16 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/zvol/tank/fish: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/zvol/tank/fish1 0+ 208049 208050- 104857199+ 83 Linux
/dev/zvol/tank/fish2 0 - 0 0 0 Empty
/dev/zvol/tank/fish3 0 - 0 0 0 Empty
/dev/zvol/tank/fish4 0 - 0 0 0 Empty
Successfully wrote the new partition table
Re-reading the partition table ...
</pre>
<p>Format the <em>/dev/zvol/tank/fish-part1</em> partition with ext2 and
mount it under <em>/mnt/tank/fish-part1</em>.</p>
<pre>
$ sudo mkfs.ext2 -q /dev/zvol/tank/fish-part1
$ sudo mkdir -p /mnt/tank/fish-part1
$ sudo mount /dev/zvol/tank/fish-part1 /mnt/tank/fish-part1
$ ls /mnt/tank/fish-part1
lost+found
</pre>
<p>Take a snapshot of the pristine ext2 filesystem and mount it read-only.</p>
<pre>
$ sudo zfs snapshot tank/fish@pristine
$ sudo mkdir /mnt/tank/fish@pristine-part1
$ sudo mount /dev/zvol/tank/fish\@pristine-part1 /mnt/tank/fish\@pristine-part1
$ ls /mnt/tank/fish\@pristine-part1
lost+found
</pre>
<p>Changes made to <em>tank/fish-part1</em> do not appear in the pristine
snapshot <em>tank/fish@pristine-part1</em></p>
<pre>
$ sudo touch /mnt/tank/fish-part1/foo
$ ls /mnt/tank/fish-part1/
foo lost+found
$ ls /mnt/tank/fish\@pristine-part1
lost+found
</pre>
</td>
</tr>
</table>
</center>
</body>
</html>