<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>龙宇</title>
    <description>知鱼 - 子非鱼 安知鱼之乐
</description>
    <link>http://leaeasy.github.io/</link>
    <atom:link href="http://leaeasy.github.io/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Thu, 15 Oct 2015 03:20:04 +0000</pubDate>
    <lastBuildDate>Thu, 15 Oct 2015 03:20:04 +0000</lastBuildDate>
    <generator>Jekyll v2.4.0</generator>
    
      <item>
        <title>Linux下的时间机器 -- Deepin实战BTRFS子卷</title>
        <description>&lt;p&gt;基于btrfs的子卷等特性，我们可以轻松实现系统快速恢复、类似与OSX的时间机器等有趣实用的功能。&lt;/p&gt;

&lt;p&gt;Btrfs 被称为是下一代 Linux 文件系统,目前btrfs已集成入内核开发主线。&lt;/p&gt;

&lt;p&gt;本教程将针对btrfs字卷及压缩进行一些系统功能实现。&lt;/p&gt;

&lt;h2&gt;安装deepin系统&lt;/h2&gt;

&lt;p&gt;以下是全新安装deepin系统&lt;/p&gt;

&lt;h3&gt;分区选择&lt;/h3&gt;

&lt;p&gt;下载deepin系统按如下图分区方式进行安装&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;由于grub引导限制，需要设置/boot分区&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/article_images/2015-10-15-btrfs-time-machine/01-partition-options.png&quot; alt=&quot;分区选择&quot;&gt;&lt;/p&gt;

&lt;h3&gt;正常安装过程&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/assets/article_images/2015-10-15-btrfs-time-machine/02-installing-deepin.png&quot; alt=&quot;安装Deepin&quot;&gt;&lt;/p&gt;

&lt;h3&gt;安装完成后正常进入系统&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/assets/article_images/2015-10-15-btrfs-time-machine/03-deepin-interface-grub.png&quot; alt=&quot;Grub选择&quot;&gt;
&lt;img src=&quot;/assets/article_images/2015-10-15-btrfs-time-machine/03-deepin-interface-desktop.png&quot; alt=&quot;Deepin界面&quot;&gt;
&lt;img src=&quot;/assets/article_images/2015-10-15-btrfs-time-machine/03-deepin-interface-mount.png&quot; alt=&quot;挂载截图&quot;&gt;&lt;/p&gt;

&lt;h2&gt;已安装deepin系统&lt;/h2&gt;

&lt;p&gt;如果你已安装deepin系统,想要对你系统上的根分区进行转换，你首先需要使用Live CD启动。&lt;/p&gt;

&lt;p&gt;在启动后，打开终端，使用下面的命令来转换文件系统。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;btrfs-convert /dev/sda2 &lt;span class=&quot;c&quot;&gt;#这里假设/dev/sda2 为root分区&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;注意： 假如没有单独的/boot分区，还是需要重新建立一个单独的/boot分区&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;将deepin系统转移到btrfs子卷&lt;/h2&gt;

