24 October 2014

598. Move /var, /tmp, /opt to separate partitions

1. First create the partitions on a disk. In my case I created partitions on a different disk from the root partition.

2. Figure out the uuids:
ls /dev/disk/by-uuid -lah
lrwxrwxrwx 1 root root 10 Oct 22 14:02 28b59809-7dfb-4ce4-a4da-6f118171ea07 -> ../../sdb2 lrwxrwxrwx 1 root root 9 Oct 22 14:45 52f07f83-3a72-457c-b25f-7aa4f3e76461 -> ../../sdc lrwxrwxrwx 1 root root 10 Oct 7 14:42 8a5ca4ae-9963-47ea-99c3-2335c7dc8118 -> ../../sda6 lrwxrwxrwx 1 root root 10 Oct 7 14:42 9243ff6b-9834-4fa3-a93f-10a350f85687 -> ../../sda1 lrwxrwxrwx 1 root root 10 Oct 22 14:02 9f785dde-1d3a-4063-90e7-054f3d031e05 -> ../../sdb3 lrwxrwxrwx 1 root root 10 Oct 22 14:02 eacf2cad-d462-45b2-afeb-2c5ddf5669b8 -> ../../sdb4 lrwxrwxrwx 1 root root 10 Oct 7 14:42 f25a484c-e8e2-4ead-808b-96dd5e915020 -> ../../sda5 lrwxrwxrwx 1 root root 10 Oct 22 14:02 f4280c34-04d6-4def-963a-507e68dd483d -> ../../sdb1
I know that I'm looking for sbd2 (label: tmp), sdb3 (label: opt) and sdb4 (label: var). We'll use these uuids later for our /etc/fstab

3. Move /opt, as it's the easiest (should be reasonably static).

