{"id":1957,"date":"2024-04-29T12:53:44","date_gmt":"2024-04-29T09:53:44","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/decrease-storage-size-centos-7\/"},"modified":"2024-04-29T12:53:44","modified_gmt":"2024-04-29T09:53:44","slug":"decrease-storage-size-centos-7","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/decrease-storage-size-centos-7\/","title":{"rendered":"How to safely decrease storage size on CentOS 7 Cloud Servers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Decreasing the storage size involves creating a new device with the desired size, transferring all data from the old drive to the new one, and then deleting the old one. This way, all data is kept secure during the operation, and everything gets safely copied as long as it can fit in the target space.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide assumes that the root and boot partitions on your Centos 7 storage are not split into separate partitions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We highly recommend <b>backing up<\/b> your server before resizing storage!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create and attach a new storage device<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Start creating a new storage device of the preferred size in the UpCloud Control Panel. Note that your server must be shut down before the required options become available.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go to the <em>Storage<\/em> section in your server settings and click the <em>Add a new device<\/em> button underneath the list of your existing storage devices.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" style=\"width: 900px;\" src=\"https:\/\/lh7-eu.googleusercontent.com\/jSacLW95-OxS_fBZsyTuHmYKIblNkC59oV1cw29joaL_ZnpJJCS38Rt1cQOZHjEjOzFc8QZ1vxyoP-Bp8WgYBHnHpSPtia4fNyoZjYLsXxrOtvfFvLTLclds-jegJaa3_cGMCDYtalnwrqL7R9xjGZc\" alt=\"-\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the following dialogue window, select <em>New storage device<\/em>, give the storage the required size and name, then click the <em>Add a storage device<\/em> button to confirm.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are resizing to a smaller plan, make sure the new storage size matches the storage size offered with the new plan.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-eu.googleusercontent.com\/B7S6m3qNQZRRY74fYH6ir5qNZRsRkW8Y2yEIxWa1jeAvbDGcCzmxTJTpzg-jFka704oGjGgk1BJDl2K9gVx_Zvv5IW080KMcjMVS_o37Qsz7lgnHXMW_c5M6S9l6Gu5DnYBuAwn9zP8V3LuOUeMdtpU\" alt=\"-\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You should now see a second storage device below the original.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-eu.googleusercontent.com\/U0FFsysQXn7-vfjmcMrkqZ_7IvbChTlSPYH0uzfZmo_y8TWsVWaonCv44Zmw89hTz5TjMVixOtgO5-DQb-t5TiBfDOzJLT5ngDI23LS07Tz4cKL_7YGcfYCmvKi9--Ejbdp8NQ2kbB0FggzOT5AZHrk\" alt=\"-\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After the attaching process is complete, start your server up again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once your server is up and running, you can continue resizing at the OS level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Copying data to the new storage<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the name of the newly added storage device using the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">lsblk<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see something like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT<br>vda    253:0   0  50G  0  disk<br>\u2514\u2500vda1 253:1   0  50G  0  part \/<br>vdb    253:16  0  25G  0  disk<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The device you are looking for is usually the last on the list and will not have partitions on it like <em>vdb<\/em> in the example above. Create a new partition on the new storage using fdisk. Replace the <em>&lt;disk><\/em> in the command below with the new device name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo fdisk \/dev\/vdb<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The utility will open its own command prompt showing <em>Command (m for help):<\/em> instead of the usual <em>user@host:\/$.<\/em> The following one-letter commands will be entered there.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, start the new partition wizard with the command <strong><em>n<\/em><\/strong>. Use default values by just pressing enter on each of the options, or type in the required parameter if no default value is given.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&gt; n<br># Primary p, partition 1, start sector 2048, end sector at disk end.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With the partition created, make it bootable using command <strong><em>a<\/em><\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&gt; a<br># Partition 1 if asked.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Afterwards, you can check that the partition was configured properly and is marked bootable with <strong><em>p<\/em><\/strong>. It should show something along the lines of the example underneath.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&gt; p<br>Device     Boot Start      End  Sectors  Size Id Type<br>\/dev\/vdb1  *     2048 52428799 52426752   25G 83 Linux<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If everything is in order, write partition changes to the storage device using the command <strong><em>w<\/em><\/strong>. If there was a mistake in the setup, delete the faulty partition by entering command <strong>d<\/strong> and then create a new one with command <em><strong>n<\/strong><\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&gt; w<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once fdisk has finished writing the partition table to the device, it will exit and return you to the usual command prompt. Using the <em>lsblk<\/em> command, check that the new partition shows up.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">lsblk<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT<br>vda    253:0   0  50G  0  disk<br>\u2514\u2500vda1 253:1   0  50G  0  part \/<br>vdb    253:16  0  25G  0  disk<br>\u2514\u2500vdb1 253:17  0  25G  0  part<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see both storage devices and their partitions with their correct sizes. <b>The storage will be named similarly to vda or vdb, and their partitions will include the added partition identifier number, e.g. vda1 or vdb1.<\/b> Notice that some commands below require entering the storage device name while others use the partitions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set up the partition using a file system type appropriate for your server. CentOS 7 machines use XFS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\"># Creating an XFS file system on CentOS 7.0<br>sudo mkfs.xfs \/dev\/vdb1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Afterwards, mount the new storage device on your system so that you can copy the files.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo mount \/dev\/vdb1 \/mnt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We recommend using rsync to copy such large amounts of files that your operating system might contain. It provides convenient options for copying all the files from your current storage to the new one while keeping track of the copy process, allowing you to continue from where you left off if you have to cancel the copying.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the CentOS server, you\u2019ll need to temporarily disable SELinux to allow the copy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo setenforce 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Install rsync if you do not already have it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo yum install rsync<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The rsync command here uses the options for verbose output so that you can easily see what is getting copied. However, having a large amount of output on the display might slow down the process with a larger number of small files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can disable the printout by omitting the parameter \u2013<em>v<\/em> from the command, or having the output redirected to a file by adding \u2018<em>&gt; ~\/filename.txt<\/em>\u2018 to the end of the command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo rsync -avxHAX \/ \/mnt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once the copy process has finished, check the storage space usage to see everything was copied. The used space will not be exactly the same, but the difference should be minimal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">df<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" style=\"width: 900px;\" src=\"https:\/\/lh7-eu.googleusercontent.com\/zJHxUxjOt1_qvOtKbawSi_7O28RkhZH_FYHHDqULhYhZpF5yWUIOej4wU_QnWxsG8qHqNkXsBYeDjCd5ZaD0wxtMKwLGnGnMtNnTThxhUb6G40BlrM2oLJLZG1qTB9HpvmwVRwUkqs6ry5Fe9azwezI\" alt=\"-\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, install a boot manager on the new storage to boot again with a new main storage device. Depending on your system, you need to install the correct version of GRUB.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Newer CentOS and other Red Hat variants opt for the newer version.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo grub2-install \/dev\/vdb<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see a confirmation like in the example output below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">Installing for i386-pc platform.<br>Installation finished. No error reported.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">CentOS 7 users should now set the UUID for the new storage device, check it from the <em>\/etc\/fstab<\/em> with the following command, and then replace <em>&lt;UUID><\/em> in the next command with it while selecting the new partition, <em>vdb1<\/em> for example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo umount \/mnt<br>sudo cat \/etc\/fstab<br>sudo xfs_admin -U &lt;UUID&gt; \/dev\/vdb1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After that, shut down your server either with the Shutdown request at your UpCloud Control Panel or by using the following command in your server terminal<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo shutdown -h now<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Swapping storage devices<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">With your server shut down, go to the Storage tab again and click the eject icon next to the former main storage device, leaving just the new smaller storage device.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-eu.googleusercontent.com\/-GkV7NGqNyLMMEtkTZBO7pePj6UEYa7nbwftTbUc3i_KN80l3pjNynb_8mza876T2ENZumzHPsagUs_DBvhYAmPWiUx-lJ4BuUHzg1XoOWDS6_3aWYJldwp8h1-moRX5phrhh1rw4LMIrNGOoQu_-cQ\" alt=\"-\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you are resizing to a smaller plan, head to the Plan tab, select the new plan you intend to use and click Save Changes.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-eu.googleusercontent.com\/iwA09xAZUiiyfKEUJWLX3QRal_srcro8g2PjLVjz9olC8QmFJ6kPYMzO8tGcQKcYVRaloglMfv4c501dEpq4ideXRMhdLl_N6lmX3oy2skzWyFPN15fbxme5SznSZM3aJx7FNJuTMC4VSViR-QHynLs\" alt=\"-\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then, start up your server. Confirm that your data was copied successfully and is available on the new storage device.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the server cannot find the boot section and fails to start, shut down the server and attach the original storage again to boot from. Then, reinstall the GRUB and try booting from the new device again by detaching the old one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Afterwards, you can delete the old storage from your UpCloud Control Panel in the Storage device section. If you no longer need it, be sure also to delete the backup you took.<\/p>\n","protected":false},"author":65,"featured_media":39576,"comment_status":"open","ping_status":"closed","template":"","community-category":[265],"class_list":["post-1957","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/1957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=1957"}],"version-history":[{"count":0,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/1957\/revisions"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=1957"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=1957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}