summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rwxr-xr-xsrc/btrfs-utils/btrfs-shrink54
2 files changed, 1 insertions, 55 deletions
diff --git a/Makefile b/Makefile
index e63d940..69b1405 100644
--- a/Makefile
+++ b/Makefile
@@ -58,7 +58,7 @@ dyndns_program_paths=$(addprefix cryptonomic-dyndns-server/bin/, $(dyndns_progra
58 58
59bin_programs += $(dyndns_program_paths) 59bin_programs += $(dyndns_program_paths)
60 60
61btrfs_utils=$(addprefix src/btrfs-utils/, btarfs btrfs-shrink with-btrfs-seed) 61btrfs_utils=$(addprefix src/btrfs-utils/, btarfs with-btrfs-seed)
62 62
63initrd_files:=$(wildcard src/initrd/*) dynmenu samizdat-pinentry wait_for_files 63initrd_files:=$(wildcard src/initrd/*) dynmenu samizdat-pinentry wait_for_files
64initramfs_conf_files:=$(wildcard initramfs-tools/*) 64initramfs_conf_files:=$(wildcard initramfs-tools/*)
diff --git a/src/btrfs-utils/btrfs-shrink b/src/btrfs-utils/btrfs-shrink
deleted file mode 100755
index 4c4e40d..0000000
--- a/src/btrfs-utils/btrfs-shrink
+++ /dev/null
@@ -1,54 +0,0 @@
1#!/bin/sh
2
3die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; }
4
5[ "$(id -u)" = 0 ] || die 'you are not root'
6
7shrink()
8{
9 local shrinkmegs=100 mountpoint="$1"
10 while true; do
11 while ! btrfs filesystem resize -${shrinkmegs}M "$mountpoint"/; do
12 shrinkmegs=$((shrinkmegs - 10 ))
13 if [ $shrinkmegs -lt 10 ]; then
14 return
15 fi
16 done
17 done
18}
19
20btrfs_truncate()
21{
22 local img="$1" bytes
23# 548044800/1176715264 bytes used
24 bytes=$(file "$img" | sed -ne 's?.*/\([0-9]*\) bytes used.*?\1?p')
25 if [ "$bytes" ]; then
26 truncate -s "$bytes" "$img"
27 fi
28}
29
30main()
31{
32 if [ -d "$1" ]; then
33 mountpoint=$1
34 mountpoint -q "$mountpoint" || die "not a mountpoint: $1"
35 shrink "$mountpoint"
36 elif [ -f "$1" ]; then
37 mountpoint="$1".mnt.tmp
38 mkdir "$mountpoint"
39 mount -t btrfs "$1" "$mountpoint"
40 result=$?
41 if [ $result = 0 ]; then
42 shrink "$mountpoint"
43 result=$?
44 umount "$mountpoint"
45 fi
46 rmdir "$mountpoint"
47 btrfs_truncate "$1"
48 return $result
49 else
50 die "not a file or directory: $1"
51 fi
52}
53
54main "$@"