{"id":2896,"date":"2022-05-21T01:21:45","date_gmt":"2022-05-21T01:21:45","guid":{"rendered":"https:\/\/dft.wiki\/?p=2896"},"modified":"2025-11-29T13:06:34","modified_gmt":"2025-11-29T18:06:34","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 contains much more than the physical or virtual volumes. It also lists the 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 respective mounting 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&#8230;<\/li>\n<\/ul>\n<\/li>\n<li>sudo disktype \/dev\/sdX\n<ul>\n<li>show detailed information about a disk and its partition.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<p><strong>FDISK<\/strong><\/p>\n<p>Popular commands for the interactive mode:<\/p>\n<ul>\n<li>sudo fdisk \/dev\/sd<strong>X<\/strong>\n<ul>\n<li>replace <strong>X<\/strong> by the letter of disk as the kernel identifies the volume at that time.<\/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 to inform each one.<\/li>\n<li>if only one it will assume and auto select that one.<\/li>\n<\/ol>\n<\/li>\n<li><strong>n<\/strong>\n<ol>\n<li>creates a new partition. It will ask for the type of partition desired: extended or primary (up to 4).<\/li>\n<li>next it will ask where the partition will start (what cylinder number) and how bit it will be (in KB, MB, GB or the last 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 the blocks of non-allocated space.<\/li>\n<\/ol>\n<\/li>\n<li><strong>g<\/strong>\n<ol>\n<li>wipes the whole drive and creates a new GPT partition table (the recommended type).<\/li>\n<\/ol>\n<\/li>\n<li><strong>o<\/strong>\n<ol>\n<li>wipes the whole 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>will write all the changes to the dist and quit.<\/li>\n<\/ol>\n<\/li>\n<li><strong>q<\/strong>\n<ol>\n<li>quits without saving any change to the disk.<\/li>\n<\/ol>\n<\/li>\n<li><strong>e<\/strong>\n<ol>\n<li>enters the 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>The application fdisk is also capable of execute changes to the disk in a non-interactive mode programmatically via scripts or commands as needed. See documentation for additional information. Search for sfdisk script files in the manual. See examples:<\/p>\n<ul>\n<li><strong>sudo fdisk -l<\/strong>\n<ul>\n<li>will list all the disks attached to the system.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<p><strong>CFDISK<\/strong><\/p>\n<p>It does the same thing as the fdisk but with an interactive interface that reminds a graphical interface and allows navigation over the partitions and menu options using the arrow keys or using short keys to speed up.<\/p>\n<ul>\n<li>sudo cfdisk \/dev\/sd<strong>X<\/strong>\n<ul>\n<li>opens the application on the 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 that has a graphical version called <strong>gparted<\/strong> (default in most distributions that use GNOME).<\/p>\n<p><strong>Important:<\/strong> there is no additional command to write the changes to the disk. It writes as you go.<\/p>\n<ul>\n<li>sudo parted \/dev\/sd<strong>X<\/strong>\n<ul>\n<li>opens the application to edit the disk <strong>X<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<li>sudo parted\n<ul>\n<li>opens the application with out defining the disk to be edited.<\/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>defines what disk to be edited.<\/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>show instruction and options for the command mklabel.<\/li>\n<\/ul>\n<\/li>\n<li>mklabel gpt\n<ul>\n<li>creates a GPT partition table on the disk (caution: it wipes the whole 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 necessary information (partition name, type, starting point, ending 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>After the partitions table is created and the partitions allocate chunks of the available disk sectors, each partition needs to be &#8220;formatted&#8221;.<\/p>\n<p>Formatting is the process of creating the respective 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 the partition number <strong>1<\/strong> of the disk <strong>X<\/strong> as <strong>EXT4<\/strong> format (recommended) with a label.<\/li>\n<li>same for:\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 the boot:<\/p>\n<pre>ls -l \/dev\/disk\/by-uuid\/\r\nsudo nano \/etc\/fstab<\/pre>\n<p>Append a line according to the examples:<\/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 restarting:<\/p>\n<pre>sudo mount -a<\/pre>\n<hr \/>\n<p><strong>TUNNING FILESYSTEM<\/strong><\/p>\n<p><code>tune2fs<\/code> is the tool that allows one to make adjustments to ext2\/ext3\/ext4 filesystem parameters [<a href=\"https:\/\/git.kernel.org\/pub\/scm\/fs\/ext2\/e2fsprogs.git\">Link<\/a>]. It empowers Linux administrators to fine-tune high-importance parameters for the health and resiliency of the whole system.<\/p>\n<ul>\n<li><code>-l<\/code>\n<ul>\n<li>This displays the file structure and current values of the parameters.<\/li>\n<\/ul>\n<\/li>\n<li>\u00a0<code>-L<\/code>\n<ul>\n<li>Used to set the Volume Label of the file system.<\/li>\n<\/ul>\n<\/li>\n<li>\u00a0<code>-c<\/code>\n<ul>\n<li>This option sets the maximum mount count before it is checked for errors.<\/li>\n<\/ul>\n<\/li>\n<li>\u00a0<code>-O<\/code>\n<ul>\n<li>You can enable or disable specific features using this option.<\/li>\n<\/ul>\n<\/li>\n<li>\u00a0<code>-r<\/code>\n<ul>\n<li>Used to set the reserved block.<\/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":7,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2896\/revisions"}],"predecessor-version":[{"id":5179,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2896\/revisions\/5179"}],"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}]}}