Format Ulang SD Card/Flashdisk Melalui Terminal tapi Device Busy, What Should I Do?


Well, niat ingin menulis artikel ini sebenarnya tiba-tiba muncul seketika ketika problema ini (format ulang SD card untuk keperluan raspi) bisa kuselesaikan. Error ini sangat menyebalkan menurutku dan searching di google sama sekali tidak membantu.

Dan tersangka utama dari masalah ini adalah

fitur auto mount

Auto mount...kalau tidak salah, pada versi linux yang terdahulu fitur ini belum ada. Jadi ketika kita ingin membaca isi file suatu flashdisk, maka kita harus mounting manual terlebih dahulu sebelum bisa membacanya beda dengan windows pada zaman itu yang lebih instan. Fitur inilah yang membuat 'device busy' sehingga kita tidak bisa melakukan operasi-operasi low level seperti format ulang memori atau re-partisi.

Ok, jadi ceritanya kita bisa melakukan banyak operasi low level atau manipulasi tabel partisi memori flashdisk atau SD card dengan command di terminal yaitu fdisk. Untuk me-list disk-disk apa saja yang terhubung dengan komputer kita bisa dengan perintah

 # fdisk -l  
 Disk /dev/sda: 465,8 GiB, 500107862016 bytes, 976773168 sectors  
 Units: sectors of 1 * 512 = 512 bytes  
 Sector size (logical/physical): 512 bytes / 4096 bytes  
 I/O size (minimum/optimal): 4096 bytes / 4096 bytes  
 Disklabel type: gpt  
 Disk identifier: 75D394BC-01C1-41B9-8DB0-6FC7B469AE64  
 Device     Start    End  Sectors  Size Type  
 /dev/sda1    2048  923647  921600  450M Windows recovery environment  
 /dev/sda2   923648  1128447  204800  100M EFI System  
 /dev/sda3  1128448  1161215   32768  16M Microsoft reserved  
 /dev/sda4  1161216 204802047 203640832 97,1G Microsoft basic data  
 /dev/sda5 204802048 316354559 111552512 53,2G Microsoft basic data  
 /dev/sda6 590786560 976771071 385984512 184,1G Microsoft basic data  
 /dev/sda7 316354560 582610943 266256384  127G Linux filesystem  
 /dev/sda8 582610944 590786559  8175616  3,9G Linux swap  
 Partition table entries are not in disk order.  
 Disk /dev/sdb: 7,4 GiB, 7948206080 bytes, 15523840 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: 0xccc7bfe8  
 Device   Boot Start   End Sectors Size Id Type  
 /dev/sdb1     2048  206847  204800 100M c W95 FAT32 (LBA)  
 /dev/sdb2    206848 15523839 15316992 7,3G 83 Linux  

Terlihat selain punya disk utama (/dev/sda) yang ada di dalam komputer, kita juga punya disk tambahan dari luar (/dev/sdb). Untuk mulai melakukan format memori, misal kita ingin format disk dari luar terebut maka perintahnya

 # fdisk /dev/sdb  

Lalu dari sini, banyak pilihan yang bisa kita lakukan pada disk tersebut. Semua optionnya ada di

 # man fdisk  

Pada kasus ini saya berniat untuk memformat ulang SD card milik saya untuk ditaruh OS arch linux arm untuk keperluan raspi. Jadi saya melakukan step by step seperti ini

 # fdisk /dev/sdb  
 Welcome to fdisk (util-linux 2.27.1).  
 Changes will remain in memory only, until you decide to write them.  
 Be careful before using the write command.  
 Command (m for help): o  
 Created a new DOS disklabel with disk identifier 0x8ac465f6.  
 Command (m for help): p  
 Disk /dev/sdb: 7,4 GiB, 7948206080 bytes, 15523840 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: 0x8ac465f6  
 Command (m for help): n  
 Partition type  
   p  primary (0 primary, 0 extended, 4 free)  
   e  extended (container for logical partitions)  
 Select (default p): p  
 Partition number (1-4, default 1): 1  
 First sector (2048-15523839, default 2048):   
 Last sector, +sectors or +size{K,M,G,T,P} (2048-15523839, default 15523839): +100M  
 Created a new partition 1 of type 'Linux' and of size 100 MiB.  
 Command (m for help): t  
 Selected partition 1  
 Partition type (type L to list all types): c  
 Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.  
 Command (m for help): n  
 Partition type  
   p  primary (1 primary, 0 extended, 3 free)  
   e  extended (container for logical partitions)  
 Select (default p): p  
 Partition number (2-4, default 2): 2  
 First sector (206848-15523839, default 206848):   
 Last sector, +sectors or +size{K,M,G,T,P} (206848-15523839, default 15523839):   
 Created a new partition 2 of type 'Linux' and of size 7,3 GiB.  

Sampai akhirnya saya akan melakukan 'write' (w) untuk menulis ulang tabel partisi (format yang sebenarnya)  ke SD card dan hasilnya gagal

 Command (m for help): w    
 The partition table has been altered.  
 Calling ioctl() to re-read partition table.  
 Re-reading the partition table failed.: Device or resource busy  
 The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).  

Yup, SD cardnya busy karena sudah termount otomatis oleh komputer. Selama masih termount kita tidak akan bisa memformatnya menggunakan fstab. Jadi solusinya apa? unmount SD card ini. Tapi sebelum melakukan unmount ini, kita harus tahu direktori mana yang menjadi link untuk mount memori ini. Kalau di ubuntu ini mudah, hanya dengan klik kanan > properties pada panel kiri tempat disk-disk yang terdeteksi pada komputer dan terlihat lokasi direktorinya.





Dari sini kita dapatkan direktori-direktori yang akan kita unmount. Kita unmount direktori-direktori ini dengan perintah

 # umount /media/genomexyz/87E9-7999  
 # umount /media/genomexyz/0791bf6d-4c40-4d95-98f8-4715dc91cc00  

Perhatikan, perintah untuk unmount di situ bukan 'unmount' tapi 'umount'. Kesalahan perintah untuk melakukan unmount ini sering terjadi karena masalah nama ini.

Setelah itu, kita ulangi lagi proses yang tadi dan

 # fdisk /dev/sdb  
 Welcome to fdisk (util-linux 2.27.1).  
 Changes will remain in memory only, until you decide to write them.  
 Be careful before using the write command.  
 Command (m for help): o  
 Created a new DOS disklabel with disk identifier 0xbbf27d46.  
 Command (m for help): p  
 Disk /dev/sdb: 7,4 GiB, 7948206080 bytes, 15523840 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: 0xbbf27d46  
 Command (m for help): n  
 Partition type  
   p  primary (0 primary, 0 extended, 4 free)  
   e  extended (container for logical partitions)  
 Select (default p): p  
 Partition number (1-4, default 1): 1  
 First sector (2048-15523839, default 2048):   
 Last sector, +sectors or +size{K,M,G,T,P} (2048-15523839, default 15523839): +100M  
 Created a new partition 1 of type 'Linux' and of size 100 MiB.  
 Command (m for help): t  
 Selected partition 1  
 Partition type (type L to list all types): c  
 Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.  
 Command (m for help): n  
 Partition type  
   p  primary (1 primary, 0 extended, 3 free)  
   e  extended (container for logical partitions)  
 Select (default p): p  
 Partition number (2-4, default 2): 2  
 First sector (206848-15523839, default 206848):   
 Last sector, +sectors or +size{K,M,G,T,P} (206848-15523839, default 15523839):   
 Created a new partition 2 of type 'Linux' and of size 7,3 GiB.  
 Command (m for help): w  
 The partition table has been altered.  
 Calling ioctl() to re-read partition table.  
 Syncing disks.  

Akhirnya usaha kita membuahkan hasil.

Mungkin cukup sekian untuk pembahasan kali ini. Walaupun niat saya sebenarnya ingin memasukkan OS arch linux ke SD card tapi itu tidak akan dibahas kali ini karena di luar konteks. Selain itu wiki dari arc linux arm sudah punya tutorial yang sangat jelas untuk tujuan itu. Sekian.

Komentar