Why I can't remove linux partitions on macOS Sierra I'm trying to remove linux partition from my iMac (21.5-inch, Mid 2011) on MacOS Sierra 10.12 Beta 2, So I tried existing solutions by using Disk Utility, I tried from Recovery as well, But it says 


  You can not remove this volume because the previous volume can not be resized








Some existing solutions use Terminal but I have no idea about that.

I need a simplest and easiest way to remove these linux partitions and grow my mac partition.
You can't expand a macOS partition to lower block numbers (i.e. to the "beginning of a disk") with on-board macOS tools.

Basically you have to remove all useless partitions, clone or restore your main macOS drive to a new partition on the same drive and delete the old one. 

Preparation:  


Backup your data.
Detach any external drive (especially your external Time Machine backup drive).
Restart to Internet Recovery Mode by pressing alt cmd R at startup.
The prerequisites are the latest firmware update installed, either Ethernet or WLAN (WPA/WPA2) and a router with DHCP activated.
On a 50 Mbps-line it takes about 4 min (presenting a small animated globe) to boot to a recovery netboot image which usually is loaded from an Apple/Akamai server.
Verify and repair your main macOS volume with Disk Utility


Modify partition table:


Open in the menubar Utilities/Terminal

First you should get an overview of your disks and the partition layout:
Enter diskutil list
Example listing:

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        500.1 GB    disk0
   1:                        EFI EFI                    209.7 MB    disk0s1
   2:           Linux Filesystem                        499.1 MB    disk0s2
   3:                 Linux Swap                          2.0 GB    disk0s3
   4:           Linux Filesystem                        247.5 GB    disk0s4
   5:                  Apple_HFS Mac OS X               248.6 GB    disk0s5
   6:                 Apple_Boot Recovery HD            650.0 MB    disk0s6
   7:                  Apple_HFS Recovery HD            650.0 MB    disk0s7
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     Apple_partition_scheme                         *1.3 GB    disk1
   1:        Apple_partition_map                         30.7 KB    disk1s1
   2:                  Apple_HFS OS X Base System        *1.3 GB    disk1s2
/dev/disk2-~disk14...


/dev/disk1-~disk14 ...belong to the macOS Base System (your recovery system you booted to previously)

disk0 is your main internal disk device containing the EFI-partition (dis0s1), some Linux partitions (disk0s2-disk0s4), your main macOS volume (disk0s5) and two Recovery HDs (disk0s6/disk0s7) one of which is useless - probably disk0s7.
To get a standard partition layout you have to delete a lot of partitions, create a new partition, dd or asr your main macOS volume to a new one and rearrange your recovery partition:
Get an overview:

gpt -r show disk0

Remove partitions (which requires to unmount disk0)

diskutil umountDisk disk0
gpt remove -i 7 disk0 #remove 2nd recovery partition
diskutil umountDisk disk0
gpt remove -i 4 disk0 #remove Linux 2nd partition (main)
diskutil umountDisk disk0
gpt remove -i 3 disk0 #remove Linux Swap
diskutil umountDisk disk0
gpt remove -i 2 disk0 #remove Linux 1st partition (booter?)

Create a new partition for a new main macOS with the same size as your old one:

diskutil umountDisk disk0
gpt add -i 2 -b 408640 -s 485511600 -t 48465300-0000-11AA-AA11-00306543ECAC disk0

Get a new updated view of the partition table:

diskutil list


Example listing:

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        500.1 GB    disk0
   1:                        EFI EFI                    209.7 MB    disk0s1
   2:                  Apple_HFS                        248.6 GB    disk0s2
   5:                  Apple_HFS Mac OS X               248.6 GB    disk0s5
   6:                 Apple_Boot Recovery HD            650.0 MB    disk0s6

dd your "old" macOS partition disk0s5 to the new partition disk0s2:

diskutil umountDisk disk0
dd if=/dev/disk0s5 of=/dev/disk0s2 bs=1m


(use the proper disk identifiers here: disk0s5 may be different)
remove your old main macOS partition

gpt -r show disk0
diskutil umountDisk disk0
gpt remove -i 5 disk0 #use the proper index number of your old macOS partition here

Create a new partition and clone your recovery partition:

diskutil umountDisk disk0
gpt add -i 3 -b 485920240 -s 1269536 -t 426F6F74-0000-11AA-AA11-00306543ECAC disk0
diskutil list #to get the proper device identifiers
diskutil umountDisk disk0
dd if=/dev/disk0s6 of=/dev/disk0s3 bs=1m
gpt -r show disk0
diskutil umountDisk disk0
gpt remove -i 6 disk0 #use the proper index number of your old recovery partition here

Expand your new main volume:

diskutil verifyVolume /dev/disk0s2
diskutil repairVolume /dev/disk0s2 #if necessary
diskutil resizeVolume /dev/disk0s2 499g

Reboot to your main volume


Always make certain to use the proper device identifiers - either with diskutil list or gpt -r show disk0! 



Finally I recommend to download and install a proper system! Your current system seems to be some public beta of Sierra.