{"id":2896,"date":"2022-05-21T01:21:45","date_gmt":"2022-05-21T01:21:45","guid":{"rendered":"https:\/\/dft.wiki\/?p=2896"},"modified":"2026-06-08T21:46:55","modified_gmt":"2026-06-09T01:46:55","slug":"managing-partitions-from-the-command-line","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=2896","title":{"rendered":"Managing Partitions from the Command Line"},"content":{"rendered":"<p>Checking the drives attached to the Linux server or workstation.<\/p>\n<ul>\n<li>mount\n<ul>\n<li>Shows all mounted partitions.<\/li>\n<li>Note that it lists much more than physical or virtual volumes. It also includes logical volumes used by the kernel.<\/li>\n<\/ul>\n<\/li>\n<li>lsblk\n<ul>\n<li>Lists all disks as a tree with their partitions and mount points.<\/li>\n<\/ul>\n<\/li>\n<li>lsblk -S\n<ul>\n<li>Lists all disks in a table with additional information such as Brand, Model, Revision, Serial, etc.<\/li>\n<\/ul>\n<\/li>\n<li>sudo disktype \/dev\/sdX\n<ul>\n<li>Shows detailed information about a disk and its partitions.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<p><strong>FDISK<\/strong><\/p>\n<p>Popular commands for interactive mode:<\/p>\n<ul>\n<li>sudo fdisk \/dev\/sd<strong>X<\/strong>\n<ul>\n<li>Replace <strong>X<\/strong> with the letter the kernel has assigned to the disk.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ol>\n<li><strong>m<\/strong>\n<ol>\n<li>Prints the menu options.<\/li>\n<\/ol>\n<\/li>\n<li><strong>p<\/strong>\n<ol>\n<li>Prints the partition table.<\/li>\n<\/ol>\n<\/li>\n<li><strong>d<\/strong>\n<ol>\n<li>Deletes a partition. If there is more than one, it will prompt you to select which one.<\/li>\n<li>If there is only one partition, it will be selected automatically.<\/li>\n<\/ol>\n<\/li>\n<li><strong>n<\/strong>\n<ol>\n<li>Creates a new partition. It will ask for the partition type: extended or primary (up to 4).<\/li>\n<li>It will then ask where the partition starts (cylinder number) and how large it will be (in KB, MB, GB, or by cylinder).<\/li>\n<\/ol>\n<\/li>\n<li><strong>t<\/strong>\n<ol>\n<li>Changes a partition type.<\/li>\n<\/ol>\n<\/li>\n<li><strong>l<\/strong>\n<ol>\n<li>Lists known partition types.<\/li>\n<\/ol>\n<\/li>\n<li><strong>F<\/strong>\n<ol>\n<li>Lists unallocated space blocks.<\/li>\n<\/ol>\n<\/li>\n<li><strong>g<\/strong>\n<ol>\n<li>Wipes the drive and creates a new GPT partition table (recommended).<\/li>\n<\/ol>\n<\/li>\n<li><strong>o<\/strong>\n<ol>\n<li>Wipes the drive and creates a new MBR partition table (partitions are limited to 2 TB).<\/li>\n<\/ol>\n<\/li>\n<li><strong>v<\/strong>\n<ol>\n<li>Verifies the integrity of the partition table.<\/li>\n<\/ol>\n<\/li>\n<li><strong>i<\/strong>\n<ol>\n<li>Prints information about a partition.<\/li>\n<\/ol>\n<\/li>\n<li><strong>w<\/strong>\n<ol>\n<li>Writes all changes to the disk and quits.<\/li>\n<\/ol>\n<\/li>\n<li><strong>q<\/strong>\n<ol>\n<li>Quits without saving any changes to the disk.<\/li>\n<\/ol>\n<\/li>\n<li><strong>e<\/strong>\n<ol>\n<li>Enters expert mode.\n<ol>\n<li><strong>i<\/strong>\n<ol>\n<li>Changes the disk GUID.<\/li>\n<\/ol>\n<\/li>\n<li><strong>n<\/strong>\n<ol>\n<li>Changes the name of a partition.<\/li>\n<\/ol>\n<\/li>\n<li><strong>u<\/strong>\n<ol>\n<li>Changes the UUID of a partition.<\/li>\n<\/ol>\n<\/li>\n<li><strong>l<\/strong>\n<ol>\n<li>Changes the table length.<\/li>\n<\/ol>\n<\/li>\n<li><strong>A<\/strong>\n<ol>\n<li>Flags a legacy BIOS partition as bootable.<\/li>\n<\/ol>\n<\/li>\n<li><strong>p<\/strong>\n<ol>\n<li>Prints the partition table with additional information.<\/li>\n<\/ol>\n<\/li>\n<li><strong>r<\/strong>\n<ol>\n<li>Returns to the previous menu.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>fdisk can also apply changes non-interactively via scripts. See the sfdisk section in the manual for details and examples.<\/p>\n<ul>\n<li><strong>sudo fdisk -l<\/strong>\n<ul>\n<li>Lists all disks attached to the system.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<p><strong>CFDISK<\/strong><\/p>\n<p>cfdisk does the same thing as fdisk but with a more visual interface. You can navigate partitions and menu options using the arrow keys or keyboard shortcuts.<\/p>\n<ul>\n<li>sudo cfdisk \/dev\/sd<strong>X<\/strong>\n<ul>\n<li>Opens the application on the specified drive.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2897 \" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2022\/05\/Screenshot_2022-05-20_21-12-55.png\" alt=\"\" width=\"500\" height=\"280\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2022\/05\/Screenshot_2022-05-20_21-12-55.png 832w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2022\/05\/Screenshot_2022-05-20_21-12-55-300x168.png 300w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2022\/05\/Screenshot_2022-05-20_21-12-55-768x430.png 768w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<hr \/>\n<p><strong>PARTED<\/strong><\/p>\n<p>Parted is a powerful partition editor. It also has a graphical version called <strong>gparted<\/strong>, which is the default in most GNOME-based distributions.<\/p>\n<p><strong>Important:<\/strong> Changes are written to the disk immediately. There is no separate write step.<\/p>\n<ul>\n<li>sudo parted \/dev\/sd<strong>X<\/strong>\n<ul>\n<li>Opens the application for disk <strong>X<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<li>sudo parted\n<ul>\n<li>Opens the application without specifying a disk.<\/li>\n<\/ul>\n<\/li>\n<li>help\n<ul>\n<li>Prints the available options.<\/li>\n<\/ul>\n<\/li>\n<li>select \/dev\/sd<strong>X<\/strong>\n<ul>\n<li>Selects the disk to edit.<\/li>\n<\/ul>\n<\/li>\n<li>print\n<ul>\n<li>Prints the partition table.<\/li>\n<\/ul>\n<\/li>\n<li>help mklabel\n<ul>\n<li>Shows instructions and options for the mklabel command.<\/li>\n<\/ul>\n<\/li>\n<li>mklabel gpt\n<ul>\n<li>Creates a GPT partition table on the disk. Caution: this wipes the entire disk.<\/li>\n<\/ul>\n<\/li>\n<li>help mkpart\n<ul>\n<li>Shows the available options for creating a partition.<\/li>\n<\/ul>\n<\/li>\n<li>mkpart\n<ul>\n<li>Prompts for the required information (partition name, type, start point, end point or size) and creates a new partition.<\/li>\n<\/ul>\n<\/li>\n<li>quit\n<ul>\n<li>Exits the application.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<p><strong>MKFS<\/strong><\/p>\n<p>Creating a file system (formatting) on a partition.<\/p>\n<p>Once the partition table is created and partitions are defined, each partition needs to be formatted. Formatting creates the chosen file system type on the allocated disk space.<\/p>\n<ul>\n<li>sudo mkfs.ext4 -L &#8220;PartitionLabel&#8221; \/dev\/sdX1\n<ul>\n<li>Formats partition <strong>1<\/strong> on disk <strong>X<\/strong> as <strong>EXT4<\/strong> (recommended) with a label.<\/li>\n<li>The same command structure applies to:\n<ul>\n<li>mkfs.vfat<\/li>\n<li>mkfs.fat (outdated)<\/li>\n<li>mkfs.ntfs (modern Windows partition)<\/li>\n<li>mkfs.ext3 (outdated)<\/li>\n<li>mkfs.ext2 (outdated)<\/li>\n<li>mkfs.bfs<\/li>\n<li>&#8230;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<p><strong>MOUNTING VOLUMES<\/strong><\/p>\n<p>Mounting volumes on boot:<\/p>\n<pre>ls -l \/dev\/disk\/by-uuid\/\r\nsudo nano \/etc\/fstab<\/pre>\n<p>Append a line using one of these formats:<\/p>\n<pre><strong>UUID=0e5accff-ddcb-46ac-bd52-94719086959b<\/strong> \/mounting_point ext4 defaults 0 0\r\n\r\nOR\r\n\r\n<strong>\/dev\/sdb1<\/strong> \/mounting_point ext4 defaults 0 0<\/pre>\n<p>Apply changes without rebooting:<\/p>\n<pre>sudo mount -a<\/pre>\n<hr \/>\n<p><strong>TUNING THE FILESYSTEM<\/strong><\/p>\n<p><code>tune2fs<\/code> allows you to adjust ext2\/ext3\/ext4 filesystem parameters [<a href=\"https:\/\/git.kernel.org\/pub\/scm\/fs\/ext2\/e2fsprogs.git\">Link<\/a>]. It gives Linux administrators control over key parameters that affect the health and reliability of the system.<\/p>\n<ul>\n<li><code>-l<\/code>\n<ul>\n<li>Displays the file system structure and current parameter values.<\/li>\n<\/ul>\n<\/li>\n<li><code>-L<\/code>\n<ul>\n<li>Sets the volume label of the file system.<\/li>\n<\/ul>\n<\/li>\n<li><code>-c<\/code>\n<ul>\n<li>Sets the maximum mount count before the file system is checked for errors.<\/li>\n<\/ul>\n<\/li>\n<li><code>-O<\/code>\n<ul>\n<li>Enables or disables specific file system features.<\/li>\n<\/ul>\n<\/li>\n<li><code>-r<\/code>\n<ul>\n<li>Sets the number of reserved blocks.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>sudo tune2fs -l \/dev\/nvme0n1p1<\/pre>\n<pre>sudo tune2fs -L \"New Label\" \/dev\/nvme0n1p1<\/pre>\n<pre>sudo tune2fs -c 35 \/dev\/nvme0n1p1<\/pre>\n<pre>sudo tune2fs -O dir_index \/dev\/nvme0n1p1<\/pre>\n<pre>sudo tune2fs -r 5 \/dev\/nvme0n1p1<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Checking the drives attached to the Linux server or workstation. mount Shows all mounted partitions. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-2896","post","type-post","status-publish","format-standard","hentry","category-linux","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2896"}],"version-history":[{"count":8,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2896\/revisions"}],"predecessor-version":[{"id":5677,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2896\/revisions\/5677"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}