In Linux environments I often have occasion to add an HDD after the fact, so I am writing it down again.
(About ten years ago I posted a similar article (adding an HDD with fdisk from the command line
(in Japanese)))
Environment
- The Linux used is Debian 12
- The format is xfs
- The HDD to be added is 4TB
I assume Linux (Debian) is already running and the HDD to be added is already installed
Preparation
Since I am formatting with xfs this time, I install the programs I need
# apt install parted xfsprogsCreating the partition
Check in advance which device you are going to partition and formatfdisk -l, or dmesg|grep sd, or lsblk
(this time it is /dev/sdb)
# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: /dev/sdb: unrecognised disk label
Model: ATA TOSHIBA MG04ACA4 (scsi)
Disk /dev/sdb: 4001GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) mkpart primary
Error: /dev/sdb: unrecognised disk label
(parted) mklabel gpt
(parted) p
Model: ATA TOSHIBA MG04ACA4 (scsi)
Disk /dev/sdb: 4001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart primary
File system type? [ext2]? xfs
Start? 1mb
End? -1
(parted) p
Model: ATA TOSHIBA MG04ACA4 (scsi)
Disk /dev/sdb: 4001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 4001GB 4001GB xfs primary
(parted) quit
Information: You may need to update /etc/fstab.Formatting with xfs
# mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=244188544 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=0
data = bsize=4096 blocks=976754176, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=476930, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0Mounting the added device
So that the order in which the disks are recognised does not change on reboot, I write the entry in fstab by UUID
How to check the UUID
(parts are masked to prevent misuse)
$ sudo /usr/sbin/blkid
/dev/sda1: UUID="7FD6-ACD4" TYPE="vfat" PARTUUID="xxxxxf04-29f1-4203-8dc4-2688e9896d3c"
/dev/sda2: UUID="xxxxx06a-cc81-47df-a2a8-3a1ac70fb2a3" TYPE="xfs" PARTUUID="xxxxx9a0-3dd6-4180-b8da-2c6660f5147e"
/dev/sda3: UUID="xxxxxc75-47a8-4f2c-bd73-754b2dc1fa64" TYPE="swap" PARTUUID="xxxxx685-05d9-4f8b-8bed-feb492c76358"
/dev/sdb1: UUID="xxxxx285-8b1f-49aa-bdc4-ac3a636e48b3" TYPE="xfs" PARTLABEL="primary" PARTUUID="xxxxxf44-5529-45b0-ba04-3a3e5e342b03"Writing it into fstab
This time I will mount /dev/sdb1 at /mnt/test.
$ mkdir /mnt/testAdd the following single line to fstab.
# vim /etc/fstab
UUID=xxxxx285-8b1f-49aa-bdc4-ac3a636e48b3 /mnt/test xfs defaults 0 0- Check
# mount -a
# df
...
/dev/sdb1 3905108984 8231592 3896877392 1% /mnt/testIf it is not mounted the way you intended, review the entry in fstab.
You must not reboot until you have confirmed it.