Moving partitions between drives

In this guide we will show you how to move your partition from an HDD to SSD or vice versa.

We will assume that you currently have a Dedicated server which contains multiple drives.

[root@u18162509 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             4.0G  2.9G  1.1G  73% /
/dev/mapper/vg00-usr  4.8G  4.8G     0 100% /usr
/dev/mapper/vg00-var  201G  184G  8.3G  96% /var
/dev/mapper/vg00-home
                      4.8G   10M  4.6G   1% /home
/dev/mapper/hdd-data  3.9G  8.0M  3.7G   1% /data
[root@u18162509 /]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda3  vg00 lvm2 a--u 216.99g    0
  /dev/sdb1  hdd  lvm2 a--u   3.42t 3.42t

As you can see there are 2 separate volumes named vg00 and hdd.

Going forward you have 2 options.

Option 1). Your server only contains drives of a similar speed (HDD).

1). vi /etc/fstab, remove the following line.

/dev/hdd/data   /data           ext4    defaults,usrquota,noatime       0 2

2). umount /data

3). lvremove /dev/hdd/data

4). vgmerge vg00 hdd

5). pvs

[root@u18162509 /]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda3  vg00 lvm2 a--u 216.99g    0
  /dev/sdb1  vg00 lvm2 a--u   3.42t 3.42t

6). lvextend -L +5G /dev/mapper/vg00-usr

7). resize2fs /dev/mapper/vg00-usr

8). df -h

[root@u18162509 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             4.0G  2.9G  1.2G  72% /
/dev/mapper/vg00-usr   10G  4.8G  5.4G  48% /usr
/dev/mapper/vg00-var  201G  184G  8.3G  96% /var
/dev/mapper/vg00-home
                      4.8G   10M  4.6G   1% /home

Option 2). One drive is faster (SSD) then the large main drive (HDD).

On servers with drives of different performance levels we do not want to merge the volumes. Instead we will copy a partition from the smaller drive to the larger one (SSD to HDD). In this example we will be migrating /var

1). Reboot into Linux rescue

2). Mount your partitions to /mnt

3). rsync -avxHAX –progress /mnt/var/ /mnt/data/

4). vi /mnt/etc/fstab

Remove:

/dev/hdd/data   /data           ext4    defaults,usrquota,noatime       0 2

Edit:

/dev/hdd/data   /var            ext4    defaults,usrquota,noatime       0 2

5). Reboot back into local.

Mohammed has written 63 articles

4 thoughts on “Moving partitions between drives

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>