1

I created t2.medium instance and attached ebs volume to the instance

Here are some useful information.

sudo pvs

  PV         VG      Fmt  Attr PSize    PFree
/dev/xvdb1 vg_home lvm2 a--  <200.00g    0

sudo vgs

  VG      #PV #LV #SN Attr   VSize    VFree
vg_home   1   1   0 wz--n- <200.00g    0

sudo lvs

 LV      VG      Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_home vg_home -wi-a----- <200.00g

lsblk

NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                202:0    0   50G  0 disk
└─xvda1             202:1    0   50G  0 part /
xvdb                202:16   0  200G  0 disk
└─xvdb1             202:17   0  200G  0 part
  └─vg_home-lv_home 253:0    0  200G  0 lvm

lsblk -lf

NAME            FSTYPE      LABEL UUID                                   MOUNTPOINT
xvda
xvda1           xfs               0356e691-d6fb-4f8b-a905-4230dbe62a32   /
xvdb
xvdb1           LVM2_member       qSmSpW-MRuF-WrUE-jJL8-N182-xOgA-57kdkB
vg_home-lv_home xfs               b4fadb7e-714c-4cdd-a5dd-43df5ef19b84

So I need to mount vg_home-lv_home to /home directory.

I can mount this volume by running sudo mount /dev/vg_home/lv_home /home

Then its mounted. After that, I terminated my ssh session and try to ssh again. ssh -i <key> centos@<ec2_public_ip>. I can't ssh into ec2 instance, error is Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

It makes sense, because I mounted /dev/vg_home/lv_home to /home. and .ssh folder has gone from /home

Then I restarted the ec2 instance and I can ssh it again.

So my question is how can I mount xfs volume to /home directory?

I created a mountpoint /mnt/home and copied /home then unmounted from mnt/home and mounted to /home. Then I can't connected to ec2 instance at all (with restart).

So what is the best practice/method to mount a volume to ec2 instance /home directory?

-Thank you

3
  • You need to make sure you use cp -a to preserve permissions. You also likely need to temporary disable SELinux and set relabel the files in the new volume.
    – jordanm
    Commented Nov 14, 2017 at 0:54
  • hey @jordanm, I'm a newbie to Linux. could you please give me a reference (link/tutorial), please? Thank you
    – Gayan J
    Commented Nov 14, 2017 at 1:01
  • I just checked and cp -a alone should cover both permissions and SELinux context labels.
    – jordanm
    Commented Nov 14, 2017 at 1:05

1 Answer 1

1
  • Make temp directory to mount - sudo mkdir -p /srv/home
  • Mount - sudo mount /dev/vg_home/lv_home /srv/home
  • Copy file from home to temp directory - sudo cp -aR /home/* /srv/home/
  • Check the difference between two directories - diff -r /home /srv/home
  • Afterwards delete all the old content on the /home as follow - rm -rf /home/*
  • Umount from tempdir - sudo umount /srv/home
  • Mount to /home - sudo mount /dev/vg_home/lv_home /home
  • Delete temp mounted directory - sudo rm -r /srv/home/
  • edit /etc/fstab file - /dev/mapper/vg_home-lv_home /home xfs defaults 0 2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .