由于之前是一直用的机械硬盘装的ubuntu但是用着用着就觉得很不爽于是就想着怎么把根分区给迁移到SSD上去
看我的分区表
sudo blkid
/dev/sda1: LABEL="PQSERVICE" UUID="02B63AC7B63ABB4D" TYPE="ntfs"
/dev/sda2: UUID="5b3d83b0-22e9-4110-a106-91d2d7f54f11" TYPE="ext4"
/dev/sda5: UUID="6BC4865D227512DA" TYPE="ntfs"
/dev/sda6: UUID="66816FE62F9835F3" TYPE="ntfs"
/dev/sda7: UUID="2feae2ed-2e8b-470c-ac82-182fb95feb6b" TYPE="ext4"
/dev/sda8: UUID="704dd102-30d4-4df6-b8e6-9fa2ea70f477" TYPE="ext4"
/dev/sda9: UUID="0c962b35-5c39-4f65-a273-911826b04c27" TYPE="ext4"
/dev/sda10: UUID="d1e7b415-6ade-492c-b510-3b322f8805fc" TYPE="swap"
/dev/sda11: UUID="aa52495d-3b24-449c-845c-b71177a44ce3" TYPE="ext4"
/dev/sda12: LABEL="M-hM-=M-/M-dM-;M-6M-gM-^[M-^X" UUID="4EC83DAC71F8C83B" TYPE="ntfs"
/dev/sdb1: LABEL="M-gM-3M-;M-gM-;M-^_M-gM-^[M-^X" UUID="D27A4B147A4AF52F" TYPE="ntfs"
/dev/sdb2: LABEL="SSD_for_Linux" UUID="f23fad76-a75f-4e7b-a402-c536d25bb920" TYPE="ext4"
之前是/dev/sda2: UUID="5b3d83b0-22e9-4110-a106-91d2d7f54f11" TYPE="ext4"作为根分区
ok制作好livecd,开机F12 进入快速启动选择刚刚的livecd进入之后选择试用ubuntu
进入之后打开终端 sudo passwd设置新的root密码
现在设置好root密码了,好的
接下我是将/dev/sda2 的根分区 迁移到/dev/sdb2
首先挂载两个分区
sudo mkdir /mnt/sda2
sudo mkdir /mnt/sdb2
sudo mount /dev/sda2 /mnt/sda2
sudo mount /dev/sdb2 /mnt/sdb2
现在挂载好了,接下来就将sda2的数据原封不动的拷贝到sdb2
sudo cp -ax /mnt/sda2/* /mnt/sdb2/*
一定要注意的是必须加上这个ax参数,否则的话,复制到新的分区后,所有文件的拥有者都会变成root,那麻烦可就大了,而cp命令的ax参数可以阻止这样的事情发生,它会把所有的文件权限按原样复制好。
复制好了之后就要修改grub2的配置了,我这里的grub2是单独的分区的挂载到/boot的
由于开机时是grub2引导根分区的所以在里面要修改跟分区的uuid
lxiang@lxiang-Aspire-5750G:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb2 49G 11G 36G 23% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 1.9G 8.0K 1.9G 1% /dev
tmpfs 1.9G 15M 1.9G 1% /tmp
tmpfs 381M 832K 380M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1.9G 80K 1.9G 1% /run/shm
none 100M 40K 100M 1% /run/user
tmpfs 1.9G 724K 1.9G 1% /var/log
tmpfs 1.9G 36K 1.9G 1% /var/tmp
/dev/sda7 270M 64M 189M 26% /boot
/dev/sdb1 70G 47G 24G 67% /media/C
/dev/sda5 389G 303G 86G 78% /media/E
/dev/sda6 324G 191G 134G 59% /media/F
/dev/sda11 79G 11G 65G 15% /home
/dev/sda9 38G 26G 10G 73% /home/lxiang/data
挂载sda7分区到/mnt/boot
sudo gedit /mnt/boot/grub/grub.cfg
将
--set=root 5b3d83b0-22e9-4110-a106-91d2d7f54f11 (sda2 uuid)源根分区
改为 -set=root 704dd102-30d4-4df6-b8e6-9fa2ea70f477 (sdb2 uuid)目标根分区
有好几处这样的,不过楼主都改了的。
这里修改好了之后就是配置/etc/fstab
中的内容了同理将uuid 以前的改为现在sdb2的uuid
楼主配置好的fstab如# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sdb2 during installation noatime,nodiratime,discard</span> for SSD
UUID=f23fad76-a75f-4e7b-a402-c536d25bb920 / ext4 noatime,nodiratime,discard,errors=remount-ro 0 1
# /boot was on /dev/sda7 during installation
UUID=2feae2ed-2e8b-470c-ac82-182fb95feb6b /boot ext4 defaults 0 2
# /home was on /dev/sda11 during installation
UUID=aa52495d-3b24-449c-845c-b71177a44ce3 /home ext4 defaults 0 2
# /usr was on /dev/sda8 during installation
#UUID=704dd102-30d4-4df6-b8e6-9fa2ea70f477 /usr ext4 defaults 0 2
# swap was on /dev/sda10 during installation
UUID=d1e7b415-6ade-492c-b510-3b322f8805fc none swap sw 0 0
UUID=0c962b35-5c39-4f65-a273-911826b04c27 /home/lxiang/data ext4 defaults 0 2
#Windows C D E F
#UUID=000BC1B0000104D6 /media/D ntfs defaults 0 0
UUID=D27A4B147A4AF52F /media/C ntfs defaults 0 0
UUID=6BC4865D227512DA /media/E ntfs defaults 0 0
UUID=66816FE62F9835F3 /media/F ntfs defaults 0 0
#test for ssd
tmpfs /tmp tmpfs defaults,noatime,nodiratime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
红色部分是为了ssd的优化而添加的
接下来是/etc/rc.local
echo 300 > /sys/class/backlight/intel_backlight/brightness
exit 0
echo noop > /sys/block/sdb/queue/scheduler
echo 1 > /sys/block/sdb/queue/iosched/fifo_batch
echo 50 > /proc/sys/vm/dirty_ratio
echo 10 > /proc/sys/vm/dirty_background_ratio
echo 6000 > /proc/sys/vm/dirty_expire_centisecs
echo 30000 > /proc/sys/vm/dirty_writeback_centisecs
ln -sf /run/lock /var/lock
ln -sf /tmp/.viminfo .
红色部分是针对SSD的优化而配置的
具体的SSD 优化请参照
http://www.linuxidc.com/Linux/2013-04/83337.htm
测试一下SSD
lxiang@lxiang-Aspire-5750G:~$ sudo hdparm -Tt /dev/sdb2
/dev/sdb2:
Timing cached reads: 11252 MB in 1.99 seconds = 5641.82 MB/sec
Timing buffered disk reads: 1528 MB in 3.00 seconds = 508.92 MB/sec
ok 就这样大工告成