Warning! You will need to have “physical” access to the server’s console in order to perform these steps – remote login via ssh won’t be enough (init 1 – no ssh in rescue mode)

Maybe the root / dir and /home share the same harddisk and you are running out of diskspace.

So you want to move the bulk of the data /home to a separate harddisk/partition.

(this was tested on Debian 8.7, Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1 (2016-12-30) x86_64 GNU/Linux)

plan:

1. create and prepare the new partition using fdisk like described in this article

maybe i am super paranoid but i still recommend ext3 over ext4.

2. login as root DIRECTLY at the server or boot from a rescue medium like KNOPPIX, this will not work over ssh

(because then the /home directory is in use)

3. mount the newly created partition

please scroll in this box:

[cc lang=”bash” escaped=”true” width=”600″]
# i assume you have created a second partition with fdisk and formatted it ext3
# i won’t go into details how to do that – please run a search
# in this case it is a VM that got another virtual harddisk /dev/sdb attached

mkdir /mnt/sdb1; # create mount point

mount /dev/sdb1 /mnt/sdb1; # mount partition

init 1; # go into single-user or maintenance mode
# this is a runlevel were linux quits all running processes except the ones essential for root to operate

rsync –update –progress -l -aXS –exclude=’/*/.gvfs’ /home/. /mnt/sdb1/. ; # copy all data

# if you have to redo the process at a later time you might also want to delete non existing files

# BE CAREFULL WITH THE –DELETE PARAMETER

rsync –delete –update –progress -l -aXS –exclude=’/*/.gvfs’ /home/. /mnt/sda2/. ; # copy all data

diff -r /home /mnt/sdb1 -x “.gvfs/*”; # check copying worked

# the only output you should see is
Only in /mnt/sdb1: lost+found

# 4. open fstab and add this line
vim /etc/fstab;

/dev/sdb1 /home ext3 relatime,errors=remount-ro 0 1

# 5. reboot

# 6. after reboot go again into maintenance-single-user-mode

init 1;

mount; # you should now see your new home be mounted at /dev/sdb1

umount /dev/sdb1;

# move the old home diretory “out of the way”
mv /home/ /home_old;

reboot; # again

# after reboot, there should be no process using anymore the home_old directory or any of it’s files

# so you should be save to remove those
rm -rI /home_old; # remove originals

# funny reply of the filesystem… I AM ROOT HELLOOOO?

rm: cannot remove ‘/home_old/admin/conf/web’: Permission denied
rm: cannot remove ‘/home_old/admin/conf/mail’: Permission denied
rm: cannot remove ‘/home_old/admin/conf/dns’: Permission denied

# try this
rm -rf /home_old; # remove originals

# if it still did not work:

lsattr /home_old/admin/conf ; # lsattr – list file attributes on a Linux second extended file system
———-I–e– home_old/admin/conf/web
————-e– home_old/admin/conf/mail
————-e– home_old/admin/conf/dns

# chattr – change file attributes on a Linux file system
chattr -i /home_old/admin/conf

rm -rf /home_old/admin/conf; # now it works

rm -rf /home_old/admin; # now it works

rm -rf /home_old; # now it works, strange

[/cc]

see attached man pages 😀 still so much to learn 😀

chattr.man.txt

lsattr.man.txt

Links:

http://searchenterpriselinux.techtarget.com/tip/Working-with-Linux-file-system-attributes

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin