#527 Issue closed
: partition resizing¶
Labels: discuss / RFC
, support / question
lesmikesell opened issue at 2015-01-13 22:25:¶
I'm trying to use rear to convert a Centos5 system to a VM. The
source has 3 primary partitions on /dev/sda:
Disk /dev/sda: 146684248063B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32256B 106928639B 106896384B primary ext3 boot
2 106928640B 142387822079B 142280893440B primary ext3
3 142387822080B 146681418239B 4293596160B primary linux-swap
I've tried both smaller and larger target disks and the restore script
claims that it is resizing the partitions to fit, but parted always
claims that the value for the last partition is 'outside of the
device'. Actually, it only mentions resizing 2 partitions:
Partition primary on /dev/sda: size reduced to fit on disk.
Partition primary on /dev/sda: size reduced to fit on disk.
(when in fact this target disk is actually bigger) - after failing I have:
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 157840048127B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32768B 106929151B 106896384B primary boot
2 106930176B 157840048127B 157733117952B primary
And the failing command is:
parted -s /dev/sda mkpart '"primary"' 157840084992B 157840048127B >&2
Excerpts from a debug log below:
++ echo '2015-01-13 14:22:09 Device sda exists.'
2015-01-13 14:22:09 Device sda exists.
+++ get_disk_size sda
+++ local disk_name=sda
++++ get_block_size sda
++++ '[' -r /sys/block/sda/queue/logical_block_size ']'
++++ echo 512
+++ local block_size=512
+++ '[' -r /sys/block/sda/size ']'
+++ BugIfError 'Could not determine size of disk sda, please file a bug.'
+++ (( 0 != 0 ))
+++ local nr_blocks=308281344
+++ local disk_size=157840048128
+++ echo 157840048128
++ newsize=157840048128
++ '[' 157840048128 -eq 146684248064 ']'
++ LogPrint 'Device sda has size 157840048128, 146684248064 expected'
++ Log 'Device sda has size 157840048128, 146684248064 expected'
++ test 1 -gt 0
+++ Stamp
+++ date '+%Y-%m-%d %H:%M:%S '
++ echo '2015-01-13 14:22:09 Device sda has size 157840048128, 146684248064 expected'
2015-01-13 14:22:09 Device sda has size 157840048128, 146684248064 expected
++ Print 'Device sda has size 157840048128, 146684248064 expected'
++ test 1
++ echo -e 'Device sda has size 157840048128, 146684248064 expected'
++ MIGRATION_MODE=true
++ read disk dev size junk
[...]
+++ get_disk_size sda
+++ local disk_name=sda
++++ get_block_size sda
++++ '[' -r /sys/block/sda/queue/logical_block_size ']'
++++ echo 512
+++ local block_size=512
+++ '[' -r /sys/block/sda/size ']'
+++ BugIfError 'Could not determine size of disk sda, please file a bug.'
+++ (( 0 != 0 ))
+++ local nr_blocks=308281344
+++ local disk_size=157840048128
+++ echo 157840048128
++ newsize=157840048128
++ '[' 146684248064 -eq 157840048128 ']'
[...]
+++ grep '^disk ' /var/lib/rear/layout/disklayout.conf
++ read type device size junk
+++ get_sysfs_name /dev/sda
+++ local name=sda
+++ name=sda
+++ [[ -e /sys/block/sda ]]
+++ echo sda
+++ return 0
++ sysfsname=sda
++ [[ -d /sys/block/sda ]]
+++ get_disk_size sda
+++ local disk_name=sda
++++ get_block_size sda
++++ '[' -r /sys/block/sda/queue/logical_block_size ']'
++++ echo 512
+++ local block_size=512
+++ '[' -r /sys/block/sda/size ']'
+++ BugIfError 'Could not determine size of disk sda, please file a bug.'
+++ (( 0 != 0 ))
+++ local nr_blocks=308281344
+++ local disk_size=157840048128
+++ echo 157840048128
++ newsize=157840048128
++ (( 157840048128 == 146684248064 ))
++ oldsize=146684248064
++ difference=11155800064
++ Log 'Total resize of 11155800064B'
++ test 1 -gt 0
+++ Stamp
+++ date '+%Y-%m-%d %H:%M:%S '
++ echo '2015-01-13 14:22:28 Total resize of 11155800064B'
2015-01-13 14:22:28 Total resize of 11155800064B
++ Log 'Searching for resizeable partitions on disk /dev/sda (157840048128B)'
++ test 1 -gt 0
+++ Stamp
+++ date '+%Y-%m-%d %H:%M:%S '
++ echo '2015-01-13 14:22:28 Searching for resizeable partitions on disk /dev/sda (157840048128B)'
2015-01-13 14:22:28 Searching for resizeable partitions on disk /dev/sda (157840048128B)
++ partitions=()
++ resizeable_space=0
++ available_space=157840048128
++ read type part size start name flags name junk
+++ grep '^part /dev/sda' /var/lib/rear/layout/disklayout.conf
++++ grep '^swap /dev/sda' /var/lib/rear/layout/disklayout.conf
++++ cut '-d ' -f 2
+++ grep -v /dev/sda3
++ case "$flags" in
++ available_space=157733151744
++ Log 'Will not resize partition /dev/sda1.'
++ test 1 -gt 0
+++ Stamp
+++ date '+%Y-%m-%d %H:%M:%S '
++ echo '2015-01-13 14:22:28 Will not resize partition /dev/sda1.'
2015-01-13 14:22:28 Will not resize partition /dev/sda1.
++ read type part size start name flags name junk
++ case "$flags" in
++ partitions=("${partitions[@]}" "$name|${size%B}")
++ resizeable_space=142280893440
++ Log 'Will resize partition /dev/sda2.'
++ test 1 -gt 0
++ Stamp
+++ date '+%Y-%m-%d %H:%M:%S '
++ echo '2015-01-13 14:22:28 Will resize partition /dev/sda2.'
2015-01-13 14:22:28 Will resize partition /dev/sda2.
++ read type part size start name flags name junk
++ (( 1 == 0 ))
++ (( available_space < 0 ))
++ for data in '"${partitions[@]}"'
++ name=/dev/sda2
++ partition_size=142280893440
+++ echo '142280893440 142280893440 157733151744'
+++ awk '{ printf "%d", ($1/$2)*$3; }'
++ new_size=157733151744
++ (( new_size > 0 ))
++ BugIfError 'Partition /dev/sda2 resized to a negative number.'
++ (( 0 != 0 ))
+++ echo /dev/sda2
+++ sed -r 's/.+([0-9])$/\1/'
++ nr=2
++ sed -r -i 's|^(part /dev/sda) 142280893440(.+)2$|\1 157733151744\22|' /var/lib/rear/layout/disklayout.conf.tmp
++ Log 'Resized partition /dev/sda2 from 142280893440B to 157733151744B.'
++ test 1 -gt 0
+++ Stamp
+++ date '+%Y-%m-%d %H:%M:%S '
++ echo '2015-01-13 14:22:28 Resized partition /dev/sda2 from 142280893440B to 157733151744B.'
2015-01-13 14:22:28 Resized partition /dev/sda2 from 142280893440B to 157733151744B.
++ read type device size junk
++ mv /var/lib/rear/layout/disklayout.conf.tmp /var/lib/rear/layout/disklayout.conf
gdha commented at 2015-01-14 09:50:¶
@lesmikesell which version of rear are you using? Did you tried the
latest git version too? Was the original
/var/lib/rear/layout/disklayout.conf
correct with the real situation?
gdha commented at 2015-01-20 15:29:¶
@jhoekx were you busy with helping Mike? Via the mailing list.
jhoekx commented at 2015-01-20 15:38:¶
I briefly checked based on the mailing list conversation, but haven't had the time to investigate deeper...
lesmikesell commented at 2015-01-20 16:13:¶
The rear version is the rear-1.16.1-1.el5 rpm as packaged in EPEL for Centos 5. I didn't try anything newer. I think the disklayout.conf was right for an exactly-matching destination drive. But the resizing math came out wrong for both a smaller and larger destination. I ended up making it work by obtaining the values from the source disk and editing them into the restore.sh commands with a slightly larger target drive so I don't need help with this particular instance - I'm just reporting a bug in the resizing code. Contributing factors may be that this drive has 3 primary partitions, one of which is /boot. The same system has 2 other drives, each with a single partition and those worked as expected.
gdha commented at 2017-03-08 12:28:¶
@lesmikesell I guess we can close this issue as it is old?
lesmikesell commented at 2017-03-08 16:45:¶
Yes, closing. I haven't run into this situation again.
[Export of Github issue for rear/rear.]