{"id":171,"date":"2013-12-14T00:52:05","date_gmt":"2013-12-13T22:52:05","guid":{"rendered":"http:\/\/blog.dj6dp.de\/?p=171"},"modified":"2019-12-02T00:02:24","modified_gmt":"2019-12-01T22:02:24","slug":"painlessly-moving-var-to-a-new-partition","status":"publish","type":"post","link":"https:\/\/blog.dj6dp.de\/?p=171","title":{"rendered":"Painlessly moving \/var to a new partition"},"content":{"rendered":"<p>When I installed my current Linux system, I created a root partition of only 10GB (mainly because I already had another distribution installed that I wanted to keep as a backup). While this is enough for my purposes, Audacity regularly filled up the whole partition with data in \/var\/tmp\/audacity-daria. That is not only annoying (because Audacity will stop working), but also potentially dangerous for the stability of the whole system.<br \/>\nNow I could have just knocked off the other distribution and resized the root partition, but it occured to me that it would be a better way to just use its existing partition and move \/var to it.<\/p>\n<p>I found various different tutorials on how to do this around the web, so to make confusion complete I decided to add my own. \ud83d\ude00<br \/>\nI am currently running Ubuntu 13.10 (64-Bit), but this should work on any other recent Ubuntu\/Debian release, and probably on most other current distributions, too.<br \/>\nI should also mention that I assume you have some basic knowledge about the file system structure on a linux system, that you know what a terminal is and you&#8217;re not afraid to use it. \ud83d\ude09<\/p>\n<p>First of all, we need to format the partition we are going to move \/var to. I did this with the graphical tool gparted. Some people use reiserfs, I simply stuck with ext4. In my case, the partition&#8217;s name is \/dev\/sda4. At this point, also create a new directory \/var2 by entering <em>sudo mkdir \/var2<\/em>. This is going to be our temporary mount point.<br \/>\nBefore you edit your \/etc\/fstab file, make a backup of it! I am serious; if you do ANYTHING wrong, your whole system will be unable to boot!!! To do this, move to the directory and copy it:<br \/>\n<em>cd \/etc<\/em><br \/>\n<em>sudo cp fstab fstab_backup<\/em><\/p>\n<p>Now we can put our new partition into the fstab. Find out its UUID with the command <em>blkid<\/em>, that will return something like this:<br \/>\n<code>\/dev\/sda1: UUID=\"e9325f37-4394-409f-bd9a-cb473ad0379f\" TYPE=\"ext4\"<br \/>\n\/dev\/sda2: UUID=\"75c07cfd-99ab-4a9f-a25c-d6db771c3565\" TYPE=\"swap\"<br \/>\n\/dev\/sda3: UUID=\"306b4fea-31c5-4eae-b631-c89374c28c12\" TYPE=\"ext4\"<br \/>\n\/dev\/sda4: UUID=\"20b0eecf-e80e-4d37-abe6-d2a2bb20078d\" TYPE=\"ext4\"<br \/>\n\/dev\/zram0: UUID=\"78caa6fc-d44e-4826-8e60-d0fc07e660cc\" TYPE=\"swap\"<br \/>\n\/dev\/zram1: UUID=\"323ad229-b8c4-44c5-8e56-006ca1fcaa9a\" TYPE=\"swap\"<\/code><\/p>\n<p>Copy the value for \/dev\/sda4 (or whatever your partition is) without the quotation marks, and open the fstab with a text editor of your choice. I simply use nano: <em>sudo nano \/etc\/fstab<\/em><\/p>\n<p>Add the line for your new partition, so that it looks something like this:<br \/>\n<code>UUID=20b0eecf-e80e-4d37-abe6-d2a2bb20078d \/var2 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext4\u00a0\u00a0\u00a0 defaults\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2<\/code><br \/>\n(If you are curious what the other options mean, you might want to check the manpage for fstab.)<\/p>\n<p>To mount everything according to new fstab, enter <em>sudo mount -a<\/em>. If no error occurs, you can also check if it has been correctly mounted with <em>mount<\/em> or gparted.<\/p>\n<p>Now comes the tricky part. Enter <em>sudo init 1<\/em>, your system will drop down into single user mode, leaving you with only a root prompt. Now we need to copy everything from the &#8222;old&#8220; \/var to the new one. Enter <em>sudo cp -a \/var\/* \/var2\/<\/em> &#8211; this may take a while. If you&#8217;re curious about the progress, add the option <em>-v<\/em>. You can check the correct execution by typing ls \/var and ls \/var2, which should look mostly the same.<\/p>\n<p>If you want to empty the old \/var, you need to do this now &#8211; you won&#8217;t be able to do it from within the system later on! But unless you urgently need space on the root partition, I wouldn&#8217;t touch anything more that necessary, just to be safe and able to go back, just in case.<\/p>\n<p>Now, go back to the fstab, and just change the line for \/var2 into \/var. Again, you might want to check whether that worked by entering <em>mount -a<\/em> and <em>mount<\/em>.<\/p>\n<p>Congratulations, we&#8217;re done! Type <em>reboot<\/em> and your system should come up like it has always been that way.<\/p>\n<p>If you found any mistakes in my little tutorial, <strong>please<\/strong> drop me an e-mail!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I installed my current Linux system, I created a root partition of only 10GB (mainly because I already had another distribution installed that I wanted to keep as a backup). While this is enough for my purposes, Audacity regularly &hellip; <a href=\"https:\/\/blog.dj6dp.de\/?p=171\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-english-articles","category-sonstiges"],"_links":{"self":[{"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":5,"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":274,"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions\/274"}],"wp:attachment":[{"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.dj6dp.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}