reclaim SD card original size after having used it as operating system for Openelec

After having used one of my SD cards, in raspberry PI to host the operating system, i tried multiple times to restore it to its original size. It Only showed 125Mb of space while it should normally be around 4gb. Many utilities did not work, throwing errors. Disk part worked.

Open CMD in windows and type

diskpart

This lists all the drives registered in the system at the time and their original size (no partitions)

Select the drive (SD card) you want to reclaim space for.

Type : Select Drive #

Select Disk and the number of the drive, for me it was drive 2.

Type: Clean

Then navigate to windows disk manager, format the SD card with the file system you want FAT, FAT32 and assign it a drive letter.

Diskpart in windows
Reclaim SD card unused space

 

 

Update, below a complete set of commands since only clean does not seem to work always. Creating the primary partition and formating is needed after that.

SELECT DISK 1
CLEAN
CREATE PARTITION PRIMARY
SELECT PARTITION 1
ASSIGN
FORMAT FS=NTFS
EXIT

$’\r’: command not found

I usually crate my scripts on my windows everyday computer and upload them to my unix- bash running pc. Many times i get the error :$’\r’: command not found

This is caused by the “CRLF” End  of File for windows, which unix unfortunatelly does not like.

To correct this, open the script using Notepad++ and navigate to Edit>EOL Conversion>Unix(LF)

LF Notepad ++

And then retry the script.

This automatically converts all CRLF to LF. nice hah?