How to shrink and expand SD card partition (A step by step guide)

Posted by:

|

On:

|

Shrinking the image (Using Gparted)

Note: While you can expand using Gparted as well, in this project, we used bash file instead.

Installation of Rufus and Gparted

  • For Rufus, go to their website (https://rufus.ie/en/) and download Rufus. Rufus helps format and create bootable USB flash drives, in this case for Gparted to be on a USB flash drive.

  • For Gparted, go to sourceforge for Gparted (https://sourceforge.net/projects/gparted/) and download Gparted. Gparted is used to resize partitions.

How to move Gparted onto a SD card (Using Rufus)

1. Choose the correct setting for Device (The SD card you are using) and Boot selection (ISO file of Gparted).

2. Choose “0” for persistent partition size and type the drive with a new name under “Volume label”. Then click the “Start” button.

  

3. Choose “Write in ISO image mode” and click “Ok” button for the warning.

Prepare the SD card for partition expansion

1. The SD card is installed with Ubuntu and is used in Orange Pi.

2. Edit /etc/fatab using nano.

sudo nano /etc/fatab

3. Append the following line to the file fatab

/dev/mmcblk0p1 /media/sdcard auto rw,user,exec,uid=1001,gid=1001,umask=000 0 2

4. Create a new bash file called max.sh at the root directory with the following commands

parted /dev/mmcblk0 resizepart 1 100% 
resize2fs /dev/mmcblk0p1

How to use Gparted

1. Inserting 2 SD cards into the computer (one contains bootable Gparted, the other is the SD card you want to read from or write).

2. Restart your computer.

3. Interrupt normal startup (For a Lenovo laptop, it’s by pressing “Enter” when it ask you to do so).

4. Choose “temporary startup device” (In my case it’s pressing “F12”).

5. Choose the corresponding USB for GParted to activate (In my case, I put it in a Micro SD slot).

6. Choose “Gparted Live (Default settings)”.

7. Choose “Don’t touch keymap” in configuring console-data.

8. Press “Enter” twice to select default value for the 2 questions (language and mode).

Resize the SD card partition size in Gparted

1. Select the SD card you want to resize and press the arrow icon.

2. Hover over the right side of the black rectangle and drag to the left side till it surround the yellow box and click the “Resize/Move” button.

Note: It has to be on the left side, or else it won’t be properly resize in the end. 

3. Click the green tick and select Apply to start the resize process.

4. After it’s done resizing, reboot the computer by double clicking he Exit icon (Top left of the desktop) and select Reboot.

Reading from SD card (using Win32DiskImager)

1. Start up the computer using the Windows operating system and launch Win32DiskImager.

2. Create a new image filename for the new image and select the correct device, ensuring that the option “Read Only Allocated Partitions” is ticked.

3. Click the “Read” button to extract the shrunken partition from the SD card and save it as an image.

Writing the image into a new SD card (using Win32DiskImager)

1. Insert a new SD card.

2. Choose the correct image file and device.

3. Click the “Write” button to transfer the shrunken image onto the SD card.

Expanding SD card (using Bash)

1. Reinsert the new SD card with the image into Orange Pi and turn it on.

2. Use SSH to connect to Ubuntu operating system on the Orange Pi with correct username and password.

3. The size of the partition is 3.1GB.

4. Run the following command.

bash max.sh

5. Input “y” and “127800” as your answers for the questions

6. Allow the SD card to expand the partition to it maximum capacity by waiting 1 to 2 minutes.

7. Log out and log back in, and you’ll discover that the partition size of the SD card has been expanded to its full size.

Posted by

in