forked from ffzg/gnt-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lv-insert-part.sh
executable file
·35 lines (22 loc) · 948 Bytes
/
lv-insert-part.sh
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
#!/bin/sh -xe
# insert bootable partition table at beginning of lv
test -z "$1" || test ! -e "$1" && echo "Usage: $0 /path/to/lv" && exit 1
lvs --noheadings -o vg_name,name,lv_size $1 | tee /dev/stderr | while read vg_name name lv_size ; do
lvcreate -s -L $lv_size -n ${name}.snap /dev/$vg_name/$name
# wipe beginning so that grub-install doesn't complain
dd if=/dev/zero of=/dev/$vg_name/$name bs=1 count=2048
# create partition
echo '2048,+,L,*' | sfdisk --no-reread /dev/$vg_name/$name
# FIXME label?
mkfs.ext4 -F -E offset=$(( 2048 * 512 )) /dev/$vg_name/$name
mkdir /tmp/$name
mount /dev/$vg_name/$name /tmp/$name -o offset=$(( 2048 * 512 ))
mkdir /tmp/${name}.snap
mount /dev/$vg_name/${name}.snap /tmp/${name}.snap
rsync -raHX --numeric-ids --sparse /tmp/${name}.snap/ /tmp/$name/
umount /tmp/${name}.snap
umount /tmp/$name
rmdir /tmp/${name}.snap
rmdir /tmp/${name}
lvremove -y /dev/$vg_name/${name}.snap
done