Migrating Server4You server to sane partitioning

From Lars' Site
Jump to: navigation, search

I am and have been using servers hosted at Server4You quite a lot. If one is searching Google for Server4You there are quite a number of bad reviews showing up. Most of these are related to people screwing up their own servers and Server4You not really being able to assist in fixing self inflicted problems. Server4You provide a server with unlimited bandwidth for a fixed and very reasonable cost per month. They fix hardware quick if there are issues but that is about it - it is up to you what you do with your server and how you do it, and that is precisely what I like about them.

When a new server is ordered the customer have the option on which Operating system and configuration to install on said server. I always choose Debian 8 - Minimal - RAID1, which as the name suggest is an up-to-date Debian system, with Raid 1 but no other bells or whistles. All the Server4You servers are delivered with 2 identical disks and I like to use them in mirrored in a Raid 1 configuration. What I do not like is the fact that the server is configured with one huge root partition taking the entire space.

Prerequisites

First step is to install the lvm2 package:

 # apt-get install lvm2

Remove partitions from existing RAID

s6:~# cat /proc/mdstat
Personalities : [raid1] 
md1 : active (auto-read-only) raid1 sda3[0] sdb3[1]
      7996416 blocks super 1.2 [2/2] [UU]
        resync=PENDING
      
md2 : active raid1 sda4[0] sdb4[1]
      2921632768 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  3.5% (102869824/2921632768) finish=442.0min speed=106286K/sec
      bitmap: 22/22 pages [88KB], 65536KB chunk

md0 : active raid1 sda2[0] sdb2[1]
      499392 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

s6:~# mdadm --fail /dev/md2 /dev/sdb4
mdadm: set /dev/sdb4 faulty in /dev/md2
s6:~# mdadm --remove /dev/md2 /dev/sdb4
mdadm: hot removed /dev/sdb4 from /dev/md2
s6:~# mdadm --fail /dev/md2^Cdev/sdb4
s6:~# df
Filesystem      1K-blocks   Used  Available Use% Mounted on
/dev/md2       2875655912 974048 2728583844   1% /
udev                10240      0      10240   0% /dev
tmpfs             6581444   8832    6572612   1% /run
tmpfs            16453600      0   16453600   0% /dev/shm
tmpfs                5120      0       5120   0% /run/lock
tmpfs            16453600      0   16453600   0% /sys/fs/cgroup
/dev/md0           483626  33873     424784   8% /boot
s6:~# mdadm --fail /dev/md1 /dev/sdb3
mdadm: set /dev/sdb3 faulty in /dev/md1
s6:~# mdadm --remove /dev/md1 /dev/sdb3
mdadm: hot removed /dev/sdb3 from /dev/md1
s6:~# cat /proc/mdstat
Personalities : [raid1] 
md1 : active (auto-read-only) raid1 sda3[0]
      7996416 blocks super 1.2 [2/1] [U_]
        resync=PENDING
      
md2 : active raid1 sda4[0]
      2921632768 blocks super 1.2 [2/1] [U_]
      bitmap: 22/22 pages [88KB], 65536KB chunk

md0 : active raid1 sda2[0] sdb2[1]
      499392 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>




s6:~# swapoff /dev/md1
s6:~# free
             total       used       free     shared    buffers     cached
Mem:      32907204     393680   32513524       9436      17412     242656
-/+ buffers/cache:     133612   32773592
Swap:            0          0          0
s6:~# mdadm remove /dev/md1
mdadm: An option must be given to set the mode before a second device
       (/dev/md1) is listed
s6:~# mdadm --stop /dev/md1
mdadm: stopped /dev/md1
s6:~# mdadm --zero-superblock /dev/sda3
s6:~# mdadm --zero-superblock /dev/sdb3


s6:~# mkswap /dev/sda3
Setting up swapspace version 1, size = 8000508 KiB
no label, UUID=abdbf3a3-bc1d-468f-b5bc-70512971d6d5
s6:~# mkswap /dev/sdb3
Setting up swapspace version 1, size = 8000508 KiB
no label, UUID=76f73c9c-7aa3-47f0-8478-2f0a4f280b0c


