Disk management

Commands:

  • fdisk -l - list disks and partitions

  • fdisk /dev/sdX - access the disk with fdisk utility

  • mount /dev/sdX1 /mnt/... - mount a partition

  • umount /mnt/... - unmount a partition

  • mkfs.ext4 /dev/sdX1 - format a partition with ext4 file system

  • lsblk - list block devices (disks and partitions)

Tip

fdisk is a command-line utility that provides disk partitioning functions

How to format disk with NTFS file system on Linux:

  1. fdisk -l - list disks and partitions

  2. fdisk /dev/sdX - access the disk with fdisk utility to create a partition

  3. n - create a new partition

  4. p - primary partition

  5. 1 - partition number

  6. Enter - default first sector

  7. Enter - default last sector

  8. w - write table to disk and exit

  9. mkfs.ntfs /dev/sdX1 - format a partition with NTFS file system

How to use a disk on Windows, that has been formatted on Linux:

Note

If you want to use this disk on Windows, you will need to change the partition type from 0x83 to 0x07. You can do this with fdisk utility.

  1. fdisk -l - list disks and partitions

  2. fdisk /dev/sdX - access the disk with fdisk utility

  3. p - identify the partition by printing the partition table

  4. t - change partition type

  5. 7 - select partition type 0x07 (HPFS/NTFS/exFAT)

  6. w - write table to disk and exit

Note

Now you can use this disk on Windows. But if you want to use it on Linux again, you can run a command ntfsfix /dev/sdX1.