{"id":1062,"date":"2019-02-15T11:23:13","date_gmt":"2019-02-15T08:23:13","guid":{"rendered":"https:\/\/oss-it.su\/?p=1062"},"modified":"2021-04-25T10:43:11","modified_gmt":"2021-04-25T07:43:11","slug":"%d0%b8%d0%b7%d0%bc%d0%b5%d0%bd%d0%b5%d0%bd%d0%b8%d0%b5-%d1%80%d0%b0%d0%b7%d0%bc%d0%b5%d1%80%d0%be%d0%b2-%d1%80%d0%b0%d0%b1%d0%be%d1%82%d0%b0%d1%8e%d1%89%d0%b5%d0%b3%d0%be-%d1%80%d0%b0%d0%b7%d0%b4","status":"publish","type":"post","link":"https:\/\/oss-it.su\/en\/1062","title":{"rendered":"How to resize a running partition and add a swap partition without rebooting"},"content":{"rendered":"<p>The manual is valid for most Linux distributions: Debian, Ubuntu, Arch, CentOs, Fedora, Gentoo etc.<br \/>\nTo access `partprobe` and `resize2fs` utilities, first install `parted` package.<br \/>\nAll commands should be executed under the superuser. First, let&#8217;s look at the partitions detected:<br \/>\n<code>fdisk -l<\/code><br \/>\nThis will give you the list of the partitions that are available:<br \/>\n<code>Disk \/dev\/sda: 40 GiB, 42949672960 bytes, 83886080 sectors<br \/>\nUnits: sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisklabel type: dos<br \/>\nDisk identifier: 0x648aed90<br \/>\nDevice Boot Start End Sectors Size Id Type<br \/>\n\/dev\/sda1 2048 56915967 56913920 27,1G 83 Linux<br \/>\n\/dev\/sda3 56915968 83886079 26970112 12,9G 83 Linux<\/code><br \/>\nThe 40GB hard disk is divided into two ext4 partitions, sda1 and sda3. This article will describe how to delete the second partition without rebooting it on a running system and create a 4GB swap partition. And expanding of the working first partition to the end of the available space.<br \/>\nLet&#8217;s mount the second sda3 disk:<br \/>\n<code>umount \/dev\/sda3<\/code><br \/>\nLet&#8217;s run fdisk:<br \/>\n<code>fdisk \/dev\/sda<\/code><br \/>\nIn it, small Latin letters are commands. `m`, and then Enter will display a list of available commands.<br \/>\nWe will enter the following commands one by one: `p`, `d`, `3`, `p` to delete the second partition:<br \/>\n<code>Welcome to fdisk (util-linux 2.29.2).<br \/>\nChanges will remain in memory only, until you decide to write them.<br \/>\nBe careful before using the write command.<br \/>\nCommand (m for help): p<br \/>\nDisk \/dev\/sda: 40 GiB, 42949672960 bytes, 83886080 sectors<br \/>\nUnits: sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisklabel type: dos<br \/>\nDisk identifier: 0x648aed90<br \/>\nDevice Boot Start End Sectors Size Id Type<br \/>\n\/dev\/sda1 2048 56915967 56913920 27,1G 83 Linux<br \/>\n\/dev\/sda3 56915968 83886079 26970112 12,9G 83 Linux<br \/>\nCommand (m for help): d<br \/>\nPartition number (1,3, default 3): 3<br \/>\nPartition 3 has been deleted.<br \/>\nCommand (m for help): p<br \/>\nDisk \/dev\/sda: 40 GiB, 42949672960 bytes, 83886080 sectors<br \/>\nUnits: sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisklabel type: dos<br \/>\nDisk identifier: 0x648aed90<br \/>\nDevice Boot Start End Sectors Size Id Type<br \/>\n\/dev\/sda1 2048 56915967 56913920 27,1G 83 Linux<br \/>\nCommand (m for help):<\/code><br \/>\nNext, create a new partition for swap.<br \/>\nCommands: `n`, `p`, `2`,<br \/>\nHere the utility asks for the first sector for the partition. If we make 4 GB swap, it is 4294967296 bytes. Divide into 512 &#8211; we will get 8388608 sectors &#8211; this is the size of the swap area. If the last sector is 83886079, the first sector is (83886079 &#8211; 8388608) = 75497471. It means that the first sector for 4 GB of the partition will have to be specified as 75497471 with the available parameters.<br \/>\nNext, just Enter to enter the default value (Last sector default 83886079)<br \/>\nAnd change the type of this section by commands: `t`, `2`, `82`, `p`.<br \/>\nTo the question &#8220;Partition type (type L to list all types):&#8221; you can answer `L` and see the list of available options.<br \/>\n<code>Command (m for help): n<br \/>\nPartition type<br \/>\np primary (1 primary, 0 extended, 3 free)<br \/>\ne extended (container for logical partitions)<br \/>\nSelect (default p): p<br \/>\nPartition number (2-4, default 2): 2<br \/>\nFirst sector (56915968-83886079, default 56915968): 75497471<br \/>\nLast sector, +sectors or +size{K,M,G,T,P} (75497471-83886079, default 83886079):<br \/>\nCreated a new partition 2 of type 'Linux' and of size 4 GiB.<br \/>\nCommand (m for help): t<br \/>\nPartition number (1,2, default 2): 2<br \/>\nPartition type (type L to list all types): 82<br \/>\nChanged type of partition 'Linux' to 'Linux swap \/ Solaris'.<br \/>\nCommand (m for help): p<br \/>\nDisk \/dev\/sda: 40 GiB, 42949672960 bytes, 83886080 sectors<br \/>\nUnits: sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisklabel type: dos<br \/>\nDisk identifier: 0x648aed90<br \/>\nDevice Boot Start End Sectors Size Id Type<br \/>\n\/dev\/sda1 2048 56915967 56913920 27,1G 83 Linux<br \/>\n\/dev\/sda2 75497471 83886079 8388609 4G 82 Linux swap \/ Solaris<br \/>\nCommand (m for help):<\/code><br \/>\nNow let&#8217;s increase the first partition without unmounting it (it is working system), for this purpose we will delete it and at once we will create new with the necessary parametres (last sector not 56915967, and 75497470), for this purpose we enter commands:<br \/>\n`d`, `1`, `n`, `p`, `1`, [Enter], [Enter], `N`<br \/>\n<code>Command (m for help): d<br \/>\nPartition number (1,2, default 2): 1<br \/>\nPartition 1 has been deleted.<br \/>\nCommand (m for help): n<br \/>\nPartition type<br \/>\np primary (1 primary, 0 extended, 3 free)<br \/>\ne extended (container for logical partitions)<br \/>\nSelect (default p): p<br \/>\nPartition number (1,3,4, default 1): 1<br \/>\nFirst sector (2048-83886079, default 2048):<br \/>\nLast sector, +sectors or +size{K,M,G,T,P} (2048-75497470, default 75497470):<br \/>\nCreated a new partition 1 of type 'Linux' and of size 36 GiB.<br \/>\nPartition #1 contains a ext4 signature.<br \/>\nDo you want to remove the signature? [Y]es\/[N]o: N<br \/>\nCommand (m for help):<\/code><br \/>\nIf the first partition lost its boot tag after the operations (* in the boot column after the p command), you can activate it with commands a, 1:<br \/>\n<code>Command (m for help): a<br \/>\nPartition number (1,2, default 2): 1<br \/>\nThe bootable flag on partition 1 is enabled now.<br \/>\nCommand (m for help):<\/code><br \/>\nIf the beginning of the partition differs from the one that can be created (when entering the primary value &#8211; Value out of range) &#8211; first create the one that is suggested, then switch to expert mode, `x`, change the value of the beginning of the partition to the required, `b` and exit expert mode `r`.<br \/>\nRe-enter the `p` command and check to see if you are aprove of these changes. After all, everything you&#8217;ve done hasn&#8217;t come into effect yet. If that&#8217;s okay, you can enter the `w` command to accept the changes:<br \/>\n<code>Command (m for help): w<br \/>\nThe partition table has been altered.<br \/>\nCalling ioctl() to re-read partition table.<br \/>\nRe-reading the partition table failed.: Device or resource busy<br \/>\nThe kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).<\/code><br \/>\nAfter that, let&#8217;s run it:<br \/>\n<code>partprobe \/dev\/sda<\/code><br \/>\nand then:<br \/>\n<code>resize2fs \/dev\/sda1<\/code><br \/>\nIt will be approximately the same conclusion if it is successful:<br \/>\n<code>resize2fs 1.43.4 (31-Jan-2017)<br \/>\nFilesystem at \/dev\/sda1 is mounted on \/; on-line resizing required<br \/>\nold_desc_blocks = 2, new_desc_blocks = 3<br \/>\nThe filesystem on \/dev\/sda1 is now 9436927 (4k) blocks long.<\/code><\/p>\n<p>Everything went well. The file systems are changed.<\/p>\n<p>Let&#8217;s make swapspace from the second partition:<\/p>\n<p><code>mkswap \/dev\/sda2<\/code><br \/>\nIf successful:<br \/>\n<code>Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)<br \/>\nno label, UUID=0f0c8c2e-7f31-49de-b449-1a6efbd203ca<\/code><br \/>\nLet&#8217;s mount it as a swap:<br \/>\n<code>swapon \/dev\/sda2<\/code><\/p>\n<p>Now let&#8217;s change the autoload parameters in <code>\/etc\/fstab<\/code><\/p>\n<p>If there were some old records besides the main system partition, you should comment on them. And add one for the swap section:<br \/>\n<code>UUID=0f0c8c2e-7f31-49de-b449-1a6efbd203ca none swap sw 0 0<\/code><\/p>\n<p>(the identifier was set by the mkswap command)<\/p>\n<p>After that swap should be connected automatically and everything will be ready for further work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Resizing a running partition, adding a swap partition without reloading. The instruction is relevant for most Linux distributions: Debian, Ubuntu, Arch, CentOs, Fedora, Gentoo etc.<\/p>\n","protected":false},"author":1,"featured_media":1063,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[24,25],"class_list":["post-1062","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-system","tag-partitions","tag-software"],"_links":{"self":[{"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/posts\/1062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/comments?post=1062"}],"version-history":[{"count":5,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/posts\/1062\/revisions"}],"predecessor-version":[{"id":1099,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/posts\/1062\/revisions\/1099"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/media\/1063"}],"wp:attachment":[{"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/media?parent=1062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/categories?post=1062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/tags?post=1062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}