0

My Centos6x64 VM came has a ~500G disk xvda. Initially, 8G was allocated to xvda1 and mounted on /. The remainder of the 500G disk space in xvda was not yet allocated. So i decided to make this remainder disk space usable and created a partition xvda2 with logical volumes using fdisk, pvcreate, vgcreate, lvcreate, formatting and finally updating fstab to mounted them automatically.

The relationships to the corresponding folders (mount point) is:

  • /dev/centos/home ..../home [200G]
  • /dev/centos/root ..../ [100G]

Problem is:

  • The /home seem to have mounted correctly as size shown upon df -h is 197G.
  • But the mounting on root is not correct. In the results for df -h below, the size of /dev/xvda1 mounted on /boot is 7.8G which is correct. But, the size of /dev/mapper/centos-root mounted on / incorrectly shows 7.8G. It should show approximately 100G. It is incorrectly showing the same disk space as that of /dev/xvda1.

Questions:

  • I have tried to collate some results below for your reference. Kindly help resolve this problem. What can i do to correct the problem?
  • Also, if i just wanted to increase the disk space allocated to xvda1 from 8G to say 200G, is there a simpler more direct way? on googling, i found this post that very much matched the objective. But i could not get it to reboot successfully as it lay stuck on the grub screen. I don't have much info on this failure details. Could i have missed out some setup pre-requisites when using fdisk to allocate additional disk space eg: formatting?

I pretty much new on this and stuck. Please Kindly help.

Initial State of System:

# fdisk -l
Disk /dev/xvda: 536.9 GB, 536870912000 bytes 255 heads, 63 sectors/track, 65270 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000611ee
    Device      Boot    Start   End      Blocks   Id  System
    /dev/xvda1   *      1       1045     8387584   83  Linux
Disk /dev/xvdb: 32.2 GB, 32204390400 bytes 255 heads, 63 sectors/track, 3915 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000

# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  500G  0 disk
└─xvda1 202:1    0    8G  0 part /
xvdb    202:16   0   30G  0 disk /mnt

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  897M  6.5G  12% /
tmpfs           3.6G     0  3.6G   0% /dev/shm
/dev/xvdb        30G  173M   28G   1% /mnt

# cat /etc/fstab
UUID=2d0f2d55-672b-4c05-8eba-9421dd808ad7 / ext4    defaults 1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/xvdb       /mnt    auto    defaults,nofail,comment=cloudconfig     0 2

Steps i performed:

  • fdisk /dev/xvda ...(n > p = 2 > t = 8e)
  • reboot
  • pvcreate /dev/xvda2
  • vgcreate centos /dev/xvda2
  • lvcreate -n home -L 200G centos
  • lvcreate -n root -L 100G centos
  • lvcreate -n swap -L 4G cent
  • mkfs.ext4 /dev/centos/root
  • mkfs.ext4 /dev/centos/home
  • mkswap /dev/centos/swap
  • mount /dev/xvda1 /boot
    • ...This is what i want to do but was not permitted.
    • So instead, i updated /etc/fstab and changed mount point for /dev/xvda1 from / to /boot. But this also does not work.
      • In the results provided below, df -h shows the correct mount points for both /dev/xvda1 i.e. /boot and /dev/mapper/centos-root i.e. / but the disk space shown for /dev/mapper/centos-root = 7.8G is incorrect. I was expecting ~100G.
      • Also, the results for lsblk shows empty mount point for centos-root (dm-1). For centos-root, i expected mount point / and for /dev/xvda1 expected mount point /boot.
  • mount /dev/centos/root /
  • mount /dev/centos/home /home
  • make corresponding entries into /etc/fstab (refer cat /etc/fstab below)
  • shutdown -r now
  • mkhomedir_helper centos
    • On reboot, home dir for centos became inaccessible and so i got error "Could not chdir to home directory /home/centos: No such file or directory". To resolve, I had to run the above command to recreate home directory for user centos

cat /etc/fstab

