225 lines
7.1 KiB
HTML
225 lines
7.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
|
|
<meta http-equiv="X-Content-Type-Options" content="nosniff">
|
|
<link rel="stylesheet" href="../assets/css/style.css">
|
|
<link rel="icon" type="image/x-icon" href="../favicon.ico">
|
|
<script>
|
|
// Apply theme immediately to prevent flash
|
|
(function() {
|
|
const theme = localStorage.getItem('theme') ||
|
|
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
})();
|
|
</script>
|
|
<title>fdisk Cheatsheet - Cheatsheets - Launch Pad</title>
|
|
</head>
|
|
<body>
|
|
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
|
|
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
|
|
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
|
|
</button>
|
|
<br/><br/>
|
|
<div class="name">
|
|
__ _______________________ _________._________________________
|
|
\_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/
|
|
| __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_
|
|
| \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \
|
|
\___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ /
|
|
\/ \/ \/ \/ \/ \/ \/
|
|
</div>
|
|
<div class="blog-page-header">
|
|
<div class="blog-header-content">
|
|
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
|
|
</a>
|
|
<h1 class="blog-page-title">fdisk Cheatsheet</h1>
|
|
</div>
|
|
</div>
|
|
<div class="blog-post-container">
|
|
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
|
|
<div class="blog-post">
|
|
<div class="blog-post-content">
|
|
<p><a href="index.html">← Back to cheatsheets</a></p>
|
|
<p><a href="../index.html">← Home</a></p>
|
|
<hr>
|
|
<p>fdisk is a command-line utility for disk partitioning. Used to create, delete, and manage partitions on storage devices.</p>
|
|
<hr>
|
|
<h2>Basic Usage</h2>
|
|
<ul>
|
|
<li>fdisk -l - List all partitions on all disks</li>
|
|
</ul>
|
|
<ul>
|
|
<li>fdisk -l /dev/sda - List partitions on specific disk</li>
|
|
</ul>
|
|
<ul>
|
|
<li>sudo fdisk /dev/sda - Open fdisk for disk (interactive mode)</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Interactive Commands</h2>
|
|
<p>Once in fdisk (type `m` for menu):</p>
|
|
<ul>
|
|
<li>p - Print partition table</li>
|
|
</ul>
|
|
<ul>
|
|
<li>n - Create new partition</li>
|
|
</ul>
|
|
<ul>
|
|
<li>d - Delete partition</li>
|
|
</ul>
|
|
<ul>
|
|
<li>t - Change partition type</li>
|
|
</ul>
|
|
<ul>
|
|
<li>w - Write changes and exit</li>
|
|
</ul>
|
|
<ul>
|
|
<li>q - Quit without saving</li>
|
|
</ul>
|
|
<ul>
|
|
<li>l - List known partition types</li>
|
|
</ul>
|
|
<ul>
|
|
<li>v - Verify partition table</li>
|
|
</ul>
|
|
<ul>
|
|
<li>u - Change units (sectors/cylinders)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>m - Print menu</li>
|
|
</ul>
|
|
<ul>
|
|
<li>a - Toggle bootable flag</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Operations</h2>
|
|
<h3>Create New Partition</h3>
|
|
<ol>
|
|
<li>`sudo fdisk /dev/sda`</li>
|
|
<li>`n` - New partition</li>
|
|
<li>`p` - Primary partition (or `e` for extended)</li>
|
|
<li>Choose partition number (1-4)</li>
|
|
<li>Enter first sector (default is fine)</li>
|
|
<li>Enter last sector or size (e.g., `+10G` for 10GB)</li>
|
|
<li>`w` - Write changes</li>
|
|
</ol>
|
|
<h3>Delete Partition</h3>
|
|
<ol>
|
|
<li>`sudo fdisk /dev/sda`</li>
|
|
<li>`p` - View partitions</li>
|
|
<li>`d` - Delete partition</li>
|
|
<li>Select partition number</li>
|
|
<li>`w` - Write changes</li>
|
|
</ol>
|
|
<h3>Change Partition Type</h3>
|
|
<ol>
|
|
<li>`sudo fdisk /dev/sda`</li>
|
|
<li>`t` - Change type</li>
|
|
<li>Select partition</li>
|
|
<li>Enter type code (e.g., `83` for Linux, `82` for swap)</li>
|
|
<li>`w` - Write changes</li>
|
|
</ol>
|
|
<hr>
|
|
<h2>Partition Type Codes</h2>
|
|
<ul>
|
|
<li>82 - Linux swap</li>
|
|
</ul>
|
|
<ul>
|
|
<li>83 - Linux filesystem</li>
|
|
</ul>
|
|
<ul>
|
|
<li>85 - Linux extended</li>
|
|
</ul>
|
|
<ul>
|
|
<li>8e - Linux LVM</li>
|
|
</ul>
|
|
<ul>
|
|
<li>ef - EFI system partition</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use `l` in fdisk to see full list</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>After Partitioning</h2>
|
|
<p>After creating partitions, you may need to:</p>
|
|
<ul>
|
|
<li>`partprobe` - Inform OS of partition table changes</li>
|
|
</ul>
|
|
<ul>
|
|
<li>`mkfs.ext4 /dev/sda1` - Format partition as ext4</li>
|
|
</ul>
|
|
<ul>
|
|
<li>`mount /dev/sda1 /mnt` - Mount partition</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Add to `/etc/fstab` for permanent mounting</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Related Commands</h2>
|
|
<ul>
|
|
<li>`lsblk` - List block devices in tree format</li>
|
|
</ul>
|
|
<ul>
|
|
<li>`blkid` - Show block device attributes</li>
|
|
</ul>
|
|
<ul>
|
|
<li>`parted` - Alternative partitioning tool (GPT support)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>`cfdisk` - Curses-based disk partitioner</li>
|
|
</ul>
|
|
<ul>
|
|
<li>`gdisk` - GPT fdisk (for GPT partition tables)</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Configuration</h2>
|
|
<h3>Config File Location</h3>
|
|
<ul>
|
|
<li>`/etc/fstab` - File system table (mount points)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>`/proc/partitions` - Current partition information</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Tips</h2>
|
|
<ul>
|
|
<li>Always use `-l` to list first before making changes</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Write changes (`w`) only when you're sure</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use `q` to quit without saving if you make a mistake</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Backup important data before partitioning</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use `partprobe` or reboot after partitioning</li>
|
|
</ul>
|
|
<ul>
|
|
<li>For GPT disks, use `gdisk` instead of `fdisk`</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Be very careful - partitioning can destroy data</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Test changes on non-critical systems first</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use `cfdisk` for easier interactive interface</li>
|
|
</ul>
|
|
<hr>
|
|
<p><a href="index.html">← Back to cheatsheets</a></p>
|
|
<p><a href="../index.html">← Home</a></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script async type="text/javascript" src="../blog/analytics.js"></script>
|
|
<script src="../theme.js"></script>
|
|
</body>
|
|
</html> |