{"id":867,"date":"2015-08-07T15:04:04","date_gmt":"2015-08-07T22:04:04","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=867"},"modified":"2015-08-07T15:04:04","modified_gmt":"2015-08-07T22:04:04","slug":"linux-partition-howto","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2015\/08\/07\/linux-partition-howto\/","title":{"rendered":"Linux Partition HOWTO"},"content":{"rendered":"<h1 class=\"sect1\">5. Partitioning with fdisk<\/h1>\n<p>This section shows you how to actually partition your hard drive with the <b class=\"command\">fdisk<\/b> utility. Linux allows only 4 primary partitions. You can have a much larger number of logical partitions by sub-dividing one of the primary partitions. Only one of the primary partitions can be sub-divided.<\/p>\n<p><em>Examples:<\/em><\/p>\n<ol type=\"1\">\n<li>Four primary partitions (see <a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/fdisk_partitioning.html#primary-example\">Section 5.2<\/a>)<\/li>\n<li>Mixed primary and logical partitions (see <a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/fdisk_partitioning.html#mixed\">Section 5.3<\/a>)<\/li>\n<\/ol>\n<div class=\"sect2\">\n<h2 class=\"sect2\"><a name=\"fdisk\"><\/a>5.1. fdisk usage<\/h2>\n<p><b class=\"command\">fdisk<\/b> is started by typing (as root) <tt class=\"userinput\"><b><\/b><b class=\"command\">fdisk<\/b> <\/tt><tt class=\"replaceable\"><i>device<\/i><\/tt> at the command prompt. <tt class=\"replaceable\"><i>device<\/i><\/tt> might be something like <tt class=\"filename\">\/dev\/hda<\/tt> or <tt class=\"filename\">\/dev\/sda<\/tt> (see <a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/devices.html#NamingConvention\">Section 2.1.1<\/a>). The basic <b class=\"command\">fdisk<\/b> commands you need are:<\/p>\n<p><tt class=\"userinput\"><b>p<\/b><\/tt> print the partition table<\/p>\n<p><tt class=\"userinput\"><b>n<\/b><\/tt> create a new partition<\/p>\n<p><tt class=\"userinput\"><b>d<\/b><\/tt> delete a partition<\/p>\n<p><tt class=\"userinput\"><b>q<\/b><\/tt> quit without saving changes<\/p>\n<p><tt class=\"userinput\"><b>w<\/b><\/tt> write the new partition table and exit<\/p>\n<p>Changes you make to the partition table do not take effect until you issue the write (w) command. Here is a sample partition table:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Disk \/dev\/hdb: 64 heads, 63 sectors, 621 cylinders\nUnits = cylinders of 4032 * 512 bytes\n \n   Device Boot    Start       End    Blocks   Id  System\n\/dev\/hdb1   *         1       184    370912+  83  Linux\n\/dev\/hdb2           185       368    370944   83  Linux\n\/dev\/hdb3           369       552    370944   83  Linux\n\/dev\/hdb4           553       621    139104   82  Linux swap\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The first line shows the geometry of your hard drive. It may not be physically accurate, but you can accept it as though it were. The hard drive in this example is made of 32 double-sided platters with one head on each side (probably not true). Each platter has 621 concentric tracks. A 3-dimensional track (the same track on all disks) is called a cylinder. Each track is divided into 63 sectors. Each sector contains 512 bytes of data. Therefore the block size in the partition table is 64 heads * 63 sectors * 512 bytes er&#8230;divided by 1024. (See <a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/recovering.html#BlockSize\">4<\/a> for discussion on problems with this calculation.) The start and end values are cylinders.<\/div>\n<div class=\"sect2\">\n<h2 class=\"sect2\"><a name=\"primary-example\"><\/a>5.2. Four primary partitions<\/h2>\n<p><em>The overview:<\/em><\/p>\n<p>Decide on the size of your swap space (see <a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/requirements.html#SwapSize\">Section 4.4<\/a>) and where it ought to go (see <a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/requirements.html#SwapPlacement\">Section 4.4.3<\/a>). Divide up the remaining space for the three other partitions.<\/p>\n<p>Example:<\/p>\n<p>I start fdisk from the shell prompt:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\"># <tt class=\"userinput\"><b><\/b><b class=\"command\">fdisk<\/b> <\/tt><tt class=\"filename\">\/dev\/hdb<\/tt> \n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>which indicates that I am using the second drive on my IDE controller. (See <a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/devices.html#names\">Section 2.1<\/a>.) When I print the (empty) partition table, I just get configuration information.<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Command (m for help): <tt class=\"userinput\"><b>p<\/b><\/tt>\n\nDisk \/dev\/hdb: 64 heads, 63 sectors, 621 cylinders\nUnits = cylinders of 4032 * 512 bytes\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>I knew that I had a 1.2Gb drive, but now I really know: 64 * 63 * 512 * 621 = 1281982464 bytes. I decide to reserve 128Mb of that space for swap, leaving 1153982464. If I use one of my primary partitions for swap, that means I have three left for ext2 partitions. Divided equally, that makes for 384Mb per partition. Now I get to work.<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Command (m for help): <tt class=\"userinput\"><b>n<\/b><\/tt>\nCommand action\n   e   extended\n   p   primary partition (1-4)\n<tt class=\"userinput\"><b>p<\/b><\/tt>\nPartition number (1-4): <tt class=\"userinput\"><b>1<\/b><\/tt>\nFirst cylinder (1-621, default 1):<tt class=\"userinput\"><b>&lt;RETURN&gt;<\/b><\/tt>\nUsing default value 1\nLast cylinder or +size or +sizeM or +sizeK (1-621, default 621): <tt class=\"userinput\"><b>+384M<\/b><\/tt>\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Next, I set up the partition I want to use for swap:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Command (m for help): <tt class=\"userinput\"><b>n<\/b><\/tt>\nCommand action\n   e   extended\n   p   primary partition (1-4)\np\nPartition number (1-4): <tt class=\"userinput\"><b>2<\/b><\/tt>\nFirst cylinder (197-621, default 197):<tt class=\"userinput\"><b>&lt;RETURN&gt;<\/b><\/tt>\nUsing default value 197\nLast cylinder or +size or +sizeM or +sizeK (197-621, default 621): <tt class=\"userinput\"><b>+128M<\/b><\/tt>\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Now the partition table looks like this:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">   Device Boot    Start       End    Blocks   Id  System\n\/dev\/hdb1             1       196    395104   83  Linux\n\/dev\/hdb2           197       262    133056   83  Linux\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>I set up the remaining two partitions the same way I did the first. Finally, I make the first partition bootable:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Command (m for help): <tt class=\"userinput\"><b>a<\/b><\/tt>\nPartition number (1-4): <tt class=\"userinput\"><b>1<\/b><\/tt>\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>And I make the second partition of type swap:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Command (m for help): <tt class=\"userinput\"><b>t<\/b><\/tt>\nPartition number (1-4): <tt class=\"userinput\"><b>2<\/b><\/tt>\nHex code (type L to list codes): <tt class=\"userinput\"><b>82<\/b><\/tt>\nChanged system type of partition 2 to 82 (Linux swap)      \nCommand (m for help): <tt class=\"userinput\"><b>p<\/b><\/tt>\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The end result:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Disk \/dev\/hdb: 64 heads, 63 sectors, 621 cylinders\nUnits = cylinders of 4032 * 512 bytes\n \n   Device Boot    Start       End    Blocks   Id  System\n\/dev\/hdb1   *         1       196    395104+  83  Linux\n\/dev\/hdb2           197       262    133056   82  Linux swap\n\/dev\/hdb3           263       458    395136   83  Linux\n\/dev\/hdb4           459       621    328608   83  Linux          \n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Finally, I issue the write command (w) to write the table on the disk.Side topics:<\/p>\n<ul>\n<li><a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/appendix.html#swap\">Section 10.2<\/a><\/li>\n<li><a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/appendix.html#formating\">Section 10.1<\/a><\/li>\n<li><a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/appendix.html#mounting\">Section 10.3<\/a><\/li>\n<\/ul>\n<\/div>\n<div class=\"sect2\">\n<h2 class=\"sect2\"><a name=\"mixed\"><\/a>5.3. Mixed primary and logical partitions<\/h2>\n<p><em>The overview:<\/em> create one use one of the primary partitions to house all the extra partitions. Then create logical partitions within it. Create the other primary partitions before or after creating the logical partitions.<\/p>\n<p>Example:<\/p>\n<p>I start fdisk from the shell prompt:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\"># fdisk \/dev\/sda\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>which indicates that I am using the first drive on my SCSI chain. (See <a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/devices.html#names\">Section 2.1<\/a>.)First I figure out how many partitions I want. I know my drive has a 183Gb capacity and I want 26Gb partitions (because I happen to have back-up tapes that are about that size).<\/p>\n<p><tt class=\"literal\">183Gb \/ 26Gb = ~7<\/tt><\/p>\n<p>so I will need 7 partitions. Even though fdisk accepts partition sizes expressed in Mb and Kb, I decide to calculate the number of cylinders that will end up in each partition because fdisk reports start and stop points in cylinders. I see when I enter fdisk that I have 22800 cylinders.<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">&gt; The number of cylinders for this disk is set to 22800.  There is\n&gt; nothing wrong with that, but this is larger than 1024, and could in\n&gt; certain setups cause problems with: 1) software that runs at boot\n&gt; time (e.g., LILO) 2) booting and partitioning software from other\n&gt; OSs  (e.g., DOS FDISK, OS\/2 FDISK)\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>So, 22800 total cylinders divided by seven partitions is 3258 cylinders. Each partition will be about 3258 cylinders long. I ignore the warning msg because this is not my boot drive (<a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/requirements.html\">Section 4<\/a>).Since I have 4 primary partitions, 3 of them can be 3258 long. The extended partition will have to be (4 * 3258), or 13032, cylinders long in order to contain the 4 logical partitions.<\/p>\n<p>I enter the following commands to set up the first of the 3 primary partitions (stuff I type is bold ):<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Command (m for help): <tt class=\"userinput\"><b>n<\/b><\/tt>\nCommand action\n   e   extended\n   p   primary partition (1-4)\n<tt class=\"userinput\"><b>p<\/b><\/tt>\nPartition number (1-4): <tt class=\"userinput\"><b>1<\/b><\/tt>\nFirst cylinder (1-22800, default 1): <tt class=\"userinput\"><b>&lt;RETURN&gt;<\/b><\/tt>\nUsing default value 1\nLast cylinder or +size or +sizeM or +sizeK (1-22800, default 22800): <tt class=\"userinput\"><b>3258<\/b><\/tt>\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The last partition is the extended partition:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Partition number (1-4): <tt class=\"userinput\"><b>4<\/b><\/tt>\nFirst cylinder (9775-22800, default 9775): <tt class=\"userinput\"><b>&lt;RETURN&gt;<\/b><\/tt>\nUsing default value 9775\nLast cylinder or +size or +sizeM or +sizeK (9775-22800, default 22800): <tt class=\"userinput\"><b>&lt;RETURN&gt;<\/b><\/tt>\nUsing default value 22800\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The result, when I issue the print table command is:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">\/dev\/sda1             1      3258  26169853+  83  Linux\n\/dev\/sda2          3259      6516  26169885   83  Linux\n\/dev\/sda3          6517      9774  26169885   83  Linux\n\/dev\/sda4          9775     22800 104631345    5  Extended\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Next I segment the extended partition into 4 logical partitions, starting with the first logical partition, into 3258-cylinder segments. The logical partitions automatically start from \/dev\/sda5.<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">Command (m for help):  <tt class=\"userinput\"><b>n<\/b><\/tt>\nFirst cylinder (9775-22800, default 9775): <tt class=\"userinput\"><b>&lt;RETURN&gt;<\/b><\/tt>\nUsing default value 9775\nLast cylinder or +size or +sizeM or +sizeK (9775-22800, default 22800): 13032\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The end result is:<\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre class=\"programlisting\">   Device Boot    Start       End    Blocks   Id  System\n\/dev\/sda1             1      3258  26169853+  83  Linux\n\/dev\/sda2          3259      6516  26169885   83  Linux\n\/dev\/sda3          6517      9774  26169885   83  Linux\n\/dev\/sda4          9775     22800 104631345    5  Extended\n\/dev\/sda5          9775     13032  26169853+  83  Linux\n\/dev\/sda6         13033     16290  26169853+  83  Linux\n\/dev\/sda7         16291     19584  26459023+  83  Linux\n\/dev\/sda8         19585     22800  25832488+  83  Linux\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Finally, I issue the write command (w) to write the table on the disk. To make the partitions usable, I will have to format (<a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/appendix.html#formating\">Section 10.1<\/a>) each partition and then mount (<a href=\"http:\/\/tldp.org\/HOWTO\/Partition\/appendix.html#mounting\">Section 10.3<\/a>) it.<\/div>\n<div class=\"sect2\">\n<h2 class=\"sect2\"><a name=\"submitted\"><\/a>5.4. Submitted Examples<\/h2>\n<p>I&#8217;d like to submit my partition layout, because it works well with any distribution of Linux (even big RPM based ones). I have one hard drive that &#8230; is 10 gigs, exactly. Windows can&#8217;t see above 9.3 gigs of it, but Linux can see it all, and use it all. It also has much more than 1024 cylenders.<\/p>\n<div class=\"table\"><a name=\"AEN711\"><\/a><b>Table 7. Partition layout example<\/b><\/p>\n<table class=\"CALSTABLE\" border=\"1\">\n<thead>\n<tr>\n<th align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">Partition<\/th>\n<th align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">Mount point<\/th>\n<th align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">Size<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/dev\/hda1<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/boot<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">(15 megs)<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/dev\/hda2<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">windows 98 partition<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">(2 gigs)<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/dev\/hda3<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">extended<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">(N\/A)<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/dev\/hda5<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">swap space<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">(64 megs)<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/dev\/hda6<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/tmp<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">(50 megs)<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/dev\/hda7<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">(150 megs)<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/dev\/hda8<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/usr<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">(1.5 gigs)<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/dev\/hda9<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">\/home<\/td>\n<td align=\"LEFT\" valign=\"MIDDLE\" width=\"33%\">(rest of drive)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>I test new kernels for the USB mass storage, so that explains the large \/boot partition. I install LILO into the MBR, and by default I boot windows (I&#8217;m not the only one to use this computer).I also noticed that you don&#8217;t have any REAL examples of partition tables, and for newbies I HIGHLY suggest putting quite a few up. I&#8217;m freshly out of the newbie stage, and partitioning was what messed me up the most.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>5. Partitioning with fdisk This section shows you how to actually partition your hard drive with the fdisk utility. Linux allows only 4 primary partitions.&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-867","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=867"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/867\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}