-
Notifications
You must be signed in to change notification settings - Fork 11
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
It appears that the sfdisk output may have changes introducing space … #8
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# | ||
# see CHANGELOG.txt for release notes | ||
# | ||
VER=1.7.4 | ||
VER=1.7.5 | ||
|
||
|
||
|
||
|
@@ -150,7 +150,7 @@ cleanupSourceMounts() | |
# remove the partition dirs | ||
while read -r SRC_DIR; do | ||
if umount $SRC_DIR; then | ||
doMSg "unmounted source partition from $SRC_DIR" "info" | ||
doMsg "unmounted source partition from $SRC_DIR" "info" | ||
if rmdir $SRC_DIR; then | ||
doMsg "deleted empty source partition dir $SRC_DIR" "info" | ||
else | ||
|
@@ -1091,6 +1091,17 @@ runPostSyncHook() | |
fi | ||
} | ||
|
||
initDest() | ||
{ | ||
sfdisk --delete /dev/$DEST_DISK | ||
echo -e "size=+63M, type=e\ntype=5\nsize=+32M,type=83\nsize=+256M,type=c\ntype=83"| sfdisk $DEST_DISK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very specific structure, that matches your current install & will likely match most with NOOBS, but won't match many others. This is the real reason ClonePi currently does a partial dd to copy the MBR - there's a lot of ways to setup a system at the partition level. |
||
partprobe | ||
mkfs.vfat ${DEST_DISK}1 | ||
mkfs -t ext4 -F ${DEST_DISK}5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assumes there is a partition 5 - won't be the case for a vanilla Raspbian install (2 partitions). |
||
mkfs.vfat -F 32 ${DEST_DISK}6 | ||
partprobe | ||
} | ||
|
||
if [ $INIT_DEST_FILE = true -a "$CLONE_TO" = "file" ]; then | ||
# | ||
# full dd clone | ||
|
@@ -1124,47 +1135,22 @@ else | |
# partial dd clone of src disk -> dest disk | ||
doMsg "initialising $DEST_DISK, this may take some time..." "info" | ||
doMsg "setting up destination partition structure, copying ${DD_COUNT}MB..." "info" | ||
dd if=$SRC_DISK of=$DEST_DISK bs=1M count=$DD_COUNT | ||
initDest | ||
if [ ! "$?" = 0 ]; then | ||
doMsg "$DEST_DISK partial image did not complete." "error" | ||
fi | ||
# cleanup partition - to avoid volume not properly unmounted warnings | ||
LAST_PART_DEST_DEV="${DEST_DISK}${LAST_PART_NUM}" | ||
doMsg "running filesystem repair on last partition ${LAST_PART_DEST_DEV}" "info" | ||
fsck -p $LAST_PART_DEST_DEV &> /dev/null # discard errors | ||
|
||
if [ $RESIZE_DEST_DISK = true ]; then | ||
if [ $SRC_LARGER_THAN_DEST = true ]; then | ||
# resize down - parted wont run (Error: Can't have a partition outside the disk!) until the MBR is fixed up | ||
# using this approach: http://gparted.org/h2-fix-msdos-pt.php | ||
doMsg "Fixing MBR on ${DEST_DISK_NAME}..." "info" | ||
# get current MBR | ||
MBR=`sfdisk -d $DEST_DISK` | ||
# change partition size(s) so they are within DEST_SECTORS | ||
if [ ! "$SRC_EXTENDED_PART_NUM" = 0 ]; then | ||
# modify extended partition | ||
EXT_PART="${DEST_DISK}${SRC_EXTENDED_PART_NUM}" | ||
EXT_PART_ESCAPED=$(echo "$EXT_PART" | sed 's/\//\\\//g') | ||
EXT_PART_START=`fdisk -l -u $DEST_DISK | grep "^${EXT_PART}" | awk '{print $2}'` | ||
EXT_PART_NEW_SIZE=$((DEST_SECTORS - EXT_PART_START)) | ||
MBR_SEARCH_TERM=`echo "$MBR" | grep "^${EXT_PART}" | cut -f 2 -d, | xargs` | ||
MBR_REPLACE_TERM="size= ${EXT_PART_NEW_SIZE}" | ||
MBR=`echo "$MBR" | sed "/^${EXT_PART_ESCAPED}/s/${MBR_SEARCH_TERM}/${MBR_REPLACE_TERM}/"` | ||
doMsg "...modifying extended partition ${EXT_PART}..." "info" | ||
fi | ||
# modify last partition | ||
LAST_PART_ESCAPED=$(echo "$LAST_PART_DEST_DEV" | sed 's/\//\\\//g') | ||
LAST_PART_START=`fdisk -l -u $DEST_DISK | grep "^${LAST_PART_DEST_DEV}" | awk '{print $2}'` | ||
LAST_PART_NEW_SIZE=$((DEST_SECTORS - LAST_PART_START)) | ||
MBR_SEARCH_TERM=`echo "$MBR" | grep "^${LAST_PART_DEST_DEV}" | cut -f 2 -d, | xargs` | ||
MBR_REPLACE_TERM="size= ${LAST_PART_NEW_SIZE}" | ||
MBR=`echo "$MBR" | sed "/^${LAST_PART_ESCAPED}/s/${MBR_SEARCH_TERM}/${MBR_REPLACE_TERM}/"` | ||
doMsg "...modifying last partition ${LAST_PART_DEST_DEV}..." "info" | ||
# write MBR back to disk | ||
# NB: possible to get resource busy error from sfdisk, even tho it updates succesfully | ||
# a brief pause the update seems to resolve - but it may be better to discard error and assume OK | ||
sleep 1 | ||
sfdisk --force $DEST_DISK <<< "$MBR" | ||
initDest | ||
|
||
if [ "$?" = 0 ]; then | ||
doMsg "... updated MBR OK" "info" | ||
else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$DEST_DISK contains /dev/ already