UUID=3a75c67b-5053-4863-963e-c6a572f13972       /       ext4    defaults        1 1
UUID=2d0f2d55-672b-4c05-8eba-9421dd808ad7       /boot   ext4    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/xvdb       /mnt    auto    defaults,nofail,comment=cloudconfig     0 2
/dev/mapper/centos-home         /home              ext4    defaults     0 0

fdisk -l

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        1045     8387584   83  Linux
/dev/xvda2            1045       65270   515892667   8e  Linux LVM

df -h

Filesystem              Size  Used Avail Use%  Mounted on
/dev/mapper/centos-root 7.8G  898M  6.5G  12%  /
tmpfs                   3.6G     0  3.6G   0%  /dev/shm
/dev/xvda1              7.8G  898M  6.5G  12%  /boot
/dev/xvdb               30G   173M   28G   1%  /mnt
/dev/mapper/centos-home 197G   60M  187G   1%  /home

lsblk

NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                   202:0    0  500G  0 disk
├─xvda1                202:1    0    8G  0 part /
└─xvda2                202:2    0  492G  0 part
  ├─centos-home (dm-0) 253:0    0  200G  0 lvm  /home
  ├─centos-root (dm-1) 253:1    0  100G  0 lvm
  └─centos-swap (dm-2) 253:2    0    4G  0 lvm
xvdb                   202:16   0   30G  0 disk /mnt

blkid

/dev/xvda1: UUID="2d0f2d55-672b-4c05-8eba-9421dd808ad7" TYPE="ext4"
/dev/xvdb: UUID="3656cb72-7e94-4e63-81ea-66397ad45d13" SEC_TYPE="ext2" TYPE="ext3"
/dev/xvda2: UUID="ASXeKh-x8xL-nDVF-afzq-zU8a-sCbd-qGM6pS" TYPE="LVM2_member"
/dev/mapper/centos-home: UUID="4510891a-354d-4486-bd47-95d474f197bb" TYPE="ext4"
/dev/mapper/centos-root: UUID="3a75c67b-5053-4863-963e-c6a572f13972" TYPE="ext4"
/dev/mapper/centos-swap: UUID="5dff9552-3d36-4cfa-936c-28e02c1ae108" TYPE="swap"

lvdisplay

  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                lFWQxa-mqgc-Ur8t-npDc-O2NU-r6J4-UhC2j2
  LV Write Access        read/write
  LV Creation host, time ip-xx-xx-xx-xx.ec2.internal, 2018-06-16 07:18:22 +0000
  LV Status              available
  # open                 1
  LV Size                200.00 GiB
  Current LE             51200
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                UQ6oAD-JyRa-cb8l-VmgW-aZh9-qbof-Z1Z9af
  LV Write Access        read/write
  LV Creation host, time ip-xx-xx-xx-xx.ec2.internal, 2018-06-16 07:18:22 +0000
  LV Status              available
  # open                 0
  LV Size                100.00 GiB
  Current LE             25600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                QyY2z9-5EpX-D8dY-DORZ-9BbY-TqgA-07fc3X
  LV Write Access        read/write
  LV Creation host, time ip-xx-xx-xx-xx.ec2.internal, 2018-06-16 07:18:24 +0000
  LV Status              available
  # open                 0
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
  • Your output of df -h and lsblk are not in alignment. The former suggests / is an LVM logical volume while the latter suggests it's xvda1; Did you update your GRUB config to specify your new / block device? How did you populate your / logical volume; Perhaps you dd'ed the contents? – Emmanuel Rosa Jun 16 '18 at 15:46
  • What do you have in grub configuration? It looks like your centos/root is not taken into account as the / is already mounted to xvda1 on boot... you maybe should consider mounting this xvda2 to some other mount point to take advantage of it... – tonioc Jun 16 '18 at 17:20
  • @tonioc He can't mount xvda2 elsewhere because it contains the logical volumes including /home and swap. – Nasir Riley Jun 16 '18 at 17:55
  • If you have migrated the root filesystem from xvda1 to LV root of VG centos without rebooting, there may be some out-of-date information left in /etc/mtab which might be confusing the df command. If necessary, you can actually do cat /proc/mounts >/etc/mtab to update it, since you don't seem to have anything complicated going on with mounts. Before rebooting, be sure to update your initramfs so it will be up to date with the new situation (see man mkinitrd). – telcoM Jun 16 '18 at 19:41
  • @EmmanuelRosa - i did not update GRUB config. I updated the description, will that information add clarity to my problem?; @telcoM - i will try out your directions. Currently, reviewing at man mkinitrd; @tonioc, @NasirRiley, All - will the updated description help? what can i do to allocate more disk space to /. All:, i have updated the main description to include better clarity on initial state of system and the steps i performed. Hope this is helpful. Kindly help me out. Thanks a ton. – Bipo K Jun 17 '18 at 5:18
