Resize sdcard with parted

So I had to reinstall Debian in the sdcard of my Orange Pi Lite. Thing is original image / fs is only 4Gb, which on a 64Gb sdcard leaves 60Gb unused.

Here is where parted comes to the rescue. Easier than fdisk for me. Below example extends ext4 partition to 62Gb and creates a 2Gb swap partition.

sudo parted  /dev/mmcblk0 
GNU Parted 3.2 
Using /dev/mmcblk0 
Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print
Model: SD BC2QT (sd/mmc) 
Disk /dev/mmcblk0: 64,0GB 
Sector size (logical/physical): 512B/512B 
Partition Table: msdos 
Disk Flags:  

Number  Start   End     Size    Type     File system  Flags  
1      21,0MB  73,4MB  52,4MB  primary  fat16        lba  
2      73,4MB  3743MB  3670MB  primary  ext4 

(parted) resizepart
Partition number? 2
End?  [3743MB]? 62000MB
(parted) print
Model: SD BC2QT (sd/mmc)
Disk /dev/mmcblk0: 64,0GB 
Sector size (logical/physical): 512B/512B 
Partition Table: msdos 
Disk Flags:  

Number  Start   End     Size    Type     File system  Flags  
1      21,0MB  73,4MB  52,4MB  primary  fat16        lba  
2      73,4MB  62,0GB  61,9GB  primary  ext4 

(parted) mkpart                                                            Partition type?  primary/extended? primary
File system type?  [ext2]? linux-swap
Start? 62.0GB
End? 64.0GB
(parted) print
Model: SD BC2QT (sd/mmc)
Disk /dev/mmcblk0: 64,0GB 
Sector size (logical/physical): 512B/512B 
Partition Table: msdos 
Disk Flags:  

Number  Start   End     Size    Type     File system     Flags  
1      21,0MB  73,4MB  52,4MB  primary  fat16           lba  
2      73,4MB  62,0GB  61,9GB  primary  ext4  
3      62,0GB  64,0GB  2022MB  primary  linux-swap(v1)  lba 
(parted)  
(parted) quit 
Information: You may need to update /etc/fstab. 

Now we only need to execute e2fsck and resize2fs on the extended partition.

sudo e2fsck -f /dev/mmcblk0p2  e2fsck 1.44.5 (15-Dec-2018) rootfs: recovering journal 
Pass 1: Checking inodes, blocks, and sizes 
Pass 2: Checking directory structure 
Pass 3: Checking directory connectivity 
Pass 4: Checking reference counts 
Pass 5: Checking group summary information rootfs: 109610/225344 files (0.2% non-contiguous), 650426/896000 blocks 
user@computer: ~ $ sudo resize2fs  /dev/mmcblk0p2  
resize2fs 1.44.5 (15-Dec-2018) 
Resizing the filesystem on /dev/mmcblk0p2 to 15118798 (4k) blocks. The filesystem on /dev/mmcblk0p2 is now 15118798 (4k) blocks long. 

Afterwards we can insert the sdcard into the OrangePi to have a 60Gb root partition.

sudo fdisk -l  
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: 0x00037d04 

Device         Boot     Start       End   Sectors  Size Id Type
/dev/mmcblk0p1          40960    143359    102400   50M  c W95 FAT32 (LBA) 
/dev/mmcblk0p2         143360 121093750 120950391 57.7G 83 Linux /dev/mmcblk0p3      121094144 125042687   3948544  1.9G 82 Linux swap / Solaris 

After OS boots we need to mkswap, activate and modify /etc/fstab.

mkswap /dev/mmcblk0p3; swapon /dev/mmcblk0p3; free -mt              
total        used        free      shared  buff/cache   available
Mem:            978         111          12          12         853         838
Swap:          1927           0        1927
Total:         2906         111        1940
/dev/mmcblk0p3	none	swap	sw		0		0