特殊:Badtitle/NS100:DDtoNFS:修订间差异

来自Ubuntu中文
跳到导航跳到搜索
Wikibot留言 | 贡献
新页面: {{From|https://help.ubuntu.com/community/DDtoNFS}} {{Languages|UbuntuHelp:DDtoNFS}} === How to dd to a NFS server === I bought a new hard drive for my laptop and just wanted to copy the o...
 
Wikibot留言 | 贡献
无编辑摘要
第3行: 第3行:
=== How to dd to a NFS server ===
=== How to dd to a NFS server ===
I bought a new hard drive for my laptop and just wanted to copy the old disk to the new one because I didn't feel like installing everything again. On a desktop box that's pretty easy, just put the new disk in together with the old one and use dd to copy it across. Most laptops can only take one disk so that won't work. I have a NFS server with enough space to hold the laptop disk but NFS won't allow root to write on a NFS mounted directory and dd won't work as a normal user. This is how I did it.
I bought a new hard drive for my laptop and just wanted to copy the old disk to the new one because I didn't feel like installing everything again. On a desktop box that's pretty easy, just put the new disk in together with the old one and use dd to copy it across. Most laptops can only take one disk so that won't work. I have a NFS server with enough space to hold the laptop disk but NFS won't allow root to write on a NFS mounted directory and dd won't work as a normal user. This is how I did it.
Boot from the *ubuntu Live CD with the old disk in the laptop.  
Boot from the *ubuntu Live CD with the old disk in the laptop.  
If portmap is not installed the NFS mount will take a while. Just wait a bit or install it.
If portmap is not installed the NFS mount will take a while. Just wait a bit or install it.
To install portmap type
To install portmap type
<pre><nowiki>
<pre><nowiki>
sudo aptitude install portmap
sudo aptitude install portmap
</nowiki></pre>
</nowiki></pre>
Mount the NFS directory to /mnt .
Mount the NFS directory to /mnt .
<pre><nowiki>
<pre><nowiki>
sudo mount 192.168.1.1:/home/username /mnt
sudo mount 192.168.1.1:/home/username /mnt
</nowiki></pre>  
</nowiki></pre>  
Check the permissions on the NFS directory to make sure you can write to it
Check the permissions on the NFS directory to make sure you can write to it
<pre><nowiki>
<pre><nowiki>
ls -l /mnt
ls -l /mnt
</nowiki></pre>
</nowiki></pre>
It might show something like this
It might show something like this
<pre><nowiki>
<pre><nowiki>
-rw-r--r--  1 1000 1000      108 2007-09-07 01:35 myfile.txt
-rw-r--r--  1 1000 1000      108 2007-09-07 01:35 myfile.txt
</nowiki></pre>
</nowiki></pre>
That means only the user with user id 1000 can write to the directory. The user id for the ubuntu user on the live CD is 999.  
That means only the user with user id 1000 can write to the directory. The user id for the ubuntu user on the live CD is 999.  
So lets add a user with uid 1000 that can write to the NFS directory...
So lets add a user with uid 1000 that can write to the NFS directory...
<pre><nowiki>
<pre><nowiki>
sudo adduser diskuser --uid 1000
sudo adduser diskuser --uid 1000
</nowiki></pre>
</nowiki></pre>
To see the uid of a user type
To see the uid of a user type
<pre><nowiki>
<pre><nowiki>
sudo cat /etc/passwd | grep diskuser
sudo cat /etc/passwd | grep diskuser
</nowiki></pre>
</nowiki></pre>
Now we have a user with write permission on the mounted NFS directory. The other problem is that to read from /dev/ you need to be root. Lets take a look at /dev/hda  
Now we have a user with write permission on the mounted NFS directory. The other problem is that to read from /dev/ you need to be root. Lets take a look at /dev/hda  
<pre><nowiki>
<pre><nowiki>
sudo ls -l /dev/hda
sudo ls -l /dev/hda
</nowiki></pre>
</nowiki></pre>
That shows
That shows
<pre><nowiki>
<pre><nowiki>
brw-rw---- 1 root disk 3, 0 2007-10-08 20:21 /dev/hda
brw-rw---- 1 root disk 3, 0 2007-10-08 20:21 /dev/hda
</nowiki></pre>
</nowiki></pre>
which means only user "root" and group "disk" can read from it. Sudo to the NFS directory won't work because sudo will dd as root. To fix this we have to add "diskuser" to the "disk" group like this
which means only user "root" and group "disk" can read from it. Sudo to the NFS directory won't work because sudo will dd as root. To fix this we have to add "diskuser" to the "disk" group like this
<pre><nowiki>
<pre><nowiki>
sudo adduser diskuser disk
sudo adduser diskuser disk
</nowiki></pre>
</nowiki></pre>
Now we can dd as a normal user. Log on as the "diskuser" with
Now we can dd as a normal user. Log on as the "diskuser" with
<pre><nowiki>
<pre><nowiki>
su diskuser
su diskuser
</nowiki></pre>
</nowiki></pre>
Then to copy the whole disk to a disk image on the NFS server type
Then to copy the whole disk to a disk image on the NFS server type
<pre><nowiki>
<pre><nowiki>
dd if=/dev/hda of=/mnt/disk_image.img
dd if=/dev/hda of=/mnt/disk_image.img
</nowiki></pre>
</nowiki></pre>
When it is done it will go back to the prompt and you'll see
When it is done it will go back to the prompt and you'll see
<pre><nowiki>
<pre><nowiki>
diskuser@ubuntu:~$
diskuser@ubuntu:~$
</nowiki></pre>
</nowiki></pre>
Exit "diskuser" by typing
Exit "diskuser" by typing
<pre><nowiki>
<pre><nowiki>
exit
exit
</nowiki></pre>
</nowiki></pre>
Unmount the NFS directory
Unmount the NFS directory
<pre><nowiki>
<pre><nowiki>
sudo umount /mnt
sudo umount /mnt
</nowiki></pre>
</nowiki></pre>
Shut down the laptop and put the new hard drive in. Boot from the *ubuntu Live CD and mount the NFS directory on /mnt as shown above. Now you have to copy the disk image back to the new hard drive.
Shut down the laptop and put the new hard drive in. Boot from the *ubuntu Live CD and mount the NFS directory on /mnt as shown above. Now you have to copy the disk image back to the new hard drive.
<pre><nowiki>
<pre><nowiki>
sudo dd if=/mnt/disk_image.img of=/dev/hda
sudo dd if=/mnt/disk_image.img of=/dev/hda
</nowiki></pre>
</nowiki></pre>
When it's done you'll have a copy of your old disk on the new one. Shutdown the laptop and boot from the hard drive. Please note that if the new disk is bigger than the old one you'll have to resize the partitions to be able to use all the space. The UUID of the disk might change as well. If that happens just boot from the *ubuntu Live CD again, mount the hard drive and edit the UUID's in /etc/fstab and /boot/grub/menu.list . To get the UUID of a partition or disk run  
When it's done you'll have a copy of your old disk on the new one. Shutdown the laptop and boot from the hard drive. Please note that if the new disk is bigger than the old one you'll have to resize the partitions to be able to use all the space. The UUID of the disk might change as well. If that happens just boot from the *ubuntu Live CD again, mount the hard drive and edit the UUID's in /etc/fstab and /boot/grub/menu.list . To get the UUID of a partition or disk run  
<pre><nowiki>
<pre><nowiki>
ls -l /dev/disk/by-uuid/
ls -l /dev/disk/by-uuid/
</nowiki></pre>
</nowiki></pre>
I hope this will be helpful to someone.
I hope this will be helpful to someone.
PS: Thanks to all the guys in #kubuntu for their help in understanding NFS permissions.
PS: Thanks to all the guys in #kubuntu for their help in understanding NFS permissions.
Have fun!
Have fun!


[[category:UbuntuHelp]]
[[category:UbuntuHelp]]

2007年11月30日 (五) 16:40的版本

{{#ifexist: :DDtoNFS/zh | | {{#ifexist: DDtoNFS/zh | | {{#ifeq: {{#titleparts:DDtoNFS|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:DDtoNFS|1|-1|}} | zh | | }}

How to dd to a NFS server

I bought a new hard drive for my laptop and just wanted to copy the old disk to the new one because I didn't feel like installing everything again. On a desktop box that's pretty easy, just put the new disk in together with the old one and use dd to copy it across. Most laptops can only take one disk so that won't work. I have a NFS server with enough space to hold the laptop disk but NFS won't allow root to write on a NFS mounted directory and dd won't work as a normal user. This is how I did it. Boot from the *ubuntu Live CD with the old disk in the laptop. If portmap is not installed the NFS mount will take a while. Just wait a bit or install it. To install portmap type

sudo aptitude install portmap

Mount the NFS directory to /mnt .

sudo mount 192.168.1.1:/home/username /mnt

Check the permissions on the NFS directory to make sure you can write to it

ls -l /mnt

It might show something like this

-rw-r--r--  1 1000 1000      108 2007-09-07 01:35 myfile.txt

That means only the user with user id 1000 can write to the directory. The user id for the ubuntu user on the live CD is 999. So lets add a user with uid 1000 that can write to the NFS directory...

sudo adduser diskuser --uid 1000

To see the uid of a user type

sudo cat /etc/passwd | grep diskuser

Now we have a user with write permission on the mounted NFS directory. The other problem is that to read from /dev/ you need to be root. Lets take a look at /dev/hda

sudo ls -l /dev/hda

That shows

brw-rw---- 1 root disk 3, 0 2007-10-08 20:21 /dev/hda

which means only user "root" and group "disk" can read from it. Sudo to the NFS directory won't work because sudo will dd as root. To fix this we have to add "diskuser" to the "disk" group like this

sudo adduser diskuser disk

Now we can dd as a normal user. Log on as the "diskuser" with

su diskuser

Then to copy the whole disk to a disk image on the NFS server type

dd if=/dev/hda of=/mnt/disk_image.img

When it is done it will go back to the prompt and you'll see

diskuser@ubuntu:~$

Exit "diskuser" by typing

exit

Unmount the NFS directory

sudo umount /mnt

Shut down the laptop and put the new hard drive in. Boot from the *ubuntu Live CD and mount the NFS directory on /mnt as shown above. Now you have to copy the disk image back to the new hard drive.

sudo dd if=/mnt/disk_image.img of=/dev/hda

When it's done you'll have a copy of your old disk on the new one. Shutdown the laptop and boot from the hard drive. Please note that if the new disk is bigger than the old one you'll have to resize the partitions to be able to use all the space. The UUID of the disk might change as well. If that happens just boot from the *ubuntu Live CD again, mount the hard drive and edit the UUID's in /etc/fstab and /boot/grub/menu.list . To get the UUID of a partition or disk run

ls -l /dev/disk/by-uuid/

I hope this will be helpful to someone. PS: Thanks to all the guys in #kubuntu for their help in understanding NFS permissions. Have fun!