我电脑上有两个硬盘驱动器。目前第二个驱动器被挂载为"/media/storage"。
我该如何将用户数据从"/home"移动到"/media/storage/home"?
我可以直接将数据移动过去然后简单地创建符号链接吗?
我该如何将用户数据从"/home"移动到"/media/storage/home"?
我可以直接将数据移动过去然后简单地创建符号链接吗?
为了避免在图形环境下工作时产生副作用,我们应该使用Ctrl+Alt+F1从终端执行所有移动HOME的操作。
sudo mkdir /mnt/tmp
sudo mount /dev/sdb1 /mnt/tmp
假设/sdb1是新的HOME分区
sudo rsync -avx /home/ /mnt/tmp
sudo mount /dev/sdb1 /home
/home
(你可以稍后再做,但那样你将不得不启动一个实时系统来查看旧的主目录)。sudo umount /home # unmount the new home first!
sudo rm -rf /home/* # deletes the old home
我们需要知道新分区的UUID,以便在fstab
条目中查看:
sudo blkid
fstab
文件。sudo nano /etc/fstab # or any other editor
UUID=<noted number from above> /home ext4 defaults 0 2
请注意选择适当的文件系统,例如如果是ext3格式,则选择ext3
重新启动后,您的/home
将位于新驱动器上,具有充足的空间。
usermod
这样的分发工具来完成此任务。 - LiveWireBT/mnt/tmp
吗? - e9t/mnt/tmp
的数据)。 - Takkatsudo blkid
sudo -H gedit /etc/fstab
并将这些行添加到其中
UUID=???????? /media/home ext4 defaults 0 2
????????
替换为预期的/home
分区的UUID号码。fstab
文件,然后输入以下命令:sudo mkdir /media/home
/home
到新的分区sudo rsync -aXS --progress --exclude='/*/.gvfs' /home/. /media/home/.
sudo diff -r /home /media/home -x ".gvfs/*"
sudo -H gedit /etc/fstab
/media/home
部分更改为简单地写成/home
,使其看起来像这样:UUID=???????? /home ext4 defaults 0 2
/home
移动到/old_home
中cd / && sudo mv /home /old_home && sudo mkdir /home
使用以下方法重新启动或重新挂载全部:
sudo mount -a
任务:
相关链接:
将所有必要的SATA和电源电缆插入您的硬盘。加载Ubuntu。
按键盘上的键并输入"Disks"。
"Disks"实用程序将被打开:
sudo mkfs.ext4 -L purple /dev/sdb # not sure with parameters
sudo mkfs.ext4 -L gold /dev/sdc # not sure with parameters
# Press CTRL+ALT+T and open a console.
# Check your /dev/sdb and /dev/sdc discs are visible:
lsblk
# Create directories for the new HDD WD Purple and WD Gold
sudo mkdir /hdd_purple
sudo mkdir /hdd_gold # temporary directory
# Temporary mount to the new mount point
sudo mount /dev/sdb1 /hdd_purple
sudo mount /dev/sdc1 /hdd_gold
# Unmount drives
sudo umount /dev/sdb1
sudo umount /dev/sdc1
# Configuration file /etc/fstab has list of all partitions that will be mounted at boot.
# 1. Show and copy UUID of the HDD with this command:
sudo blkid
# My data is:
# /dev/sdb1: LABEL="purple" UUID="6ce9ec1f-3bf5-420f-8502-1b4f55f2fc60" TYPE="ext4" PARTUUID="a14c8357-a8ce-42e4-9772-64ccfad3e226"
# /dev/sdc1: LABEL="gold" UUID="1d049c7c-4565-480b-a181-2459e8ff8c1b" TYPE="ext4" PARTUUID="4c691b21-b4e3-4dab-ab91-d7bf7272b2b5"
# Make a backup of that file to be able to revert changes.
sudo cp /etc/fstab /etc/fstab.2018.11.29.bak
# 2. Add a new partitions by editing /etc/fstab file as root:
sudo nano /etc/fstab
# 3. At the bottom of fstab file add 2 lines similar to this:
UUID=6ce9ec1f-3bf5-420f-8502-1b4f55f2fc60 /hdd_purple ext4 defaults 0 2
UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b /hdd_gold ext4 defaults 0 2
# Your UUID have to be different!
# Write the file with keys <Ctrl+O> then <Return>. Quit the editor with <Ctrl+X>.
# If you have Midnight Commander running, then save before quitting with <Ctrl+X>,
# because <Ctrl+O> will switch from nano editor to your MC.
# To see if the drive is mounted correctly we can simulate the mount process at boot with:
sudo mount -a
# To avoid side effects while working in a graphical, environment
# we should perform all actions to move HOME from a terminal with Ctrl+Alt+F3.
# Press <Ctrl+Alt+F3> and swidth to console mode.
# Login in the console mode.
# Copy HOME to the new location:
sudo rsync -avx /home/ /hdd_gold
# Delete everything in the HOME directory.
# Be careful with this command, make sure you have a backup.
rm -rf /home/*
# Make HOME permanent -- edit /etc/fstab configuration file
sudo nano /etc/fstab
# Change string
UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b /hdd_gold ext4 defaults 0 2
# to string
UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b /home ext4 defaults 0 2
# /hdd_golds change to /home directory
# After a reboot, your /home resides on the new drive having plenty of space.
sudo reboot
usermod -m -d /path/to/non_existent_home_dir username
命令,然后切换回你的账户(username),最后删除临时管理员用户。虽然这仍然是5个步骤,但比其他答案要少得多,风险也更小,步骤也更简单。 - Oliver