kopia lustrzana https://github.com/cyoung/stratux
67 wiersze
1.3 KiB
Bash
Executable File
67 wiersze
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# Part of spindle http://asbradbury.org/projects/spindle
|
|
#
|
|
# See LICENSE file for copyright and license details
|
|
|
|
# TODO: this script is very rough and ready. Currently grows an image to ~4GiB
|
|
|
|
set -x
|
|
|
|
if [ $(id -u) -ne 0 ]; then
|
|
printf "Script must be run as root\n"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! "$1" ]; then
|
|
printf "Usage: ./grow_image IMAGEFILE\n"
|
|
exit 1
|
|
fi
|
|
IMAGEFILE="$1"
|
|
|
|
# Grow the image file
|
|
dd of="$IMAGEFILE" bs=1 seek=3700M count=0
|
|
|
|
# Just use losetup to create a loopback device. fdisk will operate on files,
|
|
# but it complains about the number of cylinders not being set
|
|
|
|
LOOP_DEV=$(losetup -f)
|
|
|
|
losetup -v $LOOP_DEV "$IMAGEFILE"
|
|
|
|
# Partition resizing code same as in http://github.com/asb/raspi-config
|
|
PART_START=$(parted "$IMAGEFILE" -ms unit s p | grep "^2" | cut -f 2 -d:)
|
|
if [ ! "$PART_START" ]; then
|
|
printf "Failed to extract root partition offset\n"
|
|
fi
|
|
fdisk -cu $LOOP_DEV <<EOF
|
|
p
|
|
d
|
|
2
|
|
n
|
|
p
|
|
2
|
|
$PART_START
|
|
|
|
p
|
|
w
|
|
EOF
|
|
|
|
losetup -d $LOOP_DEV
|
|
|
|
# We know the offset anyway so let's just use losetup directly rather than
|
|
# bothering with kpartx
|
|
PART_START_BYTES=$((${PART_START%s}*512))
|
|
losetup --offset "$PART_START_BYTES" -v $LOOP_DEV "$IMAGEFILE"
|
|
|
|
# Sanity check
|
|
file -s $LOOP_DEV
|
|
|
|
# Run resize2fs
|
|
e2fsck -f $LOOP_DEV
|
|
resize2fs -p $LOOP_DEV
|
|
|
|
# Unmount it all
|
|
losetup -d $LOOP_DEV
|
|
|
|
printf "Success! (hopefully)\n"
|