将文件移动到正确的位置

将文件移动到正确的位置

在阅读这篇文章时,您可能会觉得这个问题之前已被问过很多次,但考虑到所有这些帖子中不同类型的情况,我不太确定应该遵循哪组说明,所以我希望您能在这里帮助我。

在安装 Ubuntu(值得信赖)时,我将 /(约 10GB)和 /home(约 230GB)放在不同的分区上。但直到今天我才意识到,在 / 开始迅速耗尽空间后,我当前的主目录(/home/navneeth)位于 / 分区内,而单独的主目录(/media/navneeth/a7775a8b-8cbd-445b-a05d-284226b3c3aa/navneeth)实际上是空的。那么,我应该如何将文件从第一个分区移动到第二个分区,而不会导致所有应用程序配置出错?

https://askubuntu.com/a/473923/422985似乎是最简单的解决方案。它会起作用吗?有没有更“干净”的方法?我想知道是否有办法让正确的主目录从此成为“首选”主目录。

系统信息:

navneeth@home:/boot$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda7       9.3G  8.8G   62M 100% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            994M  4.0K  994M   1% /dev
tmpfs           201M 1008K  200M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none           1003M  512K 1003M   1% /run/shm
none            100M   56K  100M   1% /run/user

navneeth@home:~$ sudo fdisk -l

Disk /dev/sda: 300.1 GB, 300067970560 bytes
255 heads, 63 sectors/track, 36481 cylinders, total 586070255 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd6edd6ed

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63   114688034    57343986    7  HPFS/NTFS/exFAT
/dev/sda3       114690046   586070015   235689985    5  Extended
/dev/sda5       582070272   586070015     1999872   82  Linux swap / Solaris
/dev/sda6       134690816   582070271   223689728   83  Linux
/dev/sda7       114690048   134688767     9999360   83  Linux

Partition table entries are not in disk order

navneeth@home:/boot$  sudo du -hs /*
[sudo] password for navneeth: 
9.3M    /bin
63M /boot
4.0K    /cdrom
4.0K    /dev
13M /etc
3.9G    /home
0   /initrd.img
0   /initrd.img.old
389M    /lib
16K /lost+found
8.0K    /media
4.0K    /mnt
356M    /opt
du: cannot access ‘/proc/1948/task/1998/fdinfo/43’: No such file or directory
du: cannot access ‘/proc/1948/task/1998/fdinfo/80’: No such file or directory
du: cannot access ‘/proc/1948/task/2074/fd/81’: No such file or directory
du: cannot access ‘/proc/7123/task/7123/fd/3’: No such file or directory
du: cannot access ‘/proc/7123/task/7123/fdinfo/3’: No such file or directory
du: cannot access ‘/proc/7123/fd/3’: No such file or directory
du: cannot access ‘/proc/7123/fdinfo/3’: No such file or directory
0   /proc
208K    /root
du: cannot access ‘/run/user/1000/gvfs’: Permission denied
1.6M    /run
12M /sbin
4.0K    /srv
0   /sys
40K /tmp
3.5G    /usr
518M    /var
0   /vmlinuz
0   /vmlinuz.old

答案1

/dev/sda6根据块数,我假设您要使用的当前未使用的 230G /home 分区。这应该可行:

$ cd /
$ sudo mkdir /media/home_backup
$ sudo mount /dev/sda6 /media/home_backup

# below, -rp flags indicate recursive, and keep owner/permissions

$ sudo cp -rp /home/* /media/home_backup

$ sudo umount /media/home_backup
$ sudo mv /home /home.bak
$ sudo mkdir /home
$ sudo mount /dev/sda6 /home

# the large partition should be mounted at /home now. The following
# will make sure it's mounted at boot

$ sudo umount /home

# edit /etc/fstab as sudo, and add the following to the bottom
# of the file (tab separate each entry)

/dev/sda6 /home ext4 default 0 2

# save the file and then:

$ sudo mount -a

如果最后一个命令有效并且您可以列出 /home 分区,则它将在启动时成功挂载。

相关内容