s6:~# vi /etc/fstab
s6:~# swapon /dev/sda3
s6:~# swapon /dev/sdb3
s6:~# free
             total       used       free     shared    buffers     cached
Mem:      32907204     398560   32508644       9432      17880     242744
-/+ buffers/cache:     137936   32769268
Swap:     16001016          0   16001016
s6:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/md2 during installation
UUID=4bc2886a-8a07-4fd1-b96e-8b50350651ad /               ext4    errors=remount-ro 0       1
# /boot was on /dev/md0 during installation
UUID=2f7df835-4bc0-4635-9706-98715cc9fe42 /boot           ext2    defaults        0       2

# Swap changed to two partitions
UUID=abdbf3a3-bc1d-468f-b5bc-70512971d6d5 none            swap    sw              0       0
UUID=76f73c9c-7aa3-47f0-8478-2f0a4f280b0c none            swap    sw              0       0





s6:~# mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdb4 missing
mdadm: /dev/sdb4 appears to be part of a raid array:
       level=raid1 devices=2 ctime=Wed Jun 24 12:39:01 2015
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.

s6:~# mdadm --examine  --scan
ARRAY /dev/md/2  metadata=1.2 UUID=ad038af4:b916af34:5c6659b3:e57c83e6 name=malta2368:2
ARRAY /dev/md/0  metadata=1.2 UUID=dea2e513:a1dfbd13:e2ef47de:c3bbc55d name=malta2368:0
ARRAY /dev/md/1  metadata=1.2 UUID=3cc0f93c:cd0650c0:de6c51fe:5dbee050 name=s6:1
s6:~# mdadm --examine  --scan>>/etc/mdadm/mdadm.conf
s6:~# vi /etc/mdadm/mdadm.conf 
s6:~# cat /etc/mdadm/mdadm.conf 
# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

# by default (built-in), scan all partitions (/proc/partitions) and all
# containers for MD superblocks. alternatively, specify devices to scan, using
# wildcards if desired.
#DEVICE partitions containers

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts
MAILADDR root

# definitions of existing MD arrays
ARRAY /dev/md/0  metadata=1.2 UUID=dea2e513:a1dfbd13:e2ef47de:c3bbc55d name=malta2368:0
ARRAY /dev/md/1  metadata=1.2 UUID=3cc0f93c:cd0650c0:de6c51fe:5dbee050 name=s6:1
ARRAY /dev/md/2  metadata=1.2 UUID=ad038af4:b916af34:5c6659b3:e57c83e6 name=malta2368:2



s6:~# pvcreate /dev/md1
  Physical volume "/dev/md1" successfully created
s6:~# vgcreate --help
  vgcreate: Create a volume group

vgcreate
        [-A|--autobackup {y|n}] 
        [--addtag Tag] 
        [--alloc AllocationPolicy] 
        [-c|--clustered {y|n}] 
        [--commandprofile ProfileName]
        [-d|--debug]
        [-h|--help]
        [-l|--maxlogicalvolumes MaxLogicalVolumes]
        [--metadataprofile ProfileName]
        [-M|--metadatatype 1|2] 
        [--[vg]metadatacopies #copies] 
        [-p|--maxphysicalvolumes MaxPhysicalVolumes] 
        [-s|--physicalextentsize PhysicalExtentSize[bBsSkKmMgGtTpPeE]] 
        [-t|--test] 
        [-v|--verbose]
        [--version] 
        [-y|--yes]
        [ PHYSICAL DEVICE OPTIONS ] 
        VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]

s6:~# vgcreate s6 /dev/md1
  Volume group "s6" successfully created
s6:~# lvcreate --name root --size 2G s6
  Logical volume "root" created
s6:~# lvcreate --name usr --size 16G s6
  Logical volume "usr" created
s6:~# lvcreate --name var --size 16G s6
  Logical volume "var" created
