{"id":1341,"date":"2021-12-23T07:55:25","date_gmt":"2021-12-23T07:55:25","guid":{"rendered":"https:\/\/www.ridiculously-simple.com\/?p=1341"},"modified":"2022-01-02T16:31:04","modified_gmt":"2022-01-02T16:31:04","slug":"shrinking-a-disk-partition-under-debian-11-bullseye","status":"publish","type":"post","link":"https:\/\/www.voodoo.business\/blog\/2021\/12\/23\/shrinking-a-disk-partition-under-debian-11-bullseye\/","title":{"rendered":"Shrinking a disk partition under Debian 11 bullseye"},"content":{"rendered":"\n<p>As usual, I will start by getting to the bottom of it, then explain everything<\/p>\n\n\n\n<p>first, you need to first shrink the file system, then the partition where the filesystem resides, replace \/dev\/sda4 with whatever you partition is named<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1- Shrinking the filesystem<\/h2>\n\n\n\n<p>Unmount the partition to be resized,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">umount \/mountpoint<\/pre>\n\n\n\n<p>otherwise you will get a message such as<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Filesystem at \/dev\/sda4 is mounted on \/mountpoint; on-line resizing required\nOn-line shrinking from 30453104 to 98098 not supported.<\/pre>\n\n\n\n<p>The following commands are relevant to the program  resize2fs, they are hands on examples of use, take a close look at the description of what each does before you proceed by picking how you want to use the command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\n* Show the minimum size we can squeeze this partition to without losing data\nresize2fs -P \/dev\/sda4\n* do the filesystem resize to the MINIMUM possible size (the number you ended up with in the previous command)\nresize2fs -M \/dev\/sda4<\/pre>\n\n\n\n<p>The command above moves all data to the beginning of the filesystem\/drive, then shrinks it to the smallest possible size.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2- Shrinking the partition<\/h2>\n\n\n\n<p>2.1- Find the boundaries of the file system with fdisk<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3- You are DONE<\/h2>\n\n\n\n<p>If this is it, why is there much more in this tutorial, Simply put, what is above does very little explaining, if you want to understand what we did, you will need a bit more<\/p>\n\n\n\n<p>the assumption, I have a partition that only has 5% data, I would like to shrink the partition to ten percent of it&#8217;s size.<\/p>\n\n\n\n<p>Unlike windows, where your luck of where the data resides, you can always shrink a Linux partition to whatever size fits the data that is on it (without losing data)<\/p>\n\n\n\n<p>in this tutorial, I will assume the partition is \/dev\/sda4, you will need to replace that with whatever your partition is.<\/p>\n\n\n\n<p>1- collecting information about our partition<\/p>\n\n\n\n<p>fdisk \/dev\/sda<br>then the p command for print<\/p>\n\n\n\n<p>df -h<br>this should show you all the partitions, info about them and where they are mounted and how much space is used<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>the file system can be shrunk with resize2fs<\/p>\n\n\n\n<p>the command &#8220;resize2fs -M&#8221; should first move the data to the beginning of the drive, then shrink it<\/p>\n\n\n\n<p>first, how large is the file system ATM<br>tune2fs -l \/dev\/sda2 then multiply by block size<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As usual, I will start by getting to the bottom of it, then explain everything first, you need to first shrink the file system, then the partition where the filesystem resides, replace \/dev\/sda4 with whatever you partition is named 1- Shrinking the filesystem Unmount the partition to be resized, umount \/mountpoint otherwise you will get [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1341","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/comments?post=1341"}],"version-history":[{"count":5,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1341\/revisions"}],"predecessor-version":[{"id":1355,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1341\/revisions\/1355"}],"wp:attachment":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/media?parent=1341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/categories?post=1341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/tags?post=1341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}