sd(4)

πŸ’Ύ sd(4) β€” the SCSI disk driver, bestie edition πŸ’–

okay so this is a page from the Kernel Interfaces Manual, and it's literally all about sd, the driver for SCSI disk drives. she's iconic, she's been here forever, let's get into it 🫢


✨ SYNOPSIS ✨

#include <linux/hdreg.h>        /* for HDIO_GETGEO */
#include <linux/fs.h>           /* for BLKGETSIZE and BLKRRPART */

yes bestie you gotta include both headers, they're not optional, each one is pulling its own weight πŸ’…


πŸŽ€ CONFIGURATION πŸŽ€

so the block device name is shaped like sdlp β€” where l is a letter (the physical drive) and p is a number (the partition on that drive). and like, super often people just leave the partition number p off entirely when they mean the whole drive, no cap.

SCSI disks have a major device number of 8, and the minor device number goes like this:

(16 * drive_number) + partition_number

where drive_number is just the physical drive's number in the order it got detected, and partition_number is:

  • partition 0 is the whole drive πŸ‘‘
  • partitions 1–4 are the DOS "primary" partitions
  • partitions 5–8 are the DOS "extended" (or "logical") partitions

for example, /dev/sda has major 8 and minor 0, and it refers to, like, all of the first SCSI drive in the system. and /dev/sdb3 has major 8 and minor 19 and refers to the third DOS "primary" partition on the second SCSI drive. the math is mathing ✨

at this time, only block devices are provided. raw devices have not yet been implemented β€” like, at all. sad but true 😭

πŸ’… DESCRIPTION πŸ’…

the following ioctls are provided, and they are serving:

  • HDIO_GETGEO β€” returns the BIOS disk parameters in this structure:
struct hd_geometry {
    unsigned char  heads;
    unsigned char  sectors;
    unsigned short cylinders;
    unsigned long  start;
};

a pointer to this structure is passed as the ioctl(2) parameter.

the info you get back in that parameter is the disk geometry of the drive as understood by DOS! and this is not the physical geometry of the drive, okay, don't get it twisted. it is used when constructing the drive's partition table though, and you need it for convenient operation of fdisk(1), efdisk(1), and lilo(1). and if the geometry info isn't available, you get zero for all the parameters. zero, bestie. all of them. πŸ’€

  • BLKGETSIZE β€” returns the device size in sectors. the ioctl(2) parameter should be a pointer to a long.
  • BLKRRPART β€” forces a reread of the SCSI disk partition tables. no parameter needed, she's low maintenance πŸ¦‹

the SCSI ioctl(2) operations are also supported. and here's the catch: if the ioctl(2) parameter is required and it's NULL, then ioctl(2) fails with the error EINVAL. so don't do that πŸ™ˆ


🌸 FILES 🌸

  • /dev/sd[a-h] β€” the whole device
  • /dev/sd[a-h][0-8] β€” individual block partitions

and that's the whole page, you ate that πŸ“ this lil gem comes to you from Linux man-pages 6.20, dated 2026-02-08 β€” periodt, mwah πŸ’œβœ¨

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms