0

I'm trying to upgrade my Raspberry PI's SD card to a bigger one. I've seen and tried guides like this one: https://raspberrypi.stackexchange.com/questions/499/how-can-i-resize-my-root-partition

My setup is a bit different than what they seem to have though, and I'm having trouble figuring out how to do this properly without killing the partition table in the process.

fdisk output:

Device         Boot    Start      End  Sectors  Size Id
/dev/mmcblk0p1          8192  2357421  2349230  1.1G  e W95 FAT16 (LBA)
/dev/mmcblk0p2       2357422 15523839 13166418  6.3G 85 Linux extended
/dev/mmcblk0p5       2359296  2424829    65534   32M 83 Linux
/dev/mmcblk0p6       2424832  2553855   129024   63M  c W95 FAT32 (LBA)
/dev/mmcblk0p7       2555904 14467069 11911166  5.7G 83 Linux
/dev/mmcblk0p8      14467072 15515647  1048576  512M 83 Linux

gparted screenshot:

enter image description here

Could someone lend me a few wise words perhaps?

1
  • I have transcribed the image from your fdisk output
    – Fox
    May 7 '17 at 20:11
0

If you have Gparted, do it all with Gparted. This way you will not have to remember exact numbers or anything. Second advice is: do not make partitions switch places. If you want to enlarge root partition, move the data to the end of the free space and enlarge root in place. This is because you can not be sure there is no obsolete code that refers to partitions by their numbers.

6
  • I don't think I can do it through Gparted, I can't resize the mcblk0p2: i.imgur.com/yvs2DKI.png Oct 8 '16 at 11:02
  • Of course you can not, it is an extended partition. You must first resize or delete partitions included into it, and only after that you will be able to resize or move the extended partition itself. Oct 8 '16 at 11:12
  • To say it another way, you can change parameters of extended partition only as long as it does not require changes to the included logical partitions. So to move extended partition, you must enlarge it enough to cover old and new locations, move logical partitions to the new place and shrink extended partitions. Oct 8 '16 at 11:15
  • Or better yet, see if you can convert this SD card to GPT. I think you can. Then you will be able to move anything anywhere. Oct 8 '16 at 11:17
  • So does that mean that I should delete all the partions included into it? Would that not mean I lose the data? I'm not completely grasping this. Oct 9 '16 at 10:57
0

I don't see any problem if you want resize root partition. You don't need kill partitions.

Before all you need to resize extended partition /dev/mmcblk0p2. You can do it via Gparted. Then move /dev/mmcblk0p8 partition to the end of disk. At the final resize root /dev/mmcblk0p7 partition to all free space.

If your Gparted didn't want to resize extended partition /dev/mmcblk0p2 (i think because it was running inside this partition) then you have two ways:

  1. Recreate all partitions from mmcblk0p2 to mmcblk0p8 in fdisk program.
  2. Boot SystemRescueCD from USB flash drive on your computer and try again use GParted on SystemRescueCD.

Be carefully when you will use both programs. Fdisk program can't move partitions and data inside them. Don't change start sector number of boot partition on /dev/mmcblk0p6 and root partition on /dev/mmcblk0p7, another you will restore boot of installed Linux.

If you choose the first way, then you need to remember all information about all partition in sectors units. Then delete mmcblk0p2 partition. Don't write result at this step, fdisk doesn't apply changes immediately. And if you quit from fdisk or press Ctrl+C nothing will be changed. Then create mmcblk0p2 extended partition (press n then press e) with old start sector number and new last sector number. Then recreate other logical partitions (press n then press l) from /dev/mmcblk0p5 to /dev/mmcblk0p8 with old start and end sectors numbers. Change partitions types by pressing t key. Check (press p) all partitions will have old start and end sectors numbers and types exclude end sector number of mmcblk0p2 extended partition. If all is well then write changes to disk by pressing w key. Reboot your server. Then you can use GParted to move last two partitions to the end of disk and resize root partition.

In additions:

If fdisk don't want recreate partitions, then try to use parted:

$ sudo parted /dev/mmcblk0
(parted) unit s
(parted) print                                                            
(parted) resizepart 2 -1s                                                 
(parted) print                                                            
(parted) quit                                                            
$ sudo partprobe /dev/mmcblk0
$ sudo gparted /dev/mmcblk0

Good luck! And be carefully.

9
  • Hi, tried this but I can't because it doesn't want to resize the mcblk0p2: i.imgur.com/yvs2DKI.png Oct 8 '16 at 11:02
  • I've updated my answer. Oct 8 '16 at 19:17
  • Hi, thanks for that! I'm one step further but still stuck. It says the first logical drive I want to create is out of bounds. I added my steps here: pastebin.com/YD92jgD2. I think this is a good approach though. I can't boot from a livedisk as my SD card reader is not recognised properly in Linux, nor is it easy to boot with a USB stick and just use the internal reader of the raspberry. So would prefer to finish it with option 1. Oct 9 '16 at 11:22
  • Hmm... Don't save changes. Please show fdisk version and all out of fdisk command after press c and press p. Oct 9 '16 at 13:56
  • Version: "fdisk from util-linux 2.25.2". What else did you need? The information above the partition table? c -> p: DOS Compatibility flag is set (DEPRECATED!) Disk /dev/mmcblk0: 59.6 GiB, 64021856256 bytes, 125042688 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x000a71c7 Oct 9 '16 at 16:24
0

You cannot resize any partitions if they are mounted. If you look carefully, there are two key symbols on two partitions inside the extended partition. This will prevent any changes to the partitions.

There are various ways around your problem but you need to boot from something else to be able to unmount all partitions.

One possibility is to connect the card to a separate system using a card reader and use Gparted to resize any partitions you need after unmounting any partitions that get mounted automatically.

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.