wok diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mirror-tools/stuff/host/boot/lguest-disk Sun Aug 08 19:48:39 2010 +0200 1.3 @@ -0,0 +1,59 @@ 1.4 +#!/bin/sh 1.5 + 1.6 +usage() 1.7 +{ 1.8 + cat << EOT 1.9 +resize2fs 1.10 +usage: 1.11 +$0 grow <guest> <size>[MG] 1.12 +$0 fixmbr <guest> 1.13 +EOT 1.14 + exit 1 1.15 +} 1.16 + 1.17 +grow() 1.18 +{ 1.19 + case "$2" in 1.20 + *M) dd if=/dev/zero bs=1M count=${2%M} >> /boot/guests/$1 ;; 1.21 + *G) dd if=/dev/zero bs=1G count=${2%G} >> /boot/guests/$1 ;; 1.22 + esac 1.23 +} 1.24 + 1.25 +# write a 32 bits data 1.26 +# usage: storelong offset data32 file 1.27 +storelong() 1.28 +{ 1.29 + printf "00000 %02X %02X %02X %02X \n" \ 1.30 + $(( $2 & 255 )) $(( ($2>>8) & 255 )) \ 1.31 + $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \ 1.32 + hexdump -R | dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null 1.33 +} 1.34 + 1.35 +# read a 32 bits data 1.36 +# usage: getlong offset file 1.37 +getlong() 1.38 +{ 1.39 + dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \ 1.40 + hexdump -e '"" 1/4 "%d" "\n"' 1.41 +} 1.42 + 1.43 +fixmbr() 1.44 +{ 1.45 + if [ $(getlong 0x1ea $1) -ne 0 -a $(getlong 0x1fa $1) -ne 0 ]; then 1.46 + echo "Parttion 3 & 4 non empty. Abort" 1.47 + exit 1 1.48 + fi 1.49 + if [ $(getlong 0x1da $1) -eq 0 ]; then 1.50 + echo "Parttion 2 empty. Abort" 1.51 + exit 1 1.52 + fi 1.53 + size=$(stat -c %s $1) 1.54 + new=$(( $size/512 - 32 - $(getlong 0x1ca $1) )) 1.55 + storelong 0x1da $new $1 1.56 +} 1.57 + 1.58 +case "$1" in 1.59 +grow) shift; grow $@ ; fixmbr $1 ;; 1.60 +fixmbr) shift; fixmbr $1 ;; 1.61 +*) usage ;; 1.62 +esac