Partition-less root file system Centos 7

I have been on the quest over the last 6 months to create a completely scalable Centos VM template for deployments.. This is not only to save my precious after hours and weekend time but to provide better uptime to my customers… Today I have finally accomplished this and would like to share how you could make your own scalable VM… In this post I am only going to focus on / because I feel the rest of the volumes are fairly easy to handle with DD and can be done on the fly as it is. If you are just building a template.. I know there is going to be a bunch of LVM fan boy’s out there asking me “why not just use LVM?”… Well simple answer… LVM had its purpose on hardware … In the virtual world you can add disk space to the disk directly instead of adding a disk to a vol group; It was just the partitions holding us back from doing stuff on the fly and the linux installers never gave an option to place the OS on a raw disk. Any way here is how I accomplished this.

1. Add a small disk to the virtual machine (between 512mb/1gb) Make it SCSI(0:1)

2.  Reboot the machine

3.   Your new drive should now be /dev/sdb. Use the following commands to make it bootable and turn the old /boot off

 

[root@centos7x64 ~]# parted -s /dev/sdb 'mklabel msdos'
[root@centos7x64 ~]# parted -s /dev/sdb 'u s mkpart primary 2048 1048575'
[root@centos7x64 ~]# parted -s /dev/sdb 'set 1 boot on'
[root@centos7x64 ~]# parted -s /dev/sda 'set 1 boot off'

 

4. Create a filesystem and make it bootable

[root@centos7x64 ~]# mkfs.xfs -L boot /dev/sdb1

5. Make a copy of your fstab and add the new disk to fstab use the UUID you get from the last command run here to replace what you have next to /boot

[root@centos7x64 ~]# cp /etc/fstab /etc/fstab.orig
[root@centos7x64 ~]# blkid -o value -s UUID /dev/sdb1
bb659f0c-b85d-467f-a61f-f0d3657d446d

6. Mount  your new /boot disk and copy existing /boot directory over

[root@centos7x64 ~]# mount /dev/sdb1 /mnt
[root@centos7x64 ~]# tar -C /boot -cpf - . | tar -C /mnt -xpvf -

 

7. Unmount /boot and remount your new boot disk

[root@centos7x64 ~]# umount /mnt; mount /dev/sdb1 /boot

 

8. Update grub to give the grub the correct UUIDS

[root@centos7x64 ~] grub2-mkconfig -o /boot/grub2/grub.cfg

9. Shut down the VM and make your new boot disk SCSI 0:0 and the old root disk SCSI 0:1

10. Start the machine up and verify it boots properly. Use df to make sure you are booted on the appropriate disk. should be /boot  on /dev/sda1

/dev/sda1       508M  194M  315M  39% /boot

11. Power down the VM and add an additional hard disk to the machine for root(10-15gb should do).

12. Power the machine on

13. Create  a file system on the raw device

[root@centos7x64 ]# 
mkfs.xfs /dev/sdf
mke2fs 1.41.11 (14-Mar-2010)
/dev/sdd is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=root
OS type: Linux
...
...

14. Take note of your device names old root should be /dev/sdb your new root disk should be /dev/sdf at this point (its ok if its not like this at this point we will change it)

15. Go download a rescue disk and or live distro for the following. I used this Rescue CD

16. Mount the disk to the cd drive on the VM and reboot. Interrupt boot and boot from the disk.

17. Open terminal and mount our disks /dev/sdb1 and /dev/sdf and copy over the data

root@ubuntu:~# mkdir /mnt/sdb1
root@ubuntu:~# mkdir /mnt/sdf
root@ubuntu:~# mount /dev/sdb1 /mnt/sdb1
root@ubuntu:~# mount /dev/sdf /mnt/sdf
root@ubuntu:~# tar -C /mnt/sdb1 -cpf - . | tar -C /mnt/sdf -xpf -

18. Modify the fstab on the new /root disk (/dev/sdf in my case) the below will append the UUID to the fstab file just take the new uuid and replace the old / UUID with the new one.

root@ubuntu:~# cp /mnt/sdf/etc/fstab /mnt/sdf/etc/fstab.orig2
root@ubuntu:~# blkid -o value -s UUID /dev/sdb >> /mnt/sdf/etc/fstab
root@ubuntu:~# vi /mnt/sdf/etc/fstab

19.  Now that we have our new / disk copied and in fstab we once more need to update the grub2 config files to use the new UUIDS so we will need to mount our /dev/sda1 disk to get access to this information… There really isnt a pretty way to do this through the console so here is what I did …

root@ubuntu:~# mkdir /mnt/sda1
root@ubuntu:~# mount /dev/sda1 /mnt/sda1
root@ubuntu:~# blkid |grep /dev/sdb1
/dev/sdb1: UUID="3b130000-d0fa-4778-a973-fdaf1f2a4f51" TYPE="xfs" ## Old root
root@ubuntu:~# blkid |grep /dev/sdf/
dev/sdf: UUID="50fb9289-db06-4ca0-beb8-42797b96154d" TYPE="xfs"  ## New root
root@ubuntu:~# vi /mnt/sda1/boot/grub2/grub.cfg

20. inside Vi use the following

:%s/3b130000-d0fa-4778-a973-fdaf1f2a4f51/50fb9289-db06-4ca0-beb8-42797b96154d/g

:%s/OLDUUID/NEWUUID/g

21. Power down the machine and make sure your new /boot disk (the small one) is SCSI (0:0) and your new / disk is SCSI (0:1) and then power the VM back on. to verify functionality.

22. Make a clone of the machine at this point if it boots and leave it off just incase.. Remove the old root disk from the machine and hit ok… Then attempt to reboot.. If your machine goes FUBAR delete this machine and power on your clone and find the correct root disk to remove.


 

Leave a Reply

Your email address will not be published.