Как переместить Linux в другой раздел?

9
задан 31 August 2011 в 09:24
4 ответа

Чтобы ответить на фактический вопрос относительно cpio : Вот флаги, которые я бы использовал для cpio :

find / -xdev -depth \! -path ./lost+found -print0 | cpio --pass-through --null --dot --make-directories --unconditional --preserve-modification-time --sparse /mnt/sdb5

Конечно, поскольку вы не копируя по сети, я бы просто использовал cp :

cp --archive --sparse=always --verbose --one-file-system --target-directory=/mnt/sdb5 /

И если вы хотите иметь возможность копировать несколько раз, rsync - лучший выбор из-за его возможностей возобновления . (Он также, как и cp , обрабатывает списки управления доступом и расширенные атрибуты и может опционально работать по сети, например cpio . Так что это наиболее полезный вариант, за исключением создания первой копии локально, которая Я предпочитаю использовать cp .)

rsync --archive --inplace --hard-links --acls --xattrs --devices --specials --one-file-system --8-bit-output --human-readable --progress / /mnt/sdb5

Не забудьте скопировать / boot и / dev !

/ boot - это легко, просто скопируйте это. Но / dev в наши дни намного сложнее, так как ' скрыт udev . Я рекомендую следующую процедуру:

  1. mkdir / tmp / dev
  2. mount --move / dev / tmp / dev
  3. Скопируйте / dev в / mnt / sdb5 используя одну из приведенных выше команд
  4. mount --move / tmp / dev / dev
  5. rmdir / tmp / dev
10
ответ дан 2 December 2019 в 22:22

Как упоминал @Klox, при копировании разделов одинакового размера я соглашаюсь использовать dd .

Но если вы хотите скопировать диск на другой раздел с другого размера, я бы предпочел rsync . Смонтируйте новый раздел (скажем, / mnt / new) и:

# rsync -a --exclude=/proc --exclude=/dev --exclude=/sys / /mnt/new

Никакой дополнительной магии для символических ссылок и никакого live cd (single user / init 1 подойдет).

6
ответ дан 2 December 2019 в 22:22

The more optimal variant of dd is using partimage, it will copy only the used section of the partition making copying of large unused partitions more expedient.

Note the important caveat:

Partimage does NOT support Ext4 which is the default on new Ubuntu installations.

A convenient copy is included on the System Rescue CD distribution.

3
ответ дан 2 December 2019 в 22:22

When moving Linux installations between hard drives, I always boot from a Live CD and use dd to copy the entire partition. I recognize that this doesn't deal with changes in disk size (inevitably the new disk is bigger, which simplifies things), but I like the technique for exactly the reasons you are concerned about using cpio: something may go wrong. Using the dd technique, it's all or nothing: either the new disk boots and everything is the same, or the disk doesn't boot. There's no risk of lurking problems popping up later.

Now, of course, there's the issue of the partition not filling the new disk, but I'd rather just create a new partition to fill the extra space and rely on symlinks to move directories around. (I'm sure there's tools for resizing partitions, too, but I haven't used them.)

2
ответ дан 2 December 2019 в 22:22

Теги

Похожие вопросы