VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/ipxe/contrib/vm/cow

Last change on this file was 95666, checked in by vboxsync, 2 years ago

Devices/PC/ipxe: scm fixes and export to OSE, bugref:10254

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.1 KB
Line 
1#!/bin/sh
2
3set -e
4
5imgloop=
6tmpfile=
7tmploop=
8dmname=
9cowlink=
10
11function cleanup () {
12 set +e
13 [ -n "$cowlink" ] && rm $cowlink
14 [ -n "$dmname" ] && dmsetup remove $dmname
15 [ -n "$tmploop" ] && losetup -d $tmploop
16 [ -n "$tmpfile" ] && rm $tmpfile
17 [ -n "$imgloop" ] && losetup -d $imgloop
18}
19
20trap cleanup EXIT
21
22imgfile=$1 ; shift
23command=$1 ; shift
24if [ -z "$imgfile" -o -z "$command" ] ; then
25 echo Syntax: $0 /path/to/image/file command [args..]
26 exit 1
27fi
28
29# Set up image loop device
30x=`losetup -f` ; losetup -r $x $imgfile ; imgloop=$x
31
32# Create temporary file and set up temporary loop device
33tmpfile=`mktemp $imgfile.XXXXXXXXXX`
34truncate -r $imgfile $tmpfile
35x=`losetup -f` ; losetup $x $tmpfile ; tmploop=$x
36
37# Create snapshot device
38imgsize=`blockdev --getsz $imgloop`
39x=`basename $imgfile` ; echo 0 $imgsize snapshot $imgloop $tmploop N 16 | \
40 dmsetup create $x ; dmname=$x
41chown --reference=$imgfile /dev/mapper/$dmname
42chmod --reference=$imgfile /dev/mapper/$dmname
43
44# Create symlink
45x=$imgfile.cow ; ln -s /dev/mapper/$dmname $x ; cowlink=$x
46
47# Wait until killed
48echo "Created $cowlink"
49$command "$@" $cowlink
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette