GNU/Linux >> Belajar Linux >  >> Linux

Perintah Fdisk di Linux (Kelola Partisi)

Fdisk adalah utilitas berbasis teks yang digunakan di Linux untuk mengelola partisi disk. Menggunakan fdisk Anda dapat melihat semua partisi disk, membuat partisi baru, menghapus partisi hard disk yang ada dan melihat ukuran partisi.

Menggunakan fdisk Anda diperbolehkan untuk membuat maksimal empat partisi utama, dan sejumlah partisi logis, berdasarkan ukuran disk. Ingatlah bahwa setiap partisi tunggal membutuhkan ukuran minimal 40MB.

Dalam tutorial ini, mari kita pelajari cara menggunakan perintah fdisk di linux dengan beberapa contoh.

1) Lihat semua partisi disk yang ada

Sebelum Anda membuat partisi baru atau memodifikasi partisi yang ada, Anda mungkin ingin melihat semua partisi yang tersedia di sistem.

Perintah akan mencantumkan partisi dari semua hard disk yang terhubung. Ketika Anda memiliki lebih dari satu disk pada sistem, daftar partisi diurutkan berdasarkan nama /dev perangkat. Misalnya, /dev/sda, /dev/sdb, /dev/sdc dan seterusnya.

Gunakan fdisk -l untuk melihat semua partisi yang tersedia sebagai berikut:

# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 2904 1951866 83 Linux
/dev/sda7 2905 3147 1951866 83 Linux
/dev/sda8 3148 3264 939771 82 Linux swap / Solaris
/dev/sda9 3265 5283 16217586 b W95 FAT32

2) Melihat partisi dari hard disk tertentu

Untuk melihat semua partisi hard disk '/dev/sda', lakukan hal berikut.

# fdisk -l /dev/sda

Lihat semua Perintah fdisk Menggunakan Perintah fdisk m

Gunakan perintah fdisk m , untuk melihat semua perintah fdisk yang tersedia seperti yang ditunjukkan di bawah ini:

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

3) Hapus partisi hard disk

Mari kita asumsikan bahwa Anda ingin menggabungkan beberapa partisi (misalnya, /dev/sda6, /dev/sda7 dan /dev/sda8) ke dalam satu partisi disk. Untuk melakukannya, pertama-tama Anda harus menghapus semua partisi individual tersebut, seperti yang ditunjukkan di bawah ini.

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 2904 1951866 83 Linux
/dev/sda7 2905 3147 1951866 83 Linux
/dev/sda8 3148 3264 939771 82 Linux swap / Solaris
/dev/sda9 3265 5283 16217586 b W95 FAT32

Command (m for help): d
Partition number (1-9): 8

Command (m for help): d
Partition number (1-8): 7

Command (m for help): d
Partition number (1-7): 6

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 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)
Syncing disks.

4) Buat partisi disk baru

Setelah Anda menghapus semua partisi yang ada, Anda dapat membuat partisi baru menggunakan semua ruang yang tersedia seperti yang ditunjukkan di bawah ini.

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (2662-5283, default 2662):
Using default value 2662
Last cylinder, +cylinders or +size{K,M,G} (2662-3264, default 3264):
Using default value 3264
In the above example, fdisk n command is used to create new partition with the specific size. While creating a new partition, it expects following two inputs.
Starting cylinder number of the partition to be create (First cylinder).
Size of the partition (or) the last cylinder number (Last cylinder, +cylinders or +size ).
Please keep in mind that you should issue the fdisk write command (w) after any modifications.
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 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)
Syncing disks.

Setelah partisi dibuat, formatlah menggunakan perintah mkfs seperti gambar di bawah ini.

# mkfs.ext3 /dev/sda7

5) Melihat ukuran partisi yang ada

Seperti yang ditunjukkan di bawah ini, fdisk -s menampilkan ukuran partisi dalam blok.

Dalam contoh berikut ini menunjukkan ukuran '/dev/sda7' sebagai 4900MB.

# fdisk -s /dev/sda7
4843566

6) Beralih bendera boot dari sebuah partisi

Perintah Fdisk menampilkan flag boot dari setiap partisi. Saat Anda ingin menonaktifkan atau mengaktifkan flag boot pada partisi yang sesuai, lakukan hal berikut.

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help): a
Partition number (1-7): 5

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help):

Seperti yang terlihat di atas, flag boot dinonaktifkan pada partisi '/dev/sda5'.

7) Perbaiki urutan tabel partisi

Saat Anda menghapus partisi logis dan membuatnya kembali, Anda mungkin melihat masalah 'partisi rusak'. yaitu pesan kesalahan 'Entri tabel partisi tidak dalam urutan disk'.

Misalnya, ketika Anda menghapus tiga partisi logis (sda6, sda7 dan sda8), dan membuat partisi baru, Anda mungkin mengharapkan nama partisi baru menjadi sda6. Tapi, sistem mungkin telah membuat partisi baru sebagai sda7. Ini karena, setelah partisi dihapus, partisi 'sda9' telah dipindahkan sebagai sda6 dan ruang kosong dipindahkan ke akhir.

Untuk memperbaiki masalah urutan partisi ini, dan menetapkan sda6 ke partisi yang baru dibuat, jalankan perintah ahli f seperti yang ditunjukkan di bawah ini.

$ fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help): x

Expert command (m for help): f
Done.

Expert command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 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)
Syncing disks.

Setelah urutan tabel partisi diperbaiki, Anda tidak akan mendapatkan pesan kesalahan 'Entri tabel partisi tidak dalam urutan disk' lagi.

# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 3264 4843566 83 Linux
/dev/sda7 3265 5283 16217586 b W95 FAT32

Kesimpulan

Dalam tutorial ini, kita belajar bagaimana menggunakan perintah fdisk di Linux untuk mengelola partisi. Saya harap Anda menikmati membaca dan silakan tinggalkan saran Anda di kotak komentar di bawah ini. Catatan:Jangan hapus, ubah, atau tambah partisi, jika Anda tidak tahu apa yang Anda lakukan. Anda mungkin akhirnya kehilangan data Anda. Hati-hati.


Linux
  1. Cara mempartisi disk di Linux

  2. Cara Mencadangkan atau Mengkloning Partisi Linux Menggunakan Perintah 'cat'

  3. Cara menggunakan fdisk untuk mempartisi disk di Linux

  1. Cara Menghapus Partisi di Linux

  2. Cara Membuat Partisi di Linux

  3. Cara Membuat Partisi Disk dengan Perintah Parted di Linux

  1. 5 alat teratas untuk Memantau Penggunaan dan Partisi Disk Linux Anda

  2. Perintah Fdisk di Linux (Buat Partisi Disk)

  3. Cara mengkloning disk dengan perintah Linux dd