s6:~# lvcreate --name tmp --size 2G s6
  Logical volume "tmp" created
s6:~# lvcreate --name home --size 128G s6
  Logical volume "home" created





s6:~# mkfs.ext4 -j /dev/s6/root
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: b2f77264-2be1-48c6-a56c-1752f8cc4578
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

s6:~# mkfs.ext4 -j /dev/s6/usr
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 4194304 4k blocks and 1048576 inodes
Filesystem UUID: 5c8db7d9-8209-4ea0-8e19-2c95ca38cc1d
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   


s6:~# mkfs.ext4 -j /dev/s6/var
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 4194304 4k blocks and 1048576 inodes
Filesystem UUID: 0842e3a5-6f90-40e4-8839-e0e698e8949b
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

s6:~# mkfs.ext4 -j /dev/s6/tmp
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 36823d39-dea5-460d-9d6a-4cc1777d5f43
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

s6:~# mkfs.ext4 -j /dev/s6/home
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 33554432 4k blocks and 8388608 inodes
Filesystem UUID: fda6617e-4cc5-4944-80c0-4e73153a3b75
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     

s6:/# vi /etc/fstab
s6:/# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/md2 during installation
UUID=4bc2886a-8a07-4fd1-b96e-8b50350651ad /               ext4    errors=remount-ro 0       1
# /boot was on /dev/md0 during installation
UUID=2f7df835-4bc0-4635-9706-98715cc9fe42 /boot           ext2    defaults        0       2

# Logical volumes
/dev/mapper/s6-tmp /tmp ext4 defaults 0 0 

# Swap changed to two partitions
UUID=abdbf3a3-bc1d-468f-b5bc-70512971d6d5 none            swap    sw              0       0
UUID=76f73c9c-7aa3-47f0-8478-2f0a4f280b0c none            swap    sw              0       0

s6:/# mv tmp tmp.old 
s6:/# mkdir tmp
s6:/# mount tmp
s6:/# chmod 777 tmp
s6:/# chmod +t tmp


s6:~# df
Filesystem          1K-blocks   Used  Available Use% Mounted on
/dev/md2           2875655912 974548 2728583344   1% /
udev                    10240      0      10240   0% /dev
tmpfs                 6581444   8852    6572592   1% /run
tmpfs                16453600      0   16453600   0% /dev/shm
tmpfs                    5120      0       5120   0% /run/lock
tmpfs                16453600      0   16453600   0% /sys/fs/cgroup
/dev/md0               483626  33873     424784   8% /boot
/dev/mapper/s6-tmp    1998672   3076    1874356   1% /tmp



s6:~# cd /mnt
s6:/mnt# mkdir root usr var



s6:/mnt# mount /dev/mapper/s6-root root
s6:/mnt# mount /dev/mapper/s6-usr usr
s6:/mnt# mount /dev/mapper/s6-var var

s6:/mnt# cd /
s6:/# find . -mount -print | cpio -pvd /mnt/root


s6:/# cd /mnt/root/usr
s6:/mnt/root/usr# mv * /mnt/usr/
s6:/mnt/root/usr# ls -lsa
total 8
4 drwxr-xr-x  2 root root 4096 Jun 24 13:51 .
4 drwxr-xr-x 22 root root 4096 Jun 24 13:51 ..
s6:/mnt/root/usr# cd ../var
s6:/mnt/root/var# mv * /mnt/var/
s6:/mnt/root/var# ls -lsa
total 8
4 drwxr-xr-x  2 root root 4096 Jun 24 13:51 .
4 drwxr-xr-x 22 root root 4096 Jun 24 13:51 ..


s6:/mnt/var# cd
s6:~# umount /mnt/var
s6:~# umount /mnt/usr



s6:/# vi /etc/fstab
s6:/# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/md2 during installation
UUID=4bc2886a-8a07-4fd1-b96e-8b50350651ad /               ext4    errors=remount-ro 0       1
# /boot was on /dev/md0 during installation
UUID=2f7df835-4bc0-4635-9706-98715cc9fe42 /boot           ext2    defaults        0       2

