我希望得到一些帮助,将根分区从现有硬盘移动到新安装的 SSD。
该 PC 是 i7(Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz),配有 32GB RAM 和 2 x 2TB 5400rpm SATA 硬盘。它运行的是 Fedora 29 Linux。
新的 M.2 SSD 是:- /dev/nvme0n1 上的三星 SSD 970 EVO Plus 500GB。
/dev/sda 上的现有分区
Number Start (sector) End (sector) Size Code Name
1 2048 411647 200.0 MiB EF00 EFI System Partition
2 411648 2508799 1024.0 MiB 8300 Linux filesystem
3 2508800 3907028991 1.8 TiB 8E00 Linux LVM
/etc/fstab 文件
UUID=486b1d3d-c426-4ce6-a5ac-0f7109e4d463 /boot ext4 defaults 1 2
UUID=ACA0-FA79 /boot/efi vfat umask=0077,shortname=winnt 0 2
/dev/mapper/fedora_localhost--live-root / ext4 defaults 1 1
/dev/mapper/fedora_localhost--live-home /home ext4 defaults 1 2
/dev/mapper/fedora_localhost--live-swap swap swap defaults 0 0
# df -h 输出(减去一些 tmpfs 条目)
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_localhost--live-root 49G 16G 32G 34% /
/dev/sda2 976M 202M 708M 23% /boot
/dev/sda1 200M 18M 182M 9% /boot/efi
/dev/mapper/fedora_localhost--live-home 1.8T 88G 1.6T 6% /home
tmpfs 16G 80K 16G 1% /tmp
建议设置
从我迄今为止的研究来看,以下分区方案似乎是可行的。
ssd / 200G (New LVM volume or partition)
sda1 /boot/efi 200M (existing partition)
sda2 /boot 976M (existing partition)
LVM /home 1.8T (existing volume on hdd - may shrink this a bit)
LVM /var 49G (re-use old root LVM volume on hdd)
我的问题
使用 LVM 命令是否最好?如果是,请建议命令和开关。我以前从未做过任何 LVM 操作。
而且由于我没有使用所有 SSD,LVM 分区是否应该消耗整个 SSD?
如果 LVM 命令不是最好的,那么标准格式的分区是否使用 cp -a??? 或 rsync 来复制文件是否合适,以及如何保持权限和设备完好无损?
笔记
我意识到 /etc/fstab 将需要根卷的新条目。
我有(并计划使用)一个 knoppix 实时系统 dvd 来在主机文件系统离线时完成工作。
如果您认为一种方法更有利于延长 SSD 寿命,请添加您的评论。
谢谢
答案1
我正在回答我自己的问题,因为在对 LVM 进行大量研究并使用各种方法移动根分区之后,我决定使用 LVM 来完成这项工作。事实证明,使用 LVM(在 Fedora 29 上)非常简单。以下是我所做的。
在 SSD 上创建 LVM 物理卷。
$ sudo pvcreate /dev/nvme0n1 -v
Wiping signatures on new PV /dev/nvme0n1.
Set up physical volume for "/dev/nvme0n1" with 976773168 available sectors.
Zeroing start of device /dev/nvme0n1.
Writing physical volume data to disk "/dev/nvme0n1".
Physical volume "/dev/nvme0n1" successfully created.
现在将新的 PV 加入到卷组 (VG)。
$ sudo vgextend fedora_localhost-live /dev/nvme0n1
*(sorry missed the output of this one)*
然后使用 USB 闪存驱动器上的 SystemRescueCd(我使用的是 v6.0.3)重新启动 PC。我也可以从此救援磁盘执行上述 pvcreate 和 vgextend,我认为这并不重要。
现在需要做的就是移动带有 LVM 的分区并检查它。
# pvmove -n root /dev/sda3 /dev/nvme0n1
Daemon lvmpolld returned error 104
WARNING: Failed to connect to lvmpolld. Proceeding with polling without using lvmpolld.
WARNING: Check global/use_lvmpolld in lvm.conf or the lvmpolld daemon state.
/dev/sda3: Moved: 100.00%
(不确定这些警告是什么,但这并没有影响我所能看到的任何内容。)
# lvs -o+devices
LV VG Attr LSize Pool ...... Devices
home fedora_localhost-live -wi-a----- 1.75t /dev/sda3(4027)
root fedora_localhost-live -wi-a----- 50.00g /dev/nvme0n1(0)
swap fedora_localhost-live -wi-a----- 15.73g /dev/sda3(0)
所以根分区现在在 SSD 上。
只是检查物理与逻辑的关系......
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 200M 0 part
├─sda2 8:2 0 1G 0 part
└─sda3 8:3 0 1.8T 0 part
├─fedora_localhost--live-swap 253:0 0 15.7G 0 lvm
└─fedora_localhost--live-home 253:1 0 1.8T 0 lvm
nvme0n1 259:0 0 465.8G 0 disk
└─fedora_localhost--live-root 253:2 0 50G 0 lvm /mnt/fedoraRoot
现在是时候重新启动 Fedora 并再次检查结构了。顺便说一句,我在研究这个问题时使用了以下命令,发现它们非常有用。
$ sudo pvdisplay -m
--- Physical volume ---
PV Name /dev/sda3
VG Name fedora_localhost-live
PV Size <1.82 TiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 476625
Free PE 12800
Allocated PE 463825
PV UUID OktYlV-PYVx-A5AW-8TEs-Nz84-KDGz-F03Qz0
--- Physical Segments ---
Physical extent 0 to 4026:
Logical volume /dev/fedora_localhost-live/swap
Logical extents 0 to 4026
Physical extent 4027 to 463824:
Logical volume /dev/fedora_localhost-live/home
Logical extents 0 to 459797
Physical extent 463825 to 476624:
FREE
--- Physical volume ---
PV Name /dev/nvme0n1
VG Name fedora_localhost-live
PV Size 465.76 GiB / not usable 4.02 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 119234
Free PE 106434
Allocated PE 12800
PV UUID 02mg6I-sXK9-eRL9-X1ho-AYx3-xKOW-GwdSDO
--- Physical Segments ---
Physical extent 0 to 12799:
Logical volume /dev/fedora_localhost-live/root
Logical extents 0 to 12799
Physical extent 12800 to 119233:
FREE
和逻辑卷。
$ sudo lvdisplay -m
--- Logical volume ---
LV Path /dev/fedora_localhost-live/swap
LV Name swap
VG Name fedora_localhost-live
LV UUID K1N4iT-2pRA-w4af-MUNC-NkLt-Fzo3-AWOMkt
LV Write Access read/write
LV Creation host, time localhost-live, 2018-07-25 08:39:49 +1000
LV Status available
# open 2
LV Size 15.73 GiB
Current LE 4027
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Segments ---
Logical extents 0 to 4026:
Type linear
Physical volume /dev/sda3
Physical extents 0 to 4026
--- Logical volume ---
LV Path /dev/fedora_localhost-live/home
LV Name home
VG Name fedora_localhost-live
LV UUID RLqeX2-lrMJ-Mcce-q9k0-VJ4P-oy7H-MMUuWV
LV Write Access read/write
LV Creation host, time localhost-live, 2018-07-25 08:39:49 +1000
LV Status available
# open 1
LV Size 1.75 TiB
Current LE 459798
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Segments ---
Logical extents 0 to 459797:
Type linear
Physical volume /dev/sda3
Physical extents 4027 to 463824
--- Logical volume ---
LV Path /dev/fedora_localhost-live/root
LV Name root
VG Name fedora_localhost-live
LV UUID SOseFb-5VaZ-kTxx-jgyM-0Z7E-Q9zF-RSXFOA
LV Write Access read/write
LV Creation host, time localhost-live, 2018-07-25 08:40:05 +1000
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Segments ---
Logical extents 0 to 12799:
Type linear
Physical volume /dev/nvme0n1
Physical extents 0 to 12799
看起来就是这样。一切都很好,机器很多启动和程序加载速度更快。