18c2ecf20Sopenharmony_ci========= 28c2ecf20Sopenharmony_cidm-linear 38c2ecf20Sopenharmony_ci========= 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciDevice-Mapper's "linear" target maps a linear range of the Device-Mapper 68c2ecf20Sopenharmony_cidevice onto a linear range of another device. This is the basic building 78c2ecf20Sopenharmony_ciblock of logical volume managers. 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciParameters: <dev path> <offset> 108c2ecf20Sopenharmony_ci <dev path>: 118c2ecf20Sopenharmony_ci Full pathname to the underlying block-device, or a 128c2ecf20Sopenharmony_ci "major:minor" device-number. 138c2ecf20Sopenharmony_ci <offset>: 148c2ecf20Sopenharmony_ci Starting sector within the device. 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciExample scripts 188c2ecf20Sopenharmony_ci=============== 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci:: 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci #!/bin/sh 238c2ecf20Sopenharmony_ci # Create an identity mapping for a device 248c2ecf20Sopenharmony_ci echo "0 `blockdev --getsz $1` linear $1 0" | dmsetup create identity 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci:: 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci #!/bin/sh 298c2ecf20Sopenharmony_ci # Join 2 devices together 308c2ecf20Sopenharmony_ci size1=`blockdev --getsz $1` 318c2ecf20Sopenharmony_ci size2=`blockdev --getsz $2` 328c2ecf20Sopenharmony_ci echo "0 $size1 linear $1 0 338c2ecf20Sopenharmony_ci $size1 $size2 linear $2 0" | dmsetup create joined 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci:: 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci #!/usr/bin/perl -w 388c2ecf20Sopenharmony_ci # Split a device into 4M chunks and then join them together in reverse order. 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci my $name = "reverse"; 418c2ecf20Sopenharmony_ci my $extent_size = 4 * 1024 * 2; 428c2ecf20Sopenharmony_ci my $dev = $ARGV[0]; 438c2ecf20Sopenharmony_ci my $table = ""; 448c2ecf20Sopenharmony_ci my $count = 0; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci if (!defined($dev)) { 478c2ecf20Sopenharmony_ci die("Please specify a device.\n"); 488c2ecf20Sopenharmony_ci } 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci my $dev_size = `blockdev --getsz $dev`; 518c2ecf20Sopenharmony_ci my $extents = int($dev_size / $extent_size) - 528c2ecf20Sopenharmony_ci (($dev_size % $extent_size) ? 1 : 0); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci while ($extents > 0) { 558c2ecf20Sopenharmony_ci my $this_start = $count * $extent_size; 568c2ecf20Sopenharmony_ci $extents--; 578c2ecf20Sopenharmony_ci $count++; 588c2ecf20Sopenharmony_ci my $this_offset = $extents * $extent_size; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci $table .= "$this_start $extent_size linear $dev $this_offset\n"; 618c2ecf20Sopenharmony_ci } 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci `echo \"$table\" | dmsetup create $name`; 64