0

The filesystem you're trying to mount on /boot (/dev/xvda1) is really your /. So even if you get it to mount at the desired mount point it won't work because what you really want mounted there is the /boot directory inside of /dev/xvda1, and you can't mount directories within a filesystem.

You created the LVM logical volumes and filesystems for / and /home but did not put any data in them; You didn't migrate your existing filesystems to their new block devices.

In addition GRUB doesn't know about your new / filesystem, therefore it will try to boot from the original /. Here's an overview of what you can do to put those logical volumes to use:

WARNING

Before you do follow any of these steps make backups. Things may go horrible wrong, and the only good "undo button" is having backups.

The Safe Steps

  1. Reboot into single-user mode. You'll be copying a live filesystem, so you want as few things running as possible.
  2. Bind-mount your current / to a new location, such as a directory within your home directory.
  3. Mount your new / and /home logical volumes within your home directory as well.
  4. Copy your existing / using the bind mount and excluding /home to your new / logical volume. It's important that you use the bind mount as your copying source because it avoids copying other mounted filesystems; Everything is mounted somewhere under /.
  5. Copy your existing /home (again using the bind mount) to your new /home logical volume.
  6. Reboot and when the GRUB menu comes up select an appropriate kernel entry and press "e". This will put you in edit mode. Add/edit the variable realroot so that its value is /dev/mapper/centos-root. I'm making the assumption that your initrd has support for LVM. Then press ENTER.
  7. If all goes well your system will now boot from your root logical volume.

The Unsafe Steps

Now begins the steps which make it difficult to undo this process. This is where things can really go wrong. Bring out the Vodka (to celebrate latter, of course) and proceed:

  1. Mount your old / somewhere.
  2. Umount /boot
  3. Copy /boot from your old / to a directory in one of your logical volumes. You can even copy it into a tmpfs instead, if you dare. This will merely serve as a temporary backup for the next two steps.
  4. Here comes the point of no return: mkfs.ext4 /dev/xvda1. Your OS will no longer boot as-is.
  5. mount /dev/xvda1 /boot
  6. Populate /boot using the backup you made on step 3.
  7. Double-check the UUID for your /boot filesystem and update /etc/fstab if necessary.
  8. Now it's time to update GRUB2. Run grub-mkconfig | less and see if it's picked up the correct block devices. You should see the same realroot entry you manually added to get this far. If everything checks out, run grub-mkconfig -o /boot/grub/grub.cfg to write out the new GRUB configuration.
  9. Reboot. One of two things will happen: The system will boot successfully, or... it won't. Either way, this is when that Vodka comes in.
  • Thank you for the great details and I heed your warning. In parallel, i read this post How to resize ext4 root partition live without umount on Linux and though the initial state of system seem to be same it would not work for me. Please excuse me for cross referring but i am stuck and looking for the simplest option to allocate disk space to / at the least. Please help. – Bipo K Jun 19 '18 at 1:01
  • In the other post they increased the disk size and all they're doing is resizing the partition and the filesystem. Your case is different because you're going from a partition to a logical volume. Consequently, you can't perform the change without re-writing the filesystem; Hence the reason for the file copying. LVM is sure handy, but the moment you invoke it you leave the land of simple options. If all you really want is to use the entire disk for /, you can delete the LVM partition and then follow those instructions. – Emmanuel Rosa Jun 19 '18 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.