Skip to content
Snippets Groups Projects
Commit 29a5c774 authored by nimrod's avatar nimrod
Browse files

fixup! New post on copying the drive on a running machine.

parent d0a12162
No related branches found
No related tags found
No related merge requests found
Pipeline #3914 passed
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
Copy a drive on a running machine Copy a drive on a running machine
################################# #################################
:date: 2024-06-08 :date: 2024-06-08
:summary: Copying to a new drive while the machine is running :summary: Copying from an old drive to a new drive while the machine is running
I was close to running out of disk space the homelab machine I use for running I was close to running out of disk space on the homelab machine I use for
services with personal data that I run in my home (I feel more comfortable running services with personal data that I run in my home (I feel more
having physical control). I was too lazy to connect the machine to a monitor comfortable having physical control). I was too lazy to connect the machine to
and keyboard and rebooting from a thumbdrive so I tried to copy the old drive a monitor and keyboard and reboot from a thumbdrive so I tried to copy the old
to a new drive while the machine was running. Here's what I did: drive to a new drive while the machine was running. Here's what I did:
#. Stop running processes that have open files. For me it was stopping Docker #. Stop running processes that have open files. For me it was stopping Docker
containers, some services (I have most services running in containers so I containers, some services (I have most things running in containers so most
have few services). of the services are ones that come with a standard OS installation).
.. code:: shell .. code:: shell
...@@ -21,7 +21,7 @@ to a new drive while the machine was running. Here's what I did: ...@@ -21,7 +21,7 @@ to a new drive while the machine was running. Here's what I did:
#. :code:`cd` to a directory on a different drive to avoid keeping the path #. :code:`cd` to a directory on a different drive to avoid keeping the path
open :code:`cd /tmp`. Remount all partitions as read-only: :code:`sudo mount open (:code:`cd /tmp`). Remount all partitions as read-only: :code:`sudo mount
--all -o remount,ro -t vfat,btrfs,ext4`. This may fail and you will see an --all -o remount,ro -t vfat,btrfs,ext4`. This may fail and you will see an
error with a path that couldn't be remounted due to open files. Run error with a path that couldn't be remounted due to open files. Run
:code:`lsof /path/that/has/open/files`, find the processes that still have :code:`lsof /path/that/has/open/files`, find the processes that still have
...@@ -36,14 +36,14 @@ to a new drive while the machine was running. Here's what I did: ...@@ -36,14 +36,14 @@ to a new drive while the machine was running. Here's what I did:
#. Once the copy is complete, run :code:`sudo sync` again and :code:`echo 1 | #. Once the copy is complete, run :code:`sudo sync` again and :code:`echo 1 |
sudo tee /sys/block/nvme0n1/device/rescan`. Now we need to resize the data sudo tee /sys/block/nvme0n1/device/rescan`. Now we need to resize the data
partition, `sudo parted /dev/nvme0n1 --script resizepart 3 100%` (in my case partition, :code:`sudo parted /dev/nvme0n1 --script resizepart 3 100%` (in
the data partition was the 3rd partition after the EFI and root partitions). my case the data partition was the 3rd partition after the EFI and root
Open the encrypted partition :code:`sudo cryptsetup open /dev/nvme0n1p3 partitions). Open the encrypted partition :code:`sudo cryptsetup open
_dev_nvme0n1p2` and resize the encrypted partition :code:`sudo cryptsetup /dev/nvme0n1p3 _dev_nvme0n1p2` and resize the encrypted partition
resize _dev_nvme0n1p3`. Last resize is the filesystem in the encrypted :code:`sudo cryptsetup resize _dev_nvme0n1p3`. Last resize is the filesystem
partition, we mount it :code:`sudo mount /dev/mapper/_dev_nvme0n1p3 /mnt` in the encrypted partition, we mount it :code:`sudo mount
and resize it :code:`sudo btrfs filesystem resize max /mnt`. Umount the data /dev/mapper/_dev_nvme0n1p3 /mnt` and resize it :code:`sudo btrfs filesystem
partition :code:`sudo umount /mnt`. resize max /mnt`. Umount the data partition :code:`sudo umount /mnt`.
#. Let's reinstall the boot loader. #. Let's reinstall the boot loader.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment