Upgrading Linux

We use CentOS Linux for our desktops and servers. Today I am completing the conversion of our file server to CentOS because the disk drives needed to be upgraded. They have been in service for about two (2) years and are now completely full. They way I know this is that our end users started to complain that they could not connect to the server, and df -h showed me 0 space clear (happened overnight). So, I deleted one backup to free some space and ordered two 1.5 TB Seagates. The HDs came in yesterday (Monday) and I installed CentOS 5.2xx.

The 1U server case and main board has four SATA connectors and physical room (and power connectors for) two SATA HDs. I modified the power cable to the micro DVD by adding a third SATA power connector, then installed the old LVM formatted HDs as they were originally on SATA1 and SATA2. I installed one new 1.5 TB Seagate on SATA3, mounted it as /aaa/, then copied the /home/ folders with cp -r -a /home/* /aaa/home/. Of course this took most of the night, so I went home at 8:30PM and let the computer work without me.

Today I need to transfer the accounts from the old system to the new, without needing to re-enter every account. I will weed out obsolete accounts later: I need this server up and running now. I found instructions on how to transfer the user login information intact at http://www.cyberciti.biz/faq/howto-move-migrate-user-accounts-old-to-new-server/. Summarizing Vivek Cite’s steps:

Following files/dirs are required for traditional Linux user management:
* /etc/passwd – contains various pieces of information for each user account

* /etc/shadow – contains the encrypted password information for user’s accounts and optional the password aging information.

* /etc/group – defines the groups to which users belong

* /etc/gshadow – group shadow file (contains the encrypted password for group)

* /var/spool/mail – Generally user emails are stored here.

* /home – All Users data is stored here.

You need to backup all of the above files and directories from old server to new Linux server.

Commands to type on old Linux system

First create a tar ball of old uses (old Linux system). Create a directory:
# mkdir /root/move/
Setup UID filter limit:
# export UGIDLIMIT=500
Now copy /etc/passwd accounts to /root/move/passwd.mig using awk to filter out system account (i.e. only copy user accounts)
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
Copy /etc/group file:
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
Copy /etc/shadow file:
# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig
Copy /etc/gshadow (rarely used):
# cp /etc/gshadow /root/move/gshadow.mig
Make a backup of /home and /var/spool/mail dirs:
# tar -zcvpf /root/move/home.tar.gz /home
# tar -zcvpf /root/move/mail.tar.gz /var/spool/mail

I skipped the archiving of /home/ because I had already copied it using cp -ar . The -a option keeps the user, group, and permits intact. I skipped mail because this is a file server and there is no mail service on it. Vivek’s awk instructions worked well for updating the passwd (et al) files. I did need to edit some on my  own because I had installed a normal user account when the CentOS install routine asked me to do so. Copy the .mig files made above to the new system somehow.

Commands to type on new Linux system

First, make a backup of current users and passwords:
# mkdir /root/newsusers.bak
# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak

Now restore passwd and other files in /etc/
# cd /path/to/location
# cat passwd.mig >> /etc/passwd
# cat group.mig >> /etc/group
# cat shadow.mig >> /etc/shadow
# /bin/cp gshadow.mig /etc/gshadow

Please note that you must use >> (append) and not > (create) shell redirection.

Now copy and extract home.tar.gz to new server /home
# cd /
# tar -zxvf /path/to/location/home.tar.gz

Now copy and extract mail.tar.gz (Mails) to new server /var/spool/mail
# cd /
# tar -zxvf /path/to/location/mail.tar.gz

Now reboot system; when the Linux comes back, your user accounts will work as they did before on old system:
# reboot

I did this last part a little different: I appended for all four cases instead of copying over gshadow.

Now, to get SAMBA working proved to be the simplest part of all. The majority of users still connect for file sharing via Microsoft systems. I just backed up the new /etc/samba/* files into a subdirectory, then copied the old /etc/samba/* to the new /etc/samba directory and started the smbd service. Fini.

Leave a Reply