You are not logged in.
Pages: 1
Hello,
My hard drive sometimes fails to be recognized at boot, so it's time to replace it. I have another HDD, but I'm not sure how I should proceed...
I have two disks:
- one SSD (/dev/sda), not encrypted; it contains my /root partition (ext4);
- one HDD (/dev/sdb) with LVM, encrypted with LUKS; it contains my swap and /home partitions.
Here is the code that I used when I installed Arch for the first time (yes, I wrote it down a few years ago):
parted
select /dev/sda
mklabel msdos > Yes
mkpart primary ext4 1MB 85GB
set 1 boot on
quit
gdisk /dev/sdb (to create 1 big "Linux LVM" partition)
cryptsetup luksFormat -v -y -s 512 -h sha512 /dev/sdb1
cryptsetup luksOpen /dev/sdb1 lvm
pvcreate /dev/mapper/lvm
vgcreate vgroup /dev/mapper/lvm
lvcreate -n lv_swap -L 4G -C y vgroup
lvcreate -n lv_home -l 100%FREE vgroup
mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/mapper/vgroup-lv_home
mkswap /dev/mapper/vgroup-lv_swap
mount /dev/sda1 /mnt
mkdir /mnt/home
mount /dev/mapper/vgroup-lv_home /mnt/home/
swapon /dev/mapper/vgroup-lv_swap
pacstrap /mnt/ base linux linux-firmware lvm2 etc...Now, I want to add my new hard drive and transfer all my /home data into it. How can I do that? I mean: I need to:
- have access to my old /home partition, which is encrypted using a passphrase;
- create a new /home partition on my new hard drive -> won't it conflict with the previous one?
- encrypt this new /home partition using the same passphrase as before;
- transfer all the data;
- remove the old HDD? Can I simply do that?
I'd need a detailed explanation to be sure that I won't lose anything in the process...
Thanx a lot for any help!
Last edited by LithoUser (2022-04-19 04:29:10)
Offline
I'd need a detailed explanation to be sure that I won't lose anything in the process...
always have multiple backups if your data is important!
https://wiki.archlinux.org/title/Rsync
as for what your trying to do, its pretty much just a backup which you mount in the place of your old hdd.
-install the new drive into the machine
-repeat steps taken in your above post to partition and encrypt the disk
-mount the new disk to "/mnt/new" or similar
-rsync your /home to /mnt/new
-update fstab/crypttab so the new drive is mounted to /home, and the new swap obviously
-remove old drive from system
Offline
/dev/sda - your current drive
/dev/sdc - your backup drive which has at least as many GBs as your current drive
sudo dd if=/dev/sda of=/dev/sdc conv=noerror status=progressyou can than swap sda and sdc as you will have an exact copy of data on both drives
Offline
Thanks for your answers!
always have multiple backups if your data is important!
I do have a backup of all my important data (but my NAS drive isn't big enough to have a backup of *everything*).
sudo dd if=/dev/sda of=/dev/sdc conv=noerror status=progress
I don't think I can do that, since my new drive won't be encrypted... am I wrong?
jonno2002 > I'd like to follow your instructions, but you say: "update fstab/crypttab so the new drive is mounted to /home, and the new swap obviously"
My fstab contains the following lines:
/dev/sda1 / ext4 rw,relatime 0 1
/dev/mapper/vgroup-lv_home /home ext4 rw,relatime 0 2
/dev/mapper/vgroup-lv_swap none swap defaults 0 0So when should I create those lvm groups on my new hard drive? And should I name them differently? Or can I use the same group names as before?
Offline
the DD method WILL keep your encrypted drive, it will make an identical copy of your drive, i dont like using this method but it will work.
yes keep the all the groups the same, you should only have to change the UUID in the crypttab, depends what your setup is
Offline
OK, I understand better what DD does, thanks for the explanation.
However, since I have random failures (because of the HDD, which sometimes isn't recognized anymore while I'm working) I'd prefer to use your method so that I can copy one folder at a time.
There's still one thing that I don't understand though; if I follow what you said, I think I should do this:
gdisk /dev/sdc (to create 1 big "Linux LVM" partition)
cryptsetup luksFormat -v -y -s 512 -h sha512 /dev/sdc1
cryptsetup luksOpen /dev/sdc1 lvm
pvcreate /dev/mapper/lvm
vgcreate vgroup /dev/mapper/lvm
lvcreate -n lv_swap -L 4G -C y vgroup
lvcreate -n lv_home -l 100%FREE vgroup
mkfs.ext4 /dev/mapper/vgroup-lv_home
mkswap /dev/mapper/vgroup-lv_swap
mount /dev/sda1 /mnt
mkdir /mnt/home
mount /dev/mapper/vgroup-lv_home /mnt/home/
swapon /dev/mapper/vgroup-lv_swapBut if I keep all the groups the same, what happens with "pvcreate /dev/mapper/lvm"? Won't it be applied to my old disk? Same problem with "mkfs.ext4 /dev/mapper/vgroup-lv_home": since "/dev/mapper/vgroup-lv_home" points to my /home partition in my /etc/fstab file, won't it format my *current* /home partition? I'm pretty much sure that there's still something that I don't understand...
Last edited by LithoUser (2022-04-16 04:07:57)
Offline
yea sorry of course they would conflict, just make them different then and update crypttab/fstab accordingly.
Offline
My crypttab is empty (it contains only a few comments).
So, my previous code was wrong; and I use grub as a bootloader, so I should edit its config file too.
To sum it up, I think I should go with:
gdisk /dev/sdc (to create 1 big "Linux LVM" partition)
cryptsetup luksFormat -v -y -s 512 -h sha512 /dev/sdc1
cryptsetup luksOpen /dev/sdc1 lvm_new
pvcreate /dev/mapper/lvm_new
vgcreate vgroup_new /dev/mapper/lvm_new
lvcreate -n lv_swap_new -L 4G -C y vgroup_new
lvcreate -n lv_home_new -l 100%FREE vgroup_new
mkfs.ext4 /dev/mapper/vgroup_new-lv_home_new
mkswap /dev/mapper/vgroup_new-lv_swap_new
mkdir /mnt/home_new
mount /dev/mapper/vgroup_new-lv_home_new /mnt/home_new/
swapon /dev/mapper/vgroup_new-lv_swap_newAnd then:
- I rsync everything from my old drive to my new one;
- then I edit my fstab;
- then I edit /etc/default/grub;
- reboot;
- and then I can unplug my old HDD.
Does this sound good?
Last edited by LithoUser (2022-04-16 05:27:42)
Offline
ok so you use grub to open the luks container then ? like i said i dont know your config but it sounds like youve got the idea
Offline
Good, thanks for your help! I'll do this in a few days when I have more time, and will report here ![]()
There's still something that bothers me though : copying everything from one disk to the other will take some time; I'll probably need to do it in several times, and to turn of my computer from time to time. So: how could I keep access to *both* disks? If I add the infos about my new partitions to my /etc/fstab instead of replacing the old ones, will it be enough? I don't think so; I think I should also add one line to my /etc/default/grub file to be able to access both disks on boot... am I right?
So, currently there is the following line in /etc/default/grub:
GRUB_CMDLINE_LINUX="cryptdevice=/dev/sdb1:vgroup"Can I simply add a second line like this:
GRUB_CMDLINE_LINUX="cryptdevice=/dev/sdc1:vgroup_new"Is it really possible to have two "GRUB_CMDLINE_LINUX" in this file?
Offline
you should really be using the crypttab for non-root filesystems
Offline
I've successfully mounted my new drive, but I encounter a new problem: how can I copy my data to my new disk while keeping the same attributes (permissions/user/group)? If I do something like this:
sudo rsync -rltDv /home/me/images /mnt/home_new/me/imagesthen the files are owned by "root", and the permissions are not the same. So which command should I use to create the folders, and to copy them from my old drive to my new one?
Offline
man rsync, search for --archive.
Offline
Yes, that did the job! Problem solved, thank you very much everyone!
you should really be using the crypttab for non-root filesystems
Yes! Furthermore, now I'd like to use the same key to decrypt my two hard drives (the old one and the new one) and keep using my old drive for unimportant stuff until it's completely dead, so I'll do need crypttab. Thanx for the link in the wiki, too!
Offline
Pages: 1