wok view mirror-tools/stuff/host/boot/lguest-disk @ rev 5973

mirror-tools: add host scripts
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Aug 08 19:48:39 2010 +0200 (2010-08-08)
parents
children
line source
1 #!/bin/sh
3 usage()
4 {
5 cat << EOT
6 resize2fs
7 usage:
8 $0 grow <guest> <size>[MG]
9 $0 fixmbr <guest>
10 EOT
11 exit 1
12 }
14 grow()
15 {
16 case "$2" in
17 *M) dd if=/dev/zero bs=1M count=${2%M} >> /boot/guests/$1 ;;
18 *G) dd if=/dev/zero bs=1G count=${2%G} >> /boot/guests/$1 ;;
19 esac
20 }
22 # write a 32 bits data
23 # usage: storelong offset data32 file
24 storelong()
25 {
26 printf "00000 %02X %02X %02X %02X \n" \
27 $(( $2 & 255 )) $(( ($2>>8) & 255 )) \
28 $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \
29 hexdump -R | dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null
30 }
32 # read a 32 bits data
33 # usage: getlong offset file
34 getlong()
35 {
36 dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \
37 hexdump -e '"" 1/4 "%d" "\n"'
38 }
40 fixmbr()
41 {
42 if [ $(getlong 0x1ea $1) -ne 0 -a $(getlong 0x1fa $1) -ne 0 ]; then
43 echo "Parttion 3 & 4 non empty. Abort"
44 exit 1
45 fi
46 if [ $(getlong 0x1da $1) -eq 0 ]; then
47 echo "Parttion 2 empty. Abort"
48 exit 1
49 fi
50 size=$(stat -c %s $1)
51 new=$(( $size/512 - 32 - $(getlong 0x1ca $1) ))
52 storelong 0x1da $new $1
53 }
55 case "$1" in
56 grow) shift; grow $@ ; fixmbr $1 ;;
57 fixmbr) shift; fixmbr $1 ;;
58 *) usage ;;
59 esac