sudo udisks --mount /dev/sdb3
Mounted /org/freedesktop/UDisks/devices/sdb3 at /media/opt
sudo cp -ax /opt/* /media/opt

Edit /etc/fstab:
 
UUID=9f785dde-1d3a-4063-90e7-054f3d031e05 /opt ext4 defaults,user_xattr 0 2

Move the old /opt and mount the new one:
sudo mv /opt /opt.old
sudo mount /opt

And you should be good to go. Check with df -h:
[..] /dev/sdb3 72G 28G 41G 41% /opt

4. Move /var and /tmp

You can use init 1 according to http://unix.stackexchange.com/questions/131311/moving-var-home-to-separate-partition. Note that doing so will kill your graphical session and stop or restart most of the services i.e. close open documents before your continue. You'll then get dumped into a vty.

Open a terminal and type
 
init 1

which dumps you into a root terminal. Then, as root, do
 
mkdir /media/var
mount /dev/sdb4 /media/var
cp -ax /var/* /media/var
mkdir /media/tmp
mount /dev/sdb2 /media/tmp
cp -ax /tmp/* /media/tmp
mv /tmp /tmp.old
mv /var /var.old
mkdir /tmp
chmod 777 /tmp
mkdir /var
umount /media/var
umount /media/tmp

Changing the permissions for /tmp is important -- if they aren't generous enough it can cause all sorts of issues. In my case it was manifested by me being unable to log onto a GUI (e.g. gnome) from GDM3 -- I would get booted back to the login screen.

Edit /etc/fstab and add:
UUID=28b59809-7dfb-4ce4-a4da-6f118171ea07 /tmp ext4 defaults,user_xattr 0 2 UUID=eacf2cad-d462-45b2-afeb-2c5ddf5669b8 /var ext4 defaults,user_xattr 0 2
Note: I don't know what the best values for the attributes are. I just took what I used for /home, which is probably not optimal. You may want to do your own research into this. Then do

mount /tmp
mount /var
init 2

Once you've established that all is well you can delete /var.old and /tmp.old.
df -h shows
Filesystem Size Used Avail Use% Mounted on rootfs 92G 32G 56G 37% / udev 10M 0 10M 0% /dev tmpfs 798M 1.1M 797M 1% /run /dev/disk/by-uuid/9243ff6b-9834-4fa3-a93f-10a350f85687 92G 32G 56G 37% / tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 4.6G 88K 4.6G 1% /run/shm /dev/sda6 734G 555G 142G 80% /home /dev/sdb3 72G 28G 41G 41% /opt /dev/sdb2 72G 53M 69G 1% /tmp /dev/sdb4 48G 8.8G 37G 20% /var

597. Missing partition -- gparted shows unallocated space

The issue:
I'm low on space on my / partition since ECCE has a way of putting really large files in /tmp. Rather than trying to fix the behaviour of ECCE, I'm planning on moving /tmp to a separate disk that's dedicated to highio processes and where ECCE can't cause my / to fill up. I might move /opt as well, to free even more space. The first step in such a move is to create an additional partition on your target disk and for that gparted is good as it can move all the data before creating the new partition.

Imagine my surprise when I fired up gparted and saw:

Using Disk Utilities (palimpsest) it doesn't look too odd:

Using fdisk I see a complete lack of partitions:
sudo fdisk /dev/sdb
Command (m for help): p Disk /dev/sdb: 1000 GB, 1000202273280 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System Command (m for help):

This may be a job for testdisk. I fired it up with sudo, selected Intel type partition, and kept selecting the defaults -- eventually my partition showed up. I then did a deep search to make sure everything was ok.






I then check using palimpsest and gparted:





(I also screwed up, then fixed a disk with a different issue -- but because I'm not really sure what I did to fix it I'll make a separate post about that at a later date. Maybe.)

17 October 2014

596. Debian Jessie -- shutdown takes 'forever' (five minutes according to stopwatch!)

I've been annoyed for a couple of months now that shutting down my laptop, which has an SSD, takes up to five minutes. If I wanted that kind of shutdown times I could run Windows Vista...

Either way, it turns out that it's affecting certain systems with samba:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762002

The issue is illustrated below, which showed that it took five minutes to shut down samba -- and that's what's preventing the system from shutting down:
 
sudo service samba stop
ps aux|grep sam && date
root 2765 0.0 0.0 65468 2100 pts/0 S+ 10:45 0:00 sudo service samba stop root 2766 0.0 0.0 26252 1172 pts/0 S+ 10:45 0:00 systemctl stop samba.service root 2785 0.0 0.0 4308 636 ? Ss 10:45 0:00 /bin/sh /etc/init.d/samba stop Sunday 12 October 10:49:28 AEDT 2014
The solution is pretty simple though -- remove a set of symlinks:

First establish that they are present:
me@oxygen:/etc$ find rc* -name "*samba*"|xargs -I {} ls {} -lah
lrwxrwxrwx 1 root root 15 Sep 16  2013 rc0.d/K01samba -> ../init.d/samba
lrwxrwxrwx 1 root root 21 Sep 15 10:46 rc0.d/K01samba-ad-dc -> ../init.d/samba-ad-dc
lrwxrwxrwx 1 root root 15 Sep 16  2013 rc1.d/K01samba -> ../init.d/samba
lrwxrwxrwx 1 root root 21 Sep 15 10:46 rc1.d/K01samba-ad-dc -> ../init.d/samba-ad-dc
lrwxrwxrwx 1 root root 15 Sep 16  2013 rc2.d/S01samba -> ../init.d/samba
lrwxrwxrwx 1 root root 21 Sep 15 10:46 rc2.d/S01samba-ad-dc -> ../init.d/samba-ad-dc
lrwxrwxrwx 1 root root 15 Sep 16  2013 rc3.d/S01samba -> ../init.d/samba
lrwxrwxrwx 1 root root 21 Sep 15 10:46 rc3.d/S01samba-ad-dc -> ../init.d/samba-ad-dc
lrwxrwxrwx 1 root root 15 Sep 16  2013 rc4.d/S01samba -> ../init.d/samba
lrwxrwxrwx 1 root root 21 Sep 15 10:46 rc4.d/S01samba-ad-dc -> ../init.d/samba-ad-dc
lrwxrwxrwx 1 root root 15 Sep 16  2013 rc5.d/S01samba -> ../init.d/samba
lrwxrwxrwx 1 root root 21 Sep 15 10:46 rc5.d/S01samba-ad-dc -> ../init.d/samba-ad-dc
lrwxrwxrwx 1 root root 15 Sep 16  2013 rc6.d/K01samba -> ../init.d/samba
lrwxrwxrwx 1 root root 21 Sep 15 10:46 rc6.d/K01samba-ad-dc -> ../init.d/samba-ad-dc

Then remove them:
me@oxygen:/etc$ sudo update-rc.d samba remove 
me@oxygen:/etc$ sudo update-rc.d smbd remove 
Done!