Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add choice to keep existing filesystem size #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
This is a modification of the original rpi-clone by Bill Wilson.

rpi-clone is a shell script that will back up (clone using dd and rsync)
a running Raspberry Pi file system to a destination SD card 'sdN' plugged
Expand Down Expand Up @@ -29,7 +30,7 @@ This is done by a partial 'dd' from the running booted device /dev/mmcblk0
to the destination SD card /dev/sdN followed by a fdisk resize and mkfs.ext4
of /dev/sdN partition 2. This creates a completed partition 1 containing
all boot files and an empty but properly sized partition 2 rootfs.
The SD card partitions are then mounted on /mnt/clone and rsynced to the
The SD card partitions are then mounted on /mnt/clone and rsynced to the
running system.

You should avoid running other disk writing programs when running rpi-clone,
Expand Down Expand Up @@ -76,6 +77,16 @@ or, use git to clone the repository:
$ cd rpi-clone
$ cp rpi-clone /usr/local/sbin


Bill Wilson
billw--at--gkrellm.net

Updated March 2014 by William Phelps - ask if file system should be
expanded to fill destination SD card or not.

A larger SD card will greatly improve wear levelling, thus increasing the
life of the card. However, the file system does not need to be expanded
to take advantage of this. Larger file systems make for larger backup images.
I wanted a version of this tool that would preserve the exisiting file
system size.

https://github.com/wbphelps/rpi-clone-wm.git
16 changes: 13 additions & 3 deletions rpi-clone
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ expand_rootfs()
# Get the starting offset of the root partition
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^2" | cut -f 2 -d:)
[ "$PART_START" ] || return 1
echo -n "Do you want to expand the destination /dev/$DST_DISK? (yes/no): "
read resp
if [ "$resp" = "y" ] || [ "$resp" = "yes" ]
then
PART_END=""
else
# Get the end offset of the root partition
PART_END=$(parted /dev/mmcblk0 -ms unit s p | grep "^2" | cut -f 3 -d:)
[ "$PART_END" ] || return 1
fi
# Return value will likely be error for fdisk as it fails to reload the
# partition table because the root fs is mounted
fdisk /dev/$DST_DISK > /dev/null <<EOF
Expand All @@ -191,7 +201,7 @@ n
p
2
$PART_START

$PART_END
p
w
q
Expand Down Expand Up @@ -256,9 +266,9 @@ then
# maybe the wrong size for the destination SD card. So fdisk it to
# make it fill the rest of the disk and mkfs it to clean it out.
#
echo "Sizing partition 2 (root partition) to use all SD card space..."
expand_rootfs
mkfs.ext4 $DST_ROOT_PARTITION > /dev/null
# mkfs.ext4 $DST_ROOT_PARTITION > /dev/null
mkfs.ext4 $DST_ROOT_PARTITION

echo ""
echo "/dev/$DST_DISK is initialized and resized. Its partitions are:"
Expand Down