# Logical volumes
/dev/mapper/s6-usr /usr ext4 defaults 0 0 
/dev/mapper/s6-var /var ext4 defaults 0 0 
/dev/mapper/s6-tmp /tmp ext4 defaults 0 0 
/dev/mapper/s6-home /home ext4 defaults 0 0 

# Swap changed to two partitions
UUID=abdbf3a3-bc1d-468f-b5bc-70512971d6d5 none            swap    sw              0       0
UUID=76f73c9c-7aa3-47f0-8478-2f0a4f280b0c none            swap    sw              0       0


s6:/# cd /
s6:/# mv var var.old && mkdir var && mount var
s6:/# mv usr usr.old && mkdir usr && mount usr
s6:/# df
Filesystem           1K-blocks   Used  Available Use% Mounted on
/dev/md2            2875655912 974564 2728583328   1% /
udev                     10240      0      10240   0% /dev
tmpfs                  6581444   8852    6572592   1% /run
tmpfs                 16453600      0   16453600   0% /dev/shm
tmpfs                     5120      0       5120   0% /run/lock
tmpfs                 16453600      0   16453600   0% /sys/fs/cgroup
/dev/md0                483626  33873     424784   8% /boot
/dev/mapper/s6-tmp     1998672   3076    1874356   1% /tmp
/dev/mapper/s6-home  131980772  60984  125192520   1% /home
/dev/mapper/s6-root    1998672 236148    1641284  13% /mnt/root
/dev/mapper/s6-var    16382888 188736   15338908   2% /var
/dev/mapper/s6-usr    16382888 567904   14959740   4% /usr



s6:~# update-initramfs -k all -u
update-initramfs: Generating /boot/initrd.img-3.16.0-4-amd64


s6:~# reboot
Write failed: Broken pipe
lth@nb5:~$ ssh root@s6.netcompartner.com
You have mail.
Last login: Wed Jun 24 13:45:02 2015 from 60.51.110.202
s6:~# df
Filesystem           1K-blocks   Used  Available Use% Mounted on
/dev/md2            2875655912 974568 2728583324   1% /
udev                     10240      0      10240   0% /dev
tmpfs                  6581444   8864    6572580   1% /run
/dev/dm-0             16382888 567904   14959740   4% /usr
tmpfs                 16453600      0   16453600   0% /dev/shm
tmpfs                     5120      0       5120   0% /run/lock
tmpfs                 16453600      0   16453600   0% /sys/fs/cgroup
/dev/md0                483626  33904     424753   8% /boot
/dev/mapper/s6-var    16382888 188972   15338672   2% /var
/dev/mapper/s6-home  131980772  60984  125192520   1% /home
/dev/mapper/s6-tmp     1998672   3076    1874356   1% /tmp
s6:~# cd
s6:~# cd /
s6:/# rm -rf usr.old var.old
s6:/# 


s6:~# mount /dev/mapper/s6-root /mnt/root
s6:~# cd /mnt/root/etc
s6:/mnt/root/etc# vi fstab
s6:/mnt/root/etc# cat fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/md2 during installation
#UUID=4bc2886a-8a07-4fd1-b96e-8b50350651ad /               ext4    errors=remount-ro 0       1
/dev/mapper/s6-root     /               ext4    errors=remount-ro,grpquota,usrquota,nodiratime,noatime                          0       1

# /boot was on /dev/md0 during installation
UUID=2f7df835-4bc0-4635-9706-98715cc9fe42 /boot           ext2    defaults        0       2

# Logical volumes
/dev/mapper/s6-tmp /tmp ext4 defaults 0 0 
/dev/mapper/s6-home /home ext4 defaults 0 0 

# Swap changed to two partitions
UUID=abdbf3a3-bc1d-468f-b5bc-70512971d6d5 none            swap    sw              0       0
UUID=76f73c9c-7aa3-47f0-8478-2f0a4f280b0c none            swap    sw              0       0