Berikut adalah cara membuat, mengubah, dan menghapus partisi linux tanpa menggunakan LVM. Tutorial berikut sangat rawan menyebabkan kehilangan data. Backup terlebih dahulu partisi linux yang akan diubah-ubah atau biasakan diri anda menjalankan perintah-perintah berikut. Segala bentuk kehilangan data bukan merupakan tanggung jawab penulis.
List partisi linux yang ada, akan terlihat disk sdb sebesar 12 GB yang sudah kita tambahkan
[root@tesdisk ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 19.1G 0 disk └─sda1 8:1 0 19.1G 0 part / sdb 8:16 0 12G 0 disk sr0 11:0 1 1024M 0 rom
Masuk ke aplikasi untuk membuat partisi
[root@tesdisk ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. 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 g create a new empty GPT partition table G create an IRIX (SGI) partition table 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) Command (m for help):
Masukkan n untuk membuat partisi baru, p untuk tipe partisi primary, 1 untuk nomor partisi (jika ada partisi lain, bisa diisikan nomer 1-4 tergantung kondisi), First sector dan Last sector biarkan saja default ketika ingin mempartisi semua space disk, w untuk melakukan write konfigurasi yang baru saja kita buat
[root@tesdisk ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-25165823, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-25165823, default 25165823): Using default value 25165823 Partition 1 of type Linux and of size 12 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
List partisi setelah kita menjalankan fdisk (perhatikan ada tambahan sdb1)
[root@tesdisk ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 19.1G 0 disk └─sda1 8:1 0 19.1G 0 part / sdb 8:16 0 12G 0 disk └─sdb1 8:17 0 12G 0 part sr0 11:0 1 1024M 0 rom
Memformat partisi yang telah kita buat. Pada contoh di bawah ini, kita memakai mkfs.xfs untuk membuat partisi xfs.
[root@tesdisk ~]# mkfs.xfs -f /dev/sdb1 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=786368 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=3145472, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
Jika ingin ext4, maka bisa menggunakan mkfs.ext4
[root@tesdisk ~]# mkfs.ext4 -F /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Discarding device blocks: done Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 786432 inodes, 3145472 blocks 157273 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 96 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
Jika kita ingin mount disk, kita buat dulu folder untuk tempat mountnya
[root@tesdisk ~]# mkdir /mnt/disk1 [root@tesdisk ~]# ls /mnt/ disk1
Tambahkan sebuah baris di /etc/fstab agar partisi yang telah kita buat bisa dimount saat boot secara otomatis.
Untuk partisi xfs
/dev/sdb1 /mnt/disk1 xfs defaults 0 1
Untuk partisi ext4
/dev/sdb1 /mnt/disk1 ext4 defaults 0 1
Jalankan perintah berikut untuk mount partisi yang telah kita buat, sekaligus mengecek apakah baris pada /etc/fstab sudah benar. Pastikan tidak muncul eror apapun, karena eror pada file ini dapat menyebabkan sistem operasi tidak dapat booting
[root@tesdisk ~]# mount -a
Untuk mengecek apakah partisi yang telah kita buat berhasil, jalankan df -h
[root@tesdisk ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 1.2G 17G 7% / devtmpfs 875M 0 875M 0% /dev tmpfs 896M 0 896M 0% /dev/shm tmpfs 896M 17M 879M 2% /run tmpfs 896M 0 896M 0% /sys/fs/cgroup tmpfs 180M 0 180M 0% /run/user/0 /dev/sdb1 12G 33M 12G 1% /mnt/disk1
Coba kita tambahkan sebuah file di partisi yang baru saja kita mount
[root@tesdisk ~]# echo halo > /mnt/disk1/cek.txt [root@tesdisk ~]# cat /mnt/disk1/cek.txt halo
Kita reboot dan cek apakah partisinya otomatis ter-mount dan filenya masih ada
[root@tesdisk ~]# reboot [root@tesdisk ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 1.2G 17G 7% / devtmpfs 875M 0 875M 0% /dev tmpfs 896M 0 896M 0% /dev/shm tmpfs 896M 17M 879M 2% /run tmpfs 896M 0 896M 0% /sys/fs/cgroup /dev/sdb1 12G 33M 12G 1% /mnt/disk1 tmpfs 180M 0 180M 0% /run/user/0 [root@tesdisk ~]# cat /mnt/disk1/cek.txt halo
Kita resize disk yang kita pakai menjadi 15 GB, sdb akan menjadi 15 GB, dan sdb1 masih 12 GB
[root@tesdisk ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 19.1G 0 disk └─sda1 8:1 0 19.1G 0 part / sdb 8:16 0 15G 0 disk └─sdb1 8:17 0 12G 0 part /mnt/disk1 sr0 11:0 1 1024M 0 rom
Unmount partisi yang sudah termount (perintah di bawah ini bukan merupakan typo)
[root@tesdisk ~]# umount /mnt/disk1/
Masuk ke fdisk
[root@tesdisk ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. 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 g create a new empty GPT partition table G create an IRIX (SGI) partition table 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) Command (m for help):
Tekan p untuk print partisi yang ada di /dev/sdb
Command (m for help): p Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 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 Disk label type: dos Disk identifier: 0x0007c4fe Device Boot Start End Blocks Id System /dev/sdb1 2048 25165823 12581888 83 Linux
Tekan d untuk menghapus partisi, dan tekan n untuk membuat partisi baru sesuai ukuran yang diinginkan (15 GB) dengan langkah sama seperti saat kita membuat partisi baru (ya benar kita pilih d untuk menghapus partisi, namun karena kita sudah membuat partisi baru sebesar 15 GB sebelum menekan w, maka partisi kita akan menjadi ter-resize).
Note: Jangan memilih w setelah menekan d karena data yang sudah kita simpan akan hilang
Command (m for help): d Selected partition 1 Partition 1 is deleted Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-31457279, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279): Using default value 31457279 Partition 1 of type Linux and of size 15 GiB is set Command (m for help): p Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 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 Disk label type: dos Disk identifier: 0x0007c4fe Device Boot Start End Blocks Id System /dev/sdb1 2048 31457279 15727616 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@tesdisk ~]# reboot
Pastikan partisi sudah kita edit menjadi 15 GB
[root@tesdisk ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 19.1G 0 disk └─sda1 8:1 0 19.1G 0 part / sdb 8:16 0 15G 0 disk └─sdb1 8:17 0 15G 0 part /mnt/disk1 sr0 11:0 1 1024M 0 rom
Cek df -h, dan pastikan partisi masih berukuran 12 GB (karena kita belum memperbesar partisi xfs ataupun ext4nya)
[root@tesdisk ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 1.2G 17G 7% / devtmpfs 875M 0 875M 0% /dev tmpfs 896M 0 896M 0% /dev/shm tmpfs 896M 17M 879M 2% /run tmpfs 896M 0 896M 0% /sys/fs/cgroup /dev/sdb1 12G 33M 12G 1% /mnt/disk1 tmpfs 180M 0 180M 0% /run/user/0
Kita perbesar partisi xfsnya
[root@tesdisk ~]# xfs_growfs /mnt/disk1/ meta-data=/dev/sdb1 isize=512 agcount=4, agsize=786368 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=3145472, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 3145472 to 3931904 [root@tesdisk ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 1.2G 17G 7% / devtmpfs 875M 0 875M 0% /dev tmpfs 896M 0 896M 0% /dev/shm tmpfs 896M 17M 879M 2% /run tmpfs 896M 0 896M 0% /sys/fs/cgroup /dev/sdb1 15G 33M 15G 1% /mnt/disk1 tmpfs 180M 0 180M 0% /run/user/0
Untuk ext4, gunakan perintah berikut
[root@tesdisk ~]# resize2fs /dev/sdb1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/sdb1 is mounted on /mnt/disk1; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 2 The filesystem on /dev/sdb1 is now 3931904 blocks long. [root@tesdisk ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 1.2G 17G 7% / devtmpfs 875M 0 875M 0% /dev tmpfs 896M 0 896M 0% /dev/shm tmpfs 896M 17M 879M 2% /run tmpfs 896M 0 896M 0% /sys/fs/cgroup /dev/sdb1 15G 41M 14G 1% /mnt/disk1 tmpfs 180M 0 180M 0% /run/user/0
Cek kembali file yang telah kita tulis
[root@tesdisk ~]# cat /mnt/disk1/cek.txt halo
Unmount partisi yang akan dihapus
[root@tesdisk ~]# umount /mnt/disk1
Masuk ke fdisk
[root@tesdisk ~]# fdisk /dev/sdb
Tekan d untuk menghapus partisi dan pastikan partisi telah terhapus dengan menggunakan perintah p , dan hapus menggunakan w (perhatikan, di sini kita melakukan w(rite) setelah memilih d(elete) , yang secara otomatis akan menghapus semua data yang kita miliki di sdb1)
Command (m for help): d Selected partition 1 Partition 1 is deleted Command (m for help): p Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 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 Disk label type: dos Disk identifier: 0x0007c4fe Device Boot Start End Blocks Id System Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Buka/etc/fstab dan hapus kembali line berikut sesuai dengan jenis partisi yang dibuat
# /dev/sdb1 /mnt/disk1 xfs defaults 0 1 # /dev/sdb1 /mnt/disk1 ext4 defaults 0 1
Tertarik mengerjakan hal-hal semacam ini? Merasa tertantang dengan pekerjaan-pekerjaan yang lebih banyak menuntut automation? Let’s join us in here.
Jika ada pertanyaan maupun tanggapan terkait artikel ini, silahkan tuliskan di kolom komentar.
Hello everyone! 👋 Welcome to our step-by-step guide on using kubeadm to install Kubernetes. It's…
Proxmox adalah hypervisor yang populer digunakan karena penggunaannya yang cukup simpel jika dibandingkan dengan hypervisor…
This post is mirror of https://forums.rancher.com/t/failed-upgrade-from-v0-8-1-to-v1-0-0-caused-by-pv-created-before-v0-6-2/17586 I scale down all pods that has vpc to…
Ubuntu Konfigurasi network pada Ubuntu Server 18.04 berbeda dengan ubuntu versi sebelumnya. Versi sebelumnya menggunakan…
For detailed problems, see https://notulensiku.com/2019/02/fix-integrated-terminal-font-vscode/ To solve on mac, you need to install powerline fonts…
Untuk mengaktifkan Forward Secrecy pada web browser Apache, versi minimum yang dibutuhkan adalah: OpenSSL 1.0.1c+Apache…
View Comments
Terimakasih.. sangat bermanfaat untuk saya yg lagi belajar partisi dengan fdisk.
Senang bisa membantu 👍