Debian format external hard disk

Format external hard disk via command line

Check the harddisk info

fdisk -l | grep '^Disk'


Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors <-- This is the disk!!
Disk model: WDC WD1003FZEX-0
Disk /dev/sdb: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: Samsung SSD 850
Disklabel type: dos
Disk identifier: 0x646e9688

Check detial

fdisk -l

Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: WDC WD1003FZEX-0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Create partition

fdisk /dev/sda

Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0x190a9eac.

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):
First sector (2048-1953525167, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1953525167, default 1953525167):

Created a new partition 1 of type 'Linux' and of size 931.5 GiB.

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Review the partition

fdisk -l /dev/sda
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: WDC WD1003FZEX-0
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: dos
Disk identifier: 0x190a9eac

Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 1953525167 1953523120 931.5G 83 Linux

Format the partition

Format with ext4

mkfs -t ext4 /dev/sda1

mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 244190390 4k blocks and 61054976 inodes
Filesystem UUID: 5380f625-1626-4e10-bdc6-b0829d895f85
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

List out harddisk UUID

blkid

/dev/sdb5: UUID="c9f03f6c-4cdd-4336-bab7-e93ed1a91f90" TYPE="swap" PARTUUID="646e9688-05"
/dev/sdb1: UUID="f77930ef-b403-4de5-ac76-ca839fe9c980" BLOCK_SIZE="1024" TYPE="ext3" PARTUUID="646e9688-01"
/dev/sdb6: UUID="8fd672f3-3171-479b-aa53-e65ea387d5a3" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="646e9688-06"
/dev/sda1: UUID="5380f625-1626-4e10-bdc6-b0829d895f85" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="190a9eac-01" <-- This is the disk

Attach the disk on mount

nano /etc/fstab

加入營地的 UUID
# External harddisk
UUID=5380f625-1626-4e10-bdc6-b0829d895f85 /disk2 ext4 defaults 0

Final reboot your computer

Then you will see your harddisk

~ df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 732K 1.6G 1% /run
/dev/sda6 467G 2.7G 440G 1% /
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda1 108M 49M 54M 48% /boot
/dev/sdb1 916G 28K 870G 1% /disk2 <-- This ~~
tmpfs 1.6G 0 1.6G 0% /run/user/0

Photo by Nick on Unsplash