327 lines
17 KiB
HTML
327 lines
17 KiB
HTML
<!DOCTYPE html>
|
||
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
||
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
|
||
<link rel="canonical" href="https://blog.trentsonlinedocs.xyz/posts/faster-partitioning-with-sgdisk/">
|
||
<link rel="shortcut icon" href="../../img/favicon.ico">
|
||
<title>Faster Partitioning With sgdisk - Trent's Blog</title>
|
||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />
|
||
|
||
<link rel="stylesheet" href="../../css/theme.css" />
|
||
<link rel="stylesheet" href="../../css/theme_extra.css" />
|
||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css" />
|
||
<link href="../../extra.css" rel="stylesheet" />
|
||
|
||
<script>
|
||
// Current page data
|
||
var mkdocs_page_name = "Faster Partitioning With sgdisk";
|
||
var mkdocs_page_input_path = "posts/faster-partitioning-with-sgdisk.md";
|
||
var mkdocs_page_url = "/posts/faster-partitioning-with-sgdisk/";
|
||
</script>
|
||
|
||
<script src="../../js/jquery-2.1.1.min.js" defer></script>
|
||
<script src="../../js/modernizr-2.8.3.min.js" defer></script>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
|
||
<script>hljs.initHighlightingOnLoad();</script>
|
||
</head>
|
||
|
||
<body class="wy-body-for-nav" role="document">
|
||
|
||
<div class="wy-grid-for-nav">
|
||
|
||
|
||
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
|
||
<div class="wy-side-scroll">
|
||
<div class="wy-side-nav-search">
|
||
<a href="../.." class="icon icon-home"> Trent's Blog</a>
|
||
<div role="search">
|
||
<form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get">
|
||
<input type="text" name="q" placeholder="Search docs" title="Type search term here" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
||
<p class="caption"><span class="caption-text">RSS</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../rss/">RSS</a>
|
||
</li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">Links</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../links/">Links</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://trentpalmer.org">TrentReads</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://blog.trentpalmer.org">AttentionSpanHistory</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://github.com/TrentSPalmer">GitHub</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://twitter.com/boringtrent">Twitter</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://www.facebook.com/trentspalmer">Facebook</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://docs.trentsonlinedocs.xyz/">TrentDocs</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://trentsonlinedocs.xyz/hugo-themes-report/hugo-themes-report.html">HugoThemesReport</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://play.google.com/store/apps/details?id=org.trentpalmer.libre_gps_parser">LibreGpsParser</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://concise-pdx.com/">ConcisePDX</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://trentspalmer.github.io/fcc-challenges/">FreeCodeCampChallenges</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="" href="https://trentpalmer.work/6a57bbe24d8244289610bf57533d6c6f/">DeviceLayout</a>
|
||
</li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">Posts</span></p>
|
||
<ul class="current">
|
||
<li class="toctree-l1"><a class="reference internal" href="../trents-favorite-podcasts/">Trent's Favorite Podcasts</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../test-qr-svg-django/">Test QRCODE Svg in Django</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../prosody-photo-uploads/">Prosody Photo Uploads</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../xmpp-apt-notifications/">Xmpp Apt Notifications</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../apache-virtual-hosts/">Apache Virtual Hosts</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../sendxmpp-handler-for-python-logging/">SENDXMPPHandler for Python Logging</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../instructions-for-tethering-from-phone/">Instructions For Tethering From Phone</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../lmde4-custom-partitions-disk-encryption/">LMDE4 Custom Partitions Disk Encryption</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../linux-move-cursor-with-keyboard/">Linux Move Cursor With Keyboard</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../simplified-raspberry-streaming/">Simplified Raspberry Streaming</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../clear-linux-encrypted-xfs-root/">Clear Linux Encrypted xfs Root</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../clear-linux-guest-virt-manager/">Clear Linux Guest Virt Manager</a>
|
||
</li>
|
||
<li class="toctree-l1 current"><a class="reference internal current" href="./">Faster Partitioning With sgdisk</a>
|
||
<ul class="current">
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../lmde3-xfs-full-disk-encryption/">LMDE3 xfs Full Disk Encryption</a>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../rewrite-hugo-themes-report-in-python/">Rewrite Hugo Themes Report in Python</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||
|
||
|
||
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
<a href="../..">Trent's Blog</a>
|
||
</nav>
|
||
|
||
|
||
<div class="wy-nav-content">
|
||
<div class="rst-content">
|
||
<div role="navigation" aria-label="breadcrumbs navigation">
|
||
<ul class="wy-breadcrumbs">
|
||
<li><a href="../..">Docs</a> »</li>
|
||
|
||
|
||
|
||
<li>Posts »</li>
|
||
|
||
|
||
|
||
<li>Faster Partitioning With sgdisk</li>
|
||
<li class="wy-breadcrumbs-aside">
|
||
|
||
</li>
|
||
</ul>
|
||
|
||
<hr/>
|
||
</div>
|
||
|
||
<div role="main">
|
||
<div class="section">
|
||
|
||
<p>date: 2019-02-11T04:23:52-08:00</p>
|
||
<h2 id="disclaimer"><strong>Disclaimer</strong></h2>
|
||
<p>If any of this is wrong, let me know so I can fix it. No actual hard drives were harmed in the production of this blog post.</p>
|
||
<p>The examples are easier to read if you turn your smart phone sideways.</p>
|
||
<h2 id="command-line-is-faster"><strong>Command Line Is Faster</strong></h2>
|
||
<p>Sure you can partition your discs using a GUI disk management application or an interactive,
|
||
menu-driven terminal interface. But the command line is faster.</p>
|
||
<h2 id="gdisk-vs-sgdisk"><strong>gdisk vs sgdisk</strong></h2>
|
||
<p><code>sgdisk</code> is the scriptable version of <code>gdisk</code> (gptfdisk).</p>
|
||
<h2 id="what-the-manpage-says"><strong><a href="https://manpages.debian.org/stretch/gdisk/sgdisk.8.en.html" target="_blank">what the manpage says</a></strong></h2>
|
||
<p>If you’re familiar with <code>gdisk</code>, you probably know how to interactively set the partition size and type.
|
||
If you look at the man page for <code>sgdisk</code> you see that the relevant flags are <code>-n</code> and <code>-t</code>. The beginning and ending numbers
|
||
are absolute, unless you prepend them with a <code>+</code> or <code>-</code> sign, in which case they become relative.
|
||
<div class="highlight"><pre><span></span><code><span class="gp"># </span>For New Partition:
|
||
<span class="go">-n, --new=partnum:start:end</span>
|
||
</code></pre></div>
|
||
<div class="highlight"><pre><span></span><code><span class="gp"># </span>Change partition type:
|
||
<span class="go">-t, --typecode=partnum:{hexcode|GUID}</span>
|
||
</code></pre></div></p>
|
||
<h2 id="example-with-separate-efi-and-partitions"><strong>Example with Separate EFI and / Partitions</strong></h2>
|
||
<p>BTW, <code>gdisk</code> is a partitioning tool intended to be used with a gpt partition table, so the assumption is that you would want an efi partition,</p>
|
||
<p>(although the efi partition does not have to be on the disk you are partitioning or even on the same disk where your other system partitions are).</p>
|
||
<ol>
|
||
<li>Wipe any leftover filesystem metadata with wipefs.
|
||
<div class="highlight"><pre><span></span><code><span class="go">wipefs --all /dev/sdx</span>
|
||
</code></pre></div></li>
|
||
<li>Create a new GPT partition table.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -o</span>
|
||
</code></pre></div></li>
|
||
<li>Create an efi partition of 512MB by specifying the end of the partition (relative) and the partition type, <code>ef00</code>.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 1::+512MiB -t 1:ef00</span>
|
||
</code></pre></div></li>
|
||
<li>Create an <code>/</code> partition using the remainder of the disk, by not specifying the end or the beginning or partition type, which defaults to 8300.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 2</span>
|
||
</code></pre></div></li>
|
||
<li>Format the efi partition fat 32.
|
||
<div class="highlight"><pre><span></span><code><span class="go">mkfs.vfat -F32 /dev/sdx1</span>
|
||
</code></pre></div></li>
|
||
<li>Format the <code>/</code> partition ext4.
|
||
<div class="highlight"><pre><span></span><code><span class="go">mkfs.ext4 /dev/sdx2</span>
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h2 id="practice-with-a-sparse-image"><strong>Practice With A Sparse Image</strong></h2>
|
||
<p>If you don’t want to partition a real hard drive, you can practice using an sparse image file, instead.
|
||
<div class="highlight"><pre><span></span><code><span class="gp"># </span>create a sparse image file
|
||
<span class="go">truncate -S 100G practiceImage.img</span>
|
||
<span class="gp"># </span>partition the image file with sgdisk
|
||
<span class="go">sgdisk practiceImage.img -o</span>
|
||
<span class="gp"># </span>etc
|
||
</code></pre></div></p>
|
||
<h2 id="example-with-separate-boot-efi-and-luks-encrypted-partitions"><strong>Example with Separate /boot, EFI, and luks-encrypted / Partitions</strong></h2>
|
||
<ol>
|
||
<li>Wipe any leftover filesystem metadata with <code>wipefs</code>.
|
||
<div class="highlight"><pre><span></span><code><span class="go">wipefs --all /dev/sdx</span>
|
||
</code></pre></div></li>
|
||
<li>Create a new GPT partition table.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -o</span>
|
||
</code></pre></div></li>
|
||
<li>Create an efi partition of 512MB by specifying the end of the partition (relative) and the partition type, <code>ef00</code>.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 1::+512MiB -t 1:ef00</span>
|
||
</code></pre></div></li>
|
||
<li>Create a <code>/boot</code> partition of 1GB, by specifying the end of the partition (relative), but not specifying the partition type which defaults to <code>8300</code>.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 2::+1GiB</span>
|
||
</code></pre></div></li>
|
||
<li>Create an <code>/</code> partition using the remainder of the disk, by not specifying the end or the beginning or partition type, which defaults to <code>8300</code>.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 3</span>
|
||
</code></pre></div></li>
|
||
<li>Format the efi partition fat 32.
|
||
<div class="highlight"><pre><span></span><code><span class="go">mkfs.vfat -F32 /dev/sdx1</span>
|
||
</code></pre></div></li>
|
||
<li>Format the <code>/boot</code> partition ext4.
|
||
<div class="highlight"><pre><span></span><code><span class="go">mkfs.ext4 /dev/sdx2</span>
|
||
</code></pre></div></li>
|
||
<li>Encrypt the <code>/</code> partition.
|
||
<div class="highlight"><pre><span></span><code><span class="go">cryptsetup -y -v luksFormat --type luks2 /dev/sdx3</span>
|
||
</code></pre></div></li>
|
||
<li>Decrypt the <code>/</code> device.
|
||
<div class="highlight"><pre><span></span><code><span class="go">cryptsetup open /dev/sdx3 cryptroot</span>
|
||
</code></pre></div></li>
|
||
<li>Format the <code>/</code> device.
|
||
<div class="highlight"><pre><span></span><code><span class="go">mkfs.xfs /dev/mapper/cryptroot</span>
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h2 id="what-about-swap"><strong>What About Swap?</strong></h2>
|
||
<p>I prefer to use a swap file inside the luks-encrypted / partition. But you can make a separate swap partition if you like.</p>
|
||
<h2 id="example-with-2gb-swap-partition"><strong>Example with 2GB swap partition</strong></h2>
|
||
<ol>
|
||
<li>Wipe the disc.
|
||
<div class="highlight"><pre><span></span><code><span class="go">wipefs --all /dev/sdx</span>
|
||
</code></pre></div></li>
|
||
<li>Create a new GPT partition table.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -o</span>
|
||
</code></pre></div></li>
|
||
<li>Create an EFI partition.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 1::+512MiB -t 1:ef00</span>
|
||
</code></pre></div></li>
|
||
<li>Create a <code>/boot</code> partition.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 2::+1GiB</span>
|
||
</code></pre></div></li>
|
||
<li>Create a <code>/</code> partition with a relative negative end.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 3::-2GiB</span>
|
||
</code></pre></div></li>
|
||
<li>Create a swap partion type <code>8200</code>.
|
||
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 4 -t 4:8200</span>
|
||
</code></pre></div></li>
|
||
<li>format the partitions.
|
||
<div class="highlight"><pre><span></span><code><span class="go">mkfs.vfat -F32 /dev/sdx1</span>
|
||
<span class="go">mkfs.ext4 /dev/sdx2</span>
|
||
<span class="go">mkfs.xfs /dev/sdx3</span>
|
||
<span class="go">mkswap /dev/sdx4</span>
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h2 id="conclusion"><strong>Conclusion</strong></h2>
|
||
<ul>
|
||
<li>Good luck to you.</li>
|
||
<li>Backup your data first.</li>
|
||
<li>Kind Regards, Trent</li>
|
||
</ul>
|
||
|
||
</div>
|
||
</div>
|
||
<footer>
|
||
|
||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||
|
||
<a href="../lmde3-xfs-full-disk-encryption/" class="btn btn-neutral float-right" title="LMDE3 xfs Full Disk Encryption">Next <span class="icon icon-circle-arrow-right"></span></a>
|
||
|
||
|
||
<a href="../clear-linux-guest-virt-manager/" class="btn btn-neutral" title="Clear Linux Guest Virt Manager"><span class="icon icon-circle-arrow-left"></span> Previous</a>
|
||
|
||
</div>
|
||
|
||
|
||
<hr/>
|
||
|
||
<div role="contentinfo">
|
||
<!-- Copyright etc -->
|
||
|
||
</div>
|
||
|
||
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
||
</footer>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
</section>
|
||
|
||
</div>
|
||
|
||
<div class="rst-versions" role="note" aria-label="versions">
|
||
<span class="rst-current-version" data-toggle="rst-current-version">
|
||
|
||
|
||
<span><a href="../clear-linux-guest-virt-manager/" style="color: #fcfcfc">« Previous</a></span>
|
||
|
||
|
||
<span><a href="../lmde3-xfs-full-disk-encryption/" style="color: #fcfcfc">Next »</a></span>
|
||
|
||
</span>
|
||
</div>
|
||
<script>var base_url = '../..';</script>
|
||
<script src="../../js/theme_extra.js" defer></script>
|
||
<script src="../../js/theme.js" defer></script>
|
||
<script src="../../search/main.js" defer></script>
|
||
<script defer>
|
||
window.onload = function () {
|
||
SphinxRtdTheme.Navigation.enable(true);
|
||
};
|
||
</script>
|
||
|
||
</body>
|
||
</html>
|