11

When I run fdisk and change the size of a partition, fdisk says at the end of its output:

The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8)

I'd like to do so without having to reboot (and then write a script that does it) How do I use kpartx to do this correctly? I've tried:

kpartx -f -v /dev/mmcblk0

Which outputs:

mmcblk0p1 : 0 102400 /dev/mmcblk0 2048
mmcblk0p2 : 0 7657472 /dev/mmcblk0 104448

and:

kpartx -a -v /dev/mmcblk0

which outputs:

device-mapper: reload ioctl on mmcblk0p1 failed: Invalid argument
create/reload failed on mmcblk0p1
add map mmcblk0p1 (0:0): 0 102400 linear /dev/mmcblk0 2048
device-mapper: reload ioctl on mmcblk0p2 failed: Invalid argument
create/reload failed on mmcblk0p2
add map mmcblk0p2 (0:0): 0 7657472 linear /dev/mmcblk0 104448

This is for an SD card in a raspi running debian.

EDIT: To clarify what I am trying to do; I am deleting an unused p3 from an SD Card and resizing p2 to fill the card. The card currently contains a small boot partition p1 and p2 is where the OS sits.

4
  • Is the SD card currently in use? (E.g., does it have a mounted filesystem on it?) Commented Mar 3, 2014 at 16:11
  • @derobert, yes it does. it has 2 partitions: a small boot partition and a larger main partition where the majority of the OS sits. I am just trying to expand the 2nd partition to fill the card. Commented Mar 3, 2014 at 16:41
  • 2
    I'm pretty sure that's the answer—you can't. The kernel won't reread a partition table unless the device isn't in use... Commented Mar 3, 2014 at 16:49
  • Does partprobe help? Commented Mar 3, 2014 at 21:33

3 Answers 3

10

You want partx -u, not kpartx ( which operates on device-mapper devices ).

3
  • What is the purpose of -u flag? Commented Nov 21, 2016 at 1:21
  • 2
    @IgorGanapolsky, to update the kernel partition table to match the on disk one. A quick man partx would have answered this. Commented Jan 16, 2017 at 3:13
  • @Octopus This did it for me, where partprobe didn't. Partprobe then returned without that error. Commented Feb 11, 2019 at 18:53
6

I believe @derobert (who commented on the original question) is likely correct. In the case of fdisking a partition that is currently being used it seems there is no other option than to reboot.

Even when I use partprobe (which is obtained with apt-get install parted) I get the following output:

Error: Partition(s) 2, 3 on /dev/mmcblk0 have been written, but we have 
been unable to inform the kernel of the change, probably because it/they 
are in use.  As a result, the old partition(s) will remain in use.  You 
should reboot now before making further changes.
3
  • I did the same thing, good news is, that i was able to unmount, run partprobe <device>, and remount both partitions without rebooting. Unfortunately it still required downtime due to shutting down services. Commented Oct 2, 2014 at 21:05
  • 3
    More recent versions of parted / partprobe will not give such an error and can be used on a mounted partition without reboot. Commented May 18, 2015 at 2:02
  • @psusi , I'm using a recent version of parted but I still get the same error. The solution is to unmount the device before running parted on the device, then you don't have to reboot your system in order to inform the kernel to use the new partition instead of the old partition Commented May 1, 2019 at 18:49
1

I was getting this problem because I forgot to unmount the device. After a:

sudo umount /dev/sdb

fdisk worked correctly.

1
  • 1
    I still get an error: Calling ioctl() to re-read partition table. Re-reading the partition table failed.: Device or resource busy Commented Nov 21, 2016 at 1:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.