{"id":86,"date":"2023-07-11T04:29:27","date_gmt":"2023-07-11T04:29:27","guid":{"rendered":"https:\/\/www.beitsahour.net\/?p=86"},"modified":"2023-07-11T04:34:46","modified_gmt":"2023-07-11T04:34:46","slug":"resizing-a-too-small-boot-partition","status":"publish","type":"post","link":"https:\/\/www.beitsahour.net\/index.php\/2023\/07\/11\/04\/29\/resizing-a-too-small-boot-partition\/","title":{"rendered":"Resizing a too small \/boot partition"},"content":{"rendered":"\n\n\n<p>One of my oldest servers has been through many upgrades, from Debian Wheezy (7) all the way through Debian Bookworm (12). Along the way the original 256MiB \/boot partition got a little tight and eventually it got to the point where I could no longer upgrade the kernel.<\/p>\n<p>The system has two boot drives, each with 2 partitions in Linux-MD mirrors, the first partitions for the boot mirror and the 2nd partitions for the OS drive Crypto\/LVM.\u00a0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ fdisk -l \/dev\/sda\nDevice Boot Start End Sectors Size Id Type\n\/dev\/sda1 * 2048 499711 497664 243M fd Linux raid autodetect\n\/dev\/sda2 499712 125044735 124545024 59.4G fd Linux raid autodetect\n\n$ lsblk \/dev\/sda\nNAME                        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS\nsda                           8:0    0  59.6G  0 disk  \n\u251c\u2500sda1                        8:1    0   243M  0 part  \n\u2502 \u2514\u2500md0                       9:0    0 242.8M  0 raid1 \/boot\n\u2514\u2500sda2                        8:2    0  59.4G  0 part  \n  \u2514\u2500md1                       9:1    0  58.4G  0 raid1 \n    \u2514\u2500md1_crypt             253:14   0  58.4G  0 crypt \n      \u251c\u2500stora_vg-root_lv    253:15   0  14.3G  0 lvm   \/\n      \u2514\u2500stora_vg-swap       253:16   0  11.2G  0 lvm   &#91;SWAP]\n\n$ mdadm --detail \/dev\/md1\n\/dev\/md1:\n           Version : 1.2\n     Creation Time : Thu Mar  7 08:29:14 2019\n        Raid Level : raid1\n        Array Size : 61262848 (58.42 GiB 62.73 GB)\n     Used Dev Size : 61262848 (58.42 GiB 62.73 GB)\n      Raid Devices : 2\n     Total Devices : 2\n       Persistence : Superblock is persistent\n\n       Update Time : Mon Jul 10 18:33:08 2023\n             State : clean\n    Active Devices : 2\n   Working Devices : 2\n    Failed Devices : 0 \n     Spare Devices : 0\n\nConsistency Policy : resync\n\n              Name : server:1\n              UUID : 175fc546:57d222bf:b7e667c4:2c489708\n            Events : 1666\n\n    Number   Major   Minor   RaidDevice State\n       0       8        2        0      active sync   \/dev\/sda2\n       1       8       18        1      active sync   \/dev\/sdb2\n\n$ pvs\n  PV                    VG       Fmt  Attr PSize  PFree \n  \/dev\/mapper\/md1_crypt server_vg lvm2 a--  58.42g 32.93g\n\n$ lvs\n  LV      VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert\n  root_lv server_vg -wi-ao----  14.31g                                                    \n  swap    server_vg -wi-ao---- &lt;11.18g\n\n$ cryptsetup status  md1_crypt\n\/dev\/mapper\/md1_crypt is active and is in use.\n  type:    LUKS1\n  cipher:  aes-xts-plain64\n  keysize: 512 bits\n  key location: dm-crypt\n  device:  \/dev\/md1\n  sector size:  512\n  offset:  4096 sectors\n  size:    122521600 sectors\n  mode:    read\/write\n  flags:   discards <\/code><\/pre>\n\n\n\n<p>The end goal of today project was to decrease sda2 and increase sda1, to get there however the all children of sda2 had to be shrunk to allow it to be resized: the crypt container has to be shrunk, then the md has to be shrunk and then the partitions can be recreated. We have enough unused space so we will be subtracting 15GiB or about 31457280(15 * 1024 * 1024 * 2) 512-byte sectors reducing 122521600 to 91064320 512-byte sectors.<\/p>\n<p>The linux-md uses 1024-byte sectors and would\u00a0 be resized from 61262848 down to 45534208.<\/p>\n\n\n\n<pre>$ cryptsetup resize md1_crypt -b 91064320<br \/>$ pvresize \/dev\/mapper\/md1_crypt<br \/>$ mdadm --grow --size=45534208 \/dev\/md1<\/pre>\n\n\n\n<p>Now we will remove the drive partitions from linux-md, re-partition the drives and re-add them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mdadm --fail \/dev\/md1 \/dev\/sda2\n$ mdadm --fail \/dev\/md0 \/dev\/sda1\n$ mdadm --remove \/dev\/md1 \/dev\/sda2\n$ mdadm --remove \/dev\/md0 \/dev\/sda1\n$ wipefs -a \/dev\/sda\n$ fdisk \/dev\/sda\n$ fdisk -l \/dev\/sda\nDevice     Boot   Start       End   Sectors  Size Id Type\n\/dev\/sda1          2048   4196351   4194304    2G fd Linux raid autodetect\n\/dev\/sda2       4196352 125045423 120849072 57.6G fd Linux raid autodetect\n$ mdadm --add \/dev\/md0 \/dev\/sda1\n$ mdadm --add \/dev\/md1 \/dev\/sda2<\/code><\/pre>\n\n\n\n<p>Once re-added and and the linux-md is synced we repeat the process with sdb. Once sdb had the same treatment we can resize the linux-md arrays and children to utilize all the space again<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mdadm --grow \/dev\/md0 -z max\n$ mdadm --grow \/dev\/md1 -z max\n$ resize2fs \/dev\/md0\n$ pvresize \/dev\/mapper\/md1_crypt\n$ cryptsetup resize md1_crypt<\/code><\/pre>\n\n\n\n<p>Finally we need reinstall the boot loader that may have gotten clobbered by the repartitioning<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ grub-install \/dev\/sdb\n$ grub-install \/dev\/sda<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>One of my oldest servers has been through many upgrades, from Debian Wheezy (7) all the way through Debian Bookworm (12). Along the way the original 256MiB \/boot partition got a little tight and eventually it got to the point where I could no longer upgrade the kernel. The system has two boot drives, each [&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":[20,17,19,16,18,21],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cryptsetup","tag-fdisk","tag-linux-md","tag-mdadm","tag-partition","tag-resize"],"_links":{"self":[{"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":4,"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/posts\/86\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.beitsahour.net\/index.php\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}