This post is a result of 1 day’s worth of fiddling with bash to make an xfs type filesystem on a logical partition. I’m still learning this so some concepts might not be sufficiently elaborated. Use this as a quick lookup and I encourage more reading. If you want to skip all the drama and to get to the point, jump to The Process.
I could’ve done this with much less heartache using the GUI but where’s the fun in that! Such is the masochism of a new tux convert. I was sort of a tux-agnost earlier…..
First things first. Acknowledgements are due to my friends Suhas and Balaji who introduced me to Redhat, Knoppix, Fedora, Mandrake, BSD and Ubuntu between 2001 and 2007. I wasn’t too enthusiastic about all that back then but they’re my friends and seemed upbeat about it… so whatever fanned their sail!!! What happened after 2007? I became a .NET developer. MS-DOS baby!!!!
15 years hence, I’m kind of bored and irritated by Microsoft regurgitating LAMP, Fedora, .NET Framework-Core-Standard-6(old-wHine-new-bottle hocus pocus). I quit my job and am looking to expand my software & system engineering artistic expression.
Am now a CompTIA Network+ certified engineer. And I’m happy I did it. While studying for this certification, I developed an increased respect for my Electronics and Communication Engineering course 2003-2007…. That felt good!
I was frequently reminded of those early experiences with Linux. Back then, I had two 256 MB Seagate hard drives, one LG CD-DVD drive, a 3 1/2″ floppy drive, 30-40 2HD Amkette/Sony floppies and a 128 MB Corsair SDRAM. Not to forget, all this was useless without spare IDE cables, hard-drive jumper pins, GRUB and Partition Magic 8.
In the past 15 years, I’ve definitely used and managed some “stuff” hosted on Linux, thanks to the exposure from earlier and in general, thank you stackoverflow. But I always felt that mix of fear and uncertainty during each encounter. I only knew the beast’s name and nature. Not my ability to deal with it when unleashed. Now I’m facing those fears, prodding those timid memories. It ends now! I’m studying to get certified on Linux. CompTIA Linux+ की जय!
FHS, file, directory, user, group, permissions, daemons, services, protocols, … all done. Surprisingly, not at all daunting! Then I start studying about partition tables, linked files, filesystems. How hard can it be! ext2, swap and boot were my friends right? Right? RIGHT???? And my naivety is hung out to dry.
The Process
I could’ve done this with much less heartache using the GUI but where’s the fun in that! Such is the masochism of a new convert. I was sort of a tux-agnost earlier. Deja vu! Eerily familiar feelings now. I’m working with fdisk, gdisk and parted here.
After everything was done, this is what parted -l showed. Specifically note /dev/sdb5.
[root@centosmin ~]# parted -l
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 6443MB 5369MB primary xfs
3 6443MB 9663MB 3219MB primary ext4
4 9663MB 10.7GB 1075MB extended
5 9665MB 10.7GB 1073MB logical linux-swap(v1)
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary ext4
2 1075MB 2147MB 1073MB extended
5 1076MB 2147MB 1072MB logical xfs
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdc: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 1075MB 1074MB Linux filesystem
2 1075MB 2147MB 1073MB linux-swap(v1) Linux swap
sdb and sdc are 2GB virtual .vdi drives carved out just for this purpose.
In the standard MS-DOS Master Boot Record(for more than one reason, MS-DOS has lost its luster), we can only have a maximum of 4 partitions. So if we need to make more than 4, the standard process is to create 3 primary partitions, 1 extended partition and within that extended partition, create as many logical partitions as we need. Sounds easy.
/dev/sda was partitioned by the installer. Thankfully. I did have some recollection to keep /var, /tmp and others separate from /.
Trying out fdisk to make an MBR at /dev/sdb… I wanted to make 1 primary ext4, 1 logical xfs.
This is what I started with:
[root@centosmin ~]# 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): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 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: 0x000d51ee
Device Boot Start End Blocks Id System
First, the ext4 primary partition:
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-4194303, default 2048):↵
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): +1G
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 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: 0x000d51ee
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Next, create the enclosing extended partition as sdb2.
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 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: 0x000d51ee
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e
Partition number (2-4, default 2): 2
First sector (2099200-4194303, default 2099200):↵
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-4194303, default 4194303):↵
Using default value 4194303
Partition 2 of type Extended and of size 1023 MiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centosmin ~]# 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): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 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: 0x000d51ee
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 4194303 1047552 5 Extended
Now create the logical partition sdb5. By default, the logical partition will get created inside the sdb2 extended partition space.
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (2101248-4194303, default 2101248):↵
Using default value 2101248
Last sector, +sectors or +size{K,M,G} (2101248-4194303, default 4194303):↵
Using default value 4194303
Partition 5 of type Linux and of size 1022 MiB is set
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 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: 0x000d51ee
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 4194303 1047552 5 Extended
/dev/sdb5 2101248 4194303 1046528 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
At this point, I thought I needed to change the system ID of sdb5 to something that reflected ‘XFS’. So I needed to change it to ‘5’???
Command (m for help): t
Partition number (1,2,5, default 5): 5
Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 ❤ 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 5
You cannot change a partition into an extended one or vice versa.
Delete it first.
Type of partition 5 is unchanged: Linux
But what’s this? The default system ID indicates that the logical partition is of type EXT4 and I can’t change it to XFS?
I fiddled around fdisk with no luck No matter what I did, the new logical partition *Always* had system ID 83… same as sdb1. Read a few blogs but something seemed missing. They always jumped from creating the partition to calling it XFS without showing any evidence. No matter what site I followed, I got the same recommendations and the same result. Was there another config-default file which specified the default system ID for new partitions?
I switched tack and started using parted and didn’t have an issue. So how come so many people using fdisk haven’t mentioned anything about using parted as an intermediate step? Did everyone omit the same “seemingly trivial” step? I had to know! It wasn’t until I mistakenly tried fdisk to create the partition and then checkd using parted, that I saw the same output as I got with parted.
On checking this listing with parted -l, I was able to confirm, sdb5 was indeed of type XFS.
[root@centosmin ~]# parted -l
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary ext4
2 1075MB 2147MB 1073MB extended
5 1076MB 2147MB 1072MB logical xfs
To seal the deal, I used mkfs aliases to make the filesystems.
[root@centosmin ~]# ls -l /usr/sbin/mkfs*
-rwxr-xr-x. 1 root root 11520 Oct 1 2020 /usr/sbin/mkfs
-rwxr-xr-x. 1 root root 375240 Aug 7 2017 /usr/sbin/mkfs.btrfs
-rwxr-xr-x. 1 root root 37024 Oct 1 2020 /usr/sbin/mkfs.cramfs
-rwxr-xr-x. 4 root root 96336 Oct 1 2020 /usr/sbin/mkfs.ext2
-rwxr-xr-x. 4 root root 96336 Oct 1 2020 /usr/sbin/mkfs.ext3
-rwxr-xr-x. 4 root root 96336 Oct 1 2020 /usr/sbin/mkfs.ext4
-rwxr-xr-x. 1 root root 37136 Oct 1 2020 /usr/sbin/mkfs.minix
-rwxr-xr-x. 1 root root 368432 Oct 1 2020 /usr/sbin/mkfs.xfs
[root@centosmin ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centosmin ~]# mkfs.xfs /dev/sdb5
mkfs.xfs: /dev/sdb5 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@centosmin ~]# mkfs.xfs -f /dev/sdb5
meta-data=/dev/sdb5 isize=512 agcount=4, agsize=65408 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=261632, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
Moral of the story… if you have different tools to do the same job, find out how each of them can help you get the desired outcome.
All is well that ends well. Tchuss!