0

I have some disk image, taken with dd if=/dev/somedevice of=filename.img. I was able to shrink them following this tutorial.

Now I would like to script all the procedure, and I managed to perform almost everything, apart the fdisk resize part. I'm trying to resize the partition with this command

echo " , +7506944K," | sfdisk -N 2 /dev/loop14

But independently from the size I use I get an error:

/dev/loop14p2: Failed to resize partition #2.

How can i script the redefinition of the end of a partition? Why is my command failing, can I get some more information somehow?

3
  • The pipe is an automatic way to enter what you would have otherwise typed. Would running sfdisk -N 2 /dev/loop14 and then typing from the keyboard <space>,<space>+7506944K, work? May 5 at 15:00
  • Could you update with the partition table for /dev/loop14, and how will look after.
    – thanasisp
    May 5 at 15:36
  • @EduardoTrápani, I made some test using your method, and understood that the problem is the + sign. If I simply enter the size as 7506944K, without the plus it works. This obviously works also using the pipe
    – ErniBrown
    May 6 at 7:13

1 Answer 1

1

I understood what was wrong:

  • First, sfdisk accept the size of the partition, not the increment, so the + sign is wrong. One difference from fdisk is that the end is the sector number from the beginning of the partition, not from the beginning of the device.
  • Then the unit cannot be other than sectors.

So in my case, given the sector size of 512 bytes and a requested final size of approximately 7Gb , I had to launch the command as:

sudo sh -c 'echo " ,14596416" | sfdisk -N 2 /dev/loop14'
3
  • Units can be other than sectors, like size, see the reduce example here. I don't know if you define the end sector or sectors from the start, I guess the latter.
    – thanasisp
    May 6 at 12:38
  • @thanasisp have a look at the man page (man7.org/linux/man-pages/man8/sfdisk.8.html), the unit option is deprecated and states that only sector is accepted. I don't think it's clear, if is just the unit option that is deprecated or the whole usage of the size inside the commands. Anyway I was not able to resize correctly until i moved to the sector size. For the end sector yes, it's the number of sectors from the start (i'll modify the answer)
    – ErniBrown
    May 6 at 12:46
  • If that worked for you, then it seems good (also there was a trailing comma into the question, I am sure you tried some size without it).
    – thanasisp
    May 6 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.