&lt;p&gt;由于目前deepin-installer无法支持直接安装到某个字卷，我们只能通过手动方式进行。&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;将根分区挂载至某个目录（这里用/mnt），并进入该目录
&lt;code&gt;
mount /dev/sda2 /mnt
&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;将deepin系统迁移到字卷内部
&lt;code&gt;
btrfs subvolume snapshot /mnt /mnt/deepin-1012
&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;至此，deepin系统便迁移到字卷内部了。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;修改grub.cfg等文件
找到Deepin启动项目那行，在内核参数添加&lt;code&gt;rootflags=subvolid=xxxx&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;subvolid=xxxx中xxxx为subvolid值，通过&lt;code&gt;btrfs subvolume list .&lt;/code&gt;可以得到，第二步可以看到deepin-1012字卷的ID为263&lt;/p&gt;
&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;如下为grub.cfg的其中一段
&lt;pre&gt;&lt;code&gt;
menuentry &amp;#39;Deepin GNU/Linux 8.0 (jessie) GNU/Linux Stable&amp;#39; --class deepin --class gnu-linux --class gnu --class os $menuentry&lt;em&gt;id&lt;/em&gt;option &amp;#39;gnulinux-simple-9db18def-ad74-4197-8303-ca912a56f316&amp;#39; {
    load&lt;em&gt;video
    insmod gzio
        if [ x$grub&lt;/em&gt;platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part&lt;em&gt;msdos
    insmod ext2
    set root=&amp;#39;hd0,msdos1&amp;#39;
    if [ x$feature&lt;/em&gt;platform&lt;em&gt;search&lt;/em&gt;hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  6b5865da-87d4-4d0d-8444-0181f759c886
    else
      search --no-floppy --fs-uuid --set=root 6b5865da-87d4-4d0d-8444-0181f759c886
    fi
    echo    &amp;#39;载入 Linux 4.2.0-1-amd64 ...&amp;#39;
    linux   /vmlinuz-4.2.0-1-amd64 root=UUID=9db18def-ad74-4197-8303-ca912a56f316  rootflags=subvolid=263 ro  splash quiet
    echo    &amp;#39;载入初始化内存盘...&amp;#39;
    initrd  /initrd.img-4.2.0-1-amd64
}
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;由于grub.cfg文件指定了root分区信息，我们也可以注释掉/etc/fstab中根分区挂载条目，否则也需要在挂载参数中添加subvolid字段&lt;/p&gt;

&lt;p&gt;重启选择修改后的grub启动项进入系统，能够成功进入系统后，便可以将以前不在字卷中的文件夹及文件删除了。&lt;/p&gt;

&lt;h2&gt;deepin系统在btrfs字卷的新玩法&lt;/h2&gt;

&lt;p&gt;这里开始才是这篇教程真正要讲的内容。
以下是一个具体的例子。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;假如我们希望开启experimental源安装dde-next新桌面，但是又想保留2015旧版桌面，那我们该如何操作？&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;将根分区挂载至/mnt下
&lt;code&gt;bash
mount /dev/sda2 /mnt
&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;将当前系统快照一份备份
&lt;code&gt;bash
btrfs subvolume snapshot deepin-1012 deepin-stable
&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;安装传统方式添加experimental源安装dde-next桌面&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;这里我们操作完后，就可以通过&lt;code&gt;btrfs subvolume list.&lt;/code&gt;命令得到新字卷ID，然后添加到grub.cfg文件中&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;/assets/article_images/2015-10-15-btrfs-time-machine/04-subvolume-list.png&quot; alt=&quot;子卷信息&quot;&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;这里是grub.cfg文件的一部分
 &lt;pre&gt;&lt;code&gt;
 menuentry &amp;#39;Deepin GNU/Linux 8.0 (jessie) GNU/Linux Stable&amp;#39; --class deepin --class gnu-linux --class gnu --class os $menuentry&lt;em&gt;id&lt;/em&gt;option &amp;#39;gnulinux-simple-9db18def-ad74-4197-8303-ca912a56f316&amp;#39; {
    load&lt;em&gt;video
    insmod gzio
    if [ x$grub&lt;/em&gt;platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part&lt;em&gt;msdos
    insmod ext2
    set root=&amp;#39;hd0,msdos1&amp;#39;
    if [ x$feature&lt;/em&gt;platform&lt;em&gt;search&lt;/em&gt;hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  6b5865da-87d4-4d0d-8444-0181f759c886
    else
      search --no-floppy --fs-uuid --set=root 6b5865da-87d4-4d0d-8444-0181f759c886
    fi
    echo    &amp;#39;载入 Linux 4.2.0-1-amd64 ...&amp;#39;
    linux   /vmlinuz-4.2.0-1-amd64 root=UUID=9db18def-ad74-4197-8303-ca912a56f316  rootflags=subvolid=269 ro  splash quiet
    echo    &amp;#39;载入初始化内存盘...&amp;#39;
    initrd  /initrd.img-4.2.0-1-amd64
}
menuentry &amp;#39;Deepin GNU/Linux 8.0 (jessie) GNU/Linux Experimental&amp;#39; --class deepin --class gnu-linux --class gnu --class os $menuentry&lt;em&gt;id&lt;/em&gt;option &amp;#39;gnulinux-simple-9db18def-ad74-4197-8303-ca912a56f316&amp;#39; {
    load&lt;em&gt;video
    insmod gzio
    if [ x$grub&lt;/em&gt;platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part&lt;em&gt;msdos
    insmod ext2
    set root=&amp;#39;hd0,msdos1&amp;#39;
    if [ x$feature&lt;/em&gt;platform&lt;em&gt;search&lt;/em&gt;hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  6b5865da-87d4-4d0d-8444-0181f759c886
    else
      search --no-floppy --fs-uuid --set=root 6b5865da-87d4-4d0d-8444-0181f759c886
    fi
    echo    &amp;#39;载入 Linux 4.2.0-1-amd64 ...&amp;#39;
    linux   /vmlinuz-4.2.0-1-amd64 root=UUID=9db18def-ad74-4197-8303-ca912a56f316  rootflags=subvolid=270 ro  splash quiet
    echo    &amp;#39;载入初始化内存盘...&amp;#39;
    initrd  /initrd.img-4.2.0-1-amd64
}
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;以后我们就可以在选择菜单中选择进入dde-next系统，或者stable系统了&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/article_images/2015-10-15-btrfs-time-machine/05-deepin-subvolume-grub.png&quot; alt=&quot;子卷选择&quot;&gt;&lt;/p&gt;

&lt;h3&gt;一些解释&lt;/h3&gt;

&lt;p&gt;我们在执行安装experimental之前，将当前系统快照到一个新子卷，就类似相当于将当前系统生成一份备份，由于btrfs文件系统实现快照速度非常快，几秒之内就可以完成。
通过类似的操作，我们可以在需要测试软件、删除测试等非常影响系统情况下，操作后无需担心系统损坏等问题，只需要操作前生成一份快照便可放心安装测试，出现问题也只需要重新启动选择备份快照重新引导进入系统即可。&lt;/p&gt;

&lt;h2&gt;其他&lt;/h2&gt;

&lt;p&gt;btrfs也可以设置默认挂载子卷
&lt;code&gt;bash
 btrfs subvolume set-default 256 /
&lt;/code&gt;
这样就无需修改grub.cfg文件添加字卷id参数，也可以默认将id为256的子卷默认挂载。&lt;/p&gt;
</description>
        <pubDate>Thu, 15 Oct 2015 10:41:01 +0000</pubDate>
        <link>http://leaeasy.github.io/deepin/system/2015/10/15/deepin-install-to-btrfs-subvolume.html</link>
        <guid isPermaLink="true">http://leaeasy.github.io/deepin/system/2015/10/15/deepin-install-to-btrfs-subvolume.html</guid>
        
        <category>deepin</category>
        
        
        <category>deepin</category>
        
        <category>system</category>
        
      </item>
    
      <item>
        <title>Shell去掉空白行、多余空格</title>
        <description>&lt;h1&gt;去掉空白行&lt;/h1&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;tr -s &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;\012&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &amp;lt; test.txt &amp;gt; newtest.txt

sed -n &lt;span class=&quot;s1&quot;&gt;&amp;#39;/./p&amp;#39;&lt;/span&gt; temp_file5 &amp;gt; newtest.txt

grep . temp_file5 &amp;gt; newtest.txt

grep -v &lt;span class=&quot;s1&quot;&gt;&amp;#39;^$&amp;#39;&lt;/span&gt; temp_file5 &amp;gt; newtest.txt&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h1&gt;去掉多余空格&lt;/h1&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;cat test.txt &lt;span class=&quot;p&quot;&gt;|&lt;/span&gt; tr -s &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;:space:&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;

sed &lt;span class=&quot;s1&quot;&gt;&amp;#39;s/__*/_/g&amp;#39;&lt;/span&gt; test.txt     //这里，_表示一个空格&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</description>
        <pubDate>Wed, 14 Oct 2015 10:41:01 +0000</pubDate>
        <link>http://leaeasy.github.io/shell/2015/10/14/shell_remove_unused_blank.html</link>
        <guid isPermaLink="true">http://leaeasy.github.io/shell/2015/10/14/shell_remove_unused_blank.html</guid>
        
        <category>shell</category>
        
        
        <category>shell</category>
        
      </item>
    
  </channel>
</rss>
