convert_root_to_lvm_partition

Convertir root (/) a LVM

Esto nunca funcionó!!

Terminé reinstalando Ubuntu (no venía mal) y habilitando LVM para agregar otro SSD. Llegué hasta el bind mount para crear el initramfs. Tal vez otro día lo retome usando una VM en vez de hacerlo sobre la PC principal.

Se puede crear una partición lógica con fdisk

fdisk
  • n → new partition
  • e → extended
  • usar todo el espacio (o lo que haga falta)

Dentro de la extendida se puede crear la partición lógica

  • n → new partition
  • l → logical
  • todo el espacio

lsblk debería mostrar 3 niveles el /dev/sdx, y adentro las 2 particiones, que en realidad están superpuestas (fdisk y parted pueden mostrar esto) Supongamos que se crearon dentro del disco /dev/sdc las particiones sdc1 como extndida y sdc5 la lógica

NO es necesario crear la partición, pvcreate puede usar discos enteros.

pvcreate initializes PhysicalVolume for later use by the Logical Volume Manager (LVM). Each PhysicalVolume can be a disk partition, whole disk, meta device, or loopback file. For DOS disk partitions, the partition id should be set to 0x8e using fdisk(8), cfdisk(8), or a equivalent. For whole disk devices only the partition table must be erased, which will effectively destroy all data on that disk. This can be done by zeroing the first sector with:

dd if=/dev/zero of=PhysicalVolume bs=512 count=1

Para crear el LV

Crear el volumen físico en la partición o disco

# pvcreate /dev/sdc

crear el VolumeGroup

# vgcreate vg_new_root /dev/sdc 

crear el volumen lógico

# lvcreate -L 300G -n lv0 vg_new_root

formatear… en este caso uso ext4

# mkfs.ext4 /dev/vg_new_root/lv0 

crear una carpeta para montar ese lv

# mkdir /mnt/ssd

montar

# mount /dev/vg_new_root/lv0 /mnt/ssd/ 

lsblk queda así

...
sdc                 8:32   0 447,1G  0 disk 
└─vg_new_root-lv0 253:0    0   300G  0 lvm  /mnt/ssd

Copiar ''/'' a la nueva partición

copiar los contenidos de / a la nueva unidad. Puedo usar cp pero voy a usar rsync

rsync -avxHAX --numeric-ids --progress / /mnt/ssd 

editar el nuevo fstab

# nano /mnt/ssd/etc/fstab 

debería quedar la línea que hace referencia a / así y comentar la anterior

/dev/vg_new_root/lv0      /       ext4    defaults     1 1 

hacer un bind mount entre lo actual y lo que se copió

mount --bind / /mnt/ssd/ 

A bind mount is an alternate view of a directory tree. Classically, mounting creates a view of a storage device as a directory tree. A bind mount instead takes an existing directory tree and replicates it under a different point. The directories and files in the bind mount are the same as the original. Any modification on one side is immediately reflected on the other side, since the two views show the same data.

For example, after issuing the Linux command-

mount –bind /some/where /else/where

the directories /some/where and /else/where have the same content, which is the content of /some/where. (If /else/where was not empty, its previous content is now hidden.)

Unlike a hard link or symbolic link, a bind mount doesn't affect what is stored on the filesystem. It's a property of the live system.

we have to change the root to the new file system, followed by creating initrd with raid as well as lvm support tocar el nuevo direectrio con chrooot

# chroot /mnt/ssd/ 

A chroot is an operation that changes the apparent root directory for the current running process and their children. A program that is run in such a modified environment cannot access files and commands outside that environmental directory tree. This modified environment is called a chroot jail.

# mount -t proc /proc /proc 
# mount -t sysfs /sys /sys 
vgscan 
vgchange -ay 
mkinitramfs -o /boot/initrd-`uname -r`.lvm.img `uname -r` 
umount /sys
umount /proc

volver a la nornalidad, fuera de chroot

exit 
update-grub 
reboot 

Para borrar el LV

desactivar el LV

 lvchange -an /dev/vg_new_root/lv0

borrar lvm

lvremove /dev/vg_new_root/lv0 

borrar el grupo

vgremove vg_new_root 

borrar el physical volume

pvremove /dev/sdc5 

si hay que borrar absolutamnete todo, wipefs

wipefs -a /dev/sdc 
convert_root_to_lvm_partition.txt · Last modified: 2024/10/17 21:42 by 127.0.0.1