Advertisement
v1ral_ITS

Real Linux Terminal Instructions For Persistent FileSystem

Jul 27th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 14.27 KB | None | 0 0
  1. Note: If you previously followed the instructions on this page for "casper-cow" and it didn't work, that's because it should have read "casper-rw".
  2.  
  3. Note 2: In the instructions below the ext3 file-system is used. For a memory stick however where space is tight, the ext2 file-system will use up considerably less overhead and is probably good enough for this purpose.
  4.  
  5. Note 3: The instructions use all terminal commands, many of them looking quite serious. However it can all be done using the graphical Gnome Partition Editor tool you find in the System -> Administration menu. The exception is giving the partition a label, for this you'd still need to go to a terminal and do a # sudo e2label /dev/<yourpartition> casper-rw
  6. Determine Which Device Your USB Stick Is
  7.  
  8. Note: if you prefer, you can use GPartEd to identify and format the usb thumb drive to ext3 (or a different compatible format) and then skip directly to the "Creating the "casper-rw" File System" section.
  9.  
  10. In order to partition and format your USB Stick, we first need to determine which device your computer recognizes it as and what its mount point is. To find this information run the following command:
  11.  
  12. df -h
  13.  
  14. The output of df -h should look something like this:
  15.  
  16. Filesystem            Size  Used Avail Use% Mounted on
  17. /dev/hda1             187G  4.0G  183G   3% /
  18. varlock               9.3G  507M  8.8G   6% /var/lock
  19. udev                  506M  156K  506M   1% /dev
  20. devshm                506M     0  506M   0% /dev/shm
  21. /dev/hdb3             7.5G  1.4M  7.5G   1% /tmp
  22. /dev/hdb2             9.3G  507M  8.8G   6% /var
  23. /dev/sda1             124M   31M   94M  25% /media/USB DISK
  24.  
  25. As you can see, on my computer, my USB Stick is the last entry in the list and is seen as /dev/sda1 and is mounted and accessible at /media/USB DISK. Now that we know where our USB Stick is, let's go ahead and partition it properly.
  26. Partitioning Your USB Stick
  27.  
  28. Partitioning your USB Stick is a fairly simple task and only requires a few short steps. To partition your USB Stick we will use the command fdisk so run the following command to start the process (replacing /dev/sda with your device path):
  29.  
  30. sudo fdisk /dev/sda
  31.  
  32. Without getting in depth about how to use fdisk (which is outside the scope of this document) here is how you can partition your USB by deleting any existing partitions and creating one new partition.
  33.  
  34. First type “p” at the command prompt and hit <ENTER> to print the current partition table. The output of this command should look something like this:
  35.  
  36. Command (m for help): p
  37.  
  38. Disk /dev/sda: 130 MB, 130023424 bytes
  39. 16 heads, 32 sectors/track, 496 cylinders
  40. Units = cylinders of 512 * 512 = 262144 bytes
  41.  
  42.    Device Boot      Start         End      Blocks   Id  System
  43. /dev/sda1   *           1         496      126960    6  FAT16
  44.  
  45. Again, for this example, we will just delete all of the existing partitions so now type “d” at the command prompt. Then enter the number of the partition you wish to delete. Repeat this process for each partition on your USB Stick until they are all deleted. The following is a example of what your session might look like:
  46.  
  47. Command (m for help): d
  48. Partition number (1-4): 1
  49.  
  50. Command (m for help): d
  51. Partition number (1-4): 2
  52.  
  53. Command (m for help): d
  54. Partition number (1-4): 3
  55.  
  56. Command (m for help): d
  57. Selected partition 4
  58.  
  59. Command (m for help): p
  60.  
  61. Disk /dev/sda1: 130 MB, 130007040 bytes
  62. 16 heads, 32 sectors/track, 495 cylinders
  63. Units = cylinders of 512 * 512 = 262144 bytes
  64.  
  65.     Device Boot      Start         End      Blocks   Id  System
  66.  
  67. Command (m for help):
  68.  
  69. As you can see we have now deleted all of the partitions on our USB Stick. Now we can create one new partition by typing “n” at the command prompt followed by your desired partition number. Once that is done typew” and hit <ENTER> to write the partition table changes to your USB Stick. Here is the output from my session:
  70.  
  71. Command (m for help): n
  72. Command action
  73.   e   extended
  74.   p   primary partition (1-4)
  75. p
  76. Partition number (1-4): 1
  77. First cylinder (1-495, default 1):
  78. Using default value 1
  79. Last cylinder or +size or +sizeM or +sizeK (1-495, default 495):
  80. Using default value 495
  81.  
  82. Command (m for help): w
  83. The partition table has been altered!
  84.  
  85. Calling ioctl() to re-read partition table.
  86.  
  87. WARNING: Re-reading the partition table failed with error 22: Invalid argument.
  88. The kernel still uses the old table.
  89. The new table will be used at the next reboot.
  90. Syncing disks.
  91.  
  92. Now that we have our partition table all set let's format it.
  93. Creating the "casper-rw" File System
  94.  
  95. Formatting your USB Stick is also a very simple task. First we will unmount the device so we can format it, then just format it.
  96.  
  97. First unmount your USB Stick by running the following command:
  98.  
  99. sudo umount /dev/sda1
  100.  
  101. Now that your USB Stick is unmounted we can format it. The only special consideration is that we must give the formatted partition the label “casper-rw”. This is the name the Live CD looks for to store persistent information. You can properly format your USB Stick by issuing the following command:
  102.  
  103. sudo mkfs.ext3 -b 4096 -L casper-rw /dev/sda1
  104.  
  105. The output of this command should look something like this:
  106.  
  107. mke2fs 1.38 (30-Jun-2005)
  108. Filesystem label=casper-rw
  109. OS type: Linux
  110. Block size=4096 (log=2)
  111. Fragment size=4096 (log=2)
  112. 31744 inodes, 31740 blocks
  113. 1587 blocks (5.00%) reserved for the super user
  114. First data block=0
  115. 1 block group
  116. 32768 blocks per group, 32768 fragments per group
  117. 31744 inodes per group
  118.  
  119. Writing inode tables: done
  120. Creating journal (1024 blocks): done
  121. Writing superblocks and filesystem accounting information: done
  122.  
  123. This filesystem will be automatically checked every 20 mounts or
  124. 180 days, whichever comes first.  Use tune2fs -c or -i to override.
  125.  
  126. NOTE: This example uses the ext3 file system, but almost any file system should work. Among the file systems which won't work are VFAT and NTFS
  127.  
  128. Now that we have our partition created and formatted all that is left to do is use it. So let's go use it!
  129.  
  130. Instead of using a USB stick, you can use a file on your hard disk to store persistent information. The file must be named casper-rw and must be on the root of a partition. This partition can be any type that can be mounted automatically (e.g. vfat or ext3). (The persistent mode still works, if the file is created on the root partition of an USB stick.)
  131.  
  132. The following commands assume that a partition is mounted at /media/hda1. You can use any partition; even / will do fine. A file 128 MB in size will be created on this partition. To change the size, modify the count parameter of the "dd" command.
  133.  
  134. $ dd if=/dev/zero of=/media/hda1/casper-rw bs=1M count=128
  135. 128+0 records in
  136. 128+0 records out
  137. 134217728 bytes transferred in 0.947819 seconds (141606919 bytes/sec)
  138.  
  139. $ mkfs.ext3 /media/hda1/casper-rw
  140. mke2fs 1.38 (30-Jun-2005)
  141. /media/hda1/casper-rw is not a block special device.
  142. Proceed anyway? (y,n) y
  143. Filesystem label=
  144. OS type: Linux
  145. Block size=1024 (log=0)
  146. Fragment size=1024 (log=0)
  147. 32768 inodes, 131072 blocks
  148. 6553 blocks (5.00%) reserved for the super user
  149. First data block=1
  150. 16 block groups
  151. 8192 blocks per group, 8192 fragments per group
  152. 2048 inodes per group
  153. Superblock backups stored on blocks:
  154.        8193, 24577, 40961, 57345, 73729
  155.  
  156. Writing inode tables: done
  157. Creating journal (4096 blocks): done
  158. Writing superblocks and filesystem accounting information: done
  159.  
  160. This filesystem will be automatically checked every 23 mounts or
  161. 180 days, whichever comes first.  Use tune2fs -c or -i to override.
  162.  
  163. That's it! You can now boot the Live CD as described below.
  164.  
  165. Now we get to enjoy the fruits of our labor. Make sure your USB Stick is plugged into your computer and take the Live CD that you downloaded and burned earlier and put it in your CD drive (if it is not already there). Reboot your computer and boot up using this Live CD.
  166.  
  167. Before you reboot there are only two things that you need to remember. When the Live CD menu gets displayed hit the <F6> key to enter “Other Options”. This will display the arguments that the Live CD passes to the kernel. At the end of this argument list just add a space and add the word “persistent”. This will instruct the Live CD to maintain and use persistence. That is all. Go for it!
  168.  
  169. Note: It appears that with Flight 5, you need to create a new user in the Live CD session (go System -> Administration -> Users + Groups, then press the "Add User" button) for it to save your settings; it does not appear to save most changes to the default user, "ubuntu". When you create the new user, be sure to check the box in the "user privileges" tab that says "executing system administration tasks" or you'll be pretty limited in what you can do Smile :)
  170.  
  171. When you get back, or better yet, when you boot into your live environment come back to this page and see how you perform a few basic tests to make sure everything is working correctly.
  172.  
  173. Here are a few simple things you can do to verify that everything is working as expected.
  174. Reboot the Live CD
  175.  
  176. The first simple thing you can do to verify that persistence is working is install a few applications and change some environment settings (some thing highly visible and easily recognizable) like your theme or add some GNOME panel icons. Then just reboot... Hit <F6>, enter in “persistent” on the kernel arguments list and boot into your new custom Live CD environment. Your newly installed applications and your custom settings should all still be there.
  177.  
  178. If you want to dig a little deeper you could always inspect the contents of your USB Stick. This will also give you deeper insight into how this great system works.
  179.  
  180. (you can do this from the Live CD by going System -> Administration -> Disks, selecting the appropriate drive, setting the access path to /mnt and pressing the Enable button followed by the Browse button)
  181. Investigating What Is Now On Your "casper-rw"
  182.  
  183. Another relatively simple thing you can do to verify that everything is working and to learn more about how everything works is to just inspect what is now on your USB Stick in isolation. Reboot back into your regularly installed system, plug in your USB Stick and just have a look around. The contents of your USB Stick is what makes your custom environment your own.
  184.  
  185. By using reconstructor a CD can be remastered and an additional menu item (Persistent Mode) added on boot. The persistent mode was added as the default. No changes were made to the CD except for adding the persistent menu item. This may be best described in another how-to. If there is a place where a persistent ISO can be uploaded I'd be glad to share
  186.  
  187. The new Ubuntu Live CD persistence is an excellent capability and in addition to current Live CD uses, this will certainly make Live CDs very much more viable, useful and important. Now you can carry around your own custom Ubuntu environment on a CD and USB Stick that all just fits in your pocket. Now go gloat to your friends and co-workers about how much Ubuntu ROCKS!
  188.  
  189.     What is the min. USB key size that is needed? How about adding a swap partition to the USB key?
  190.     Wouldn't the Live CD rock more if the end-user didn't have to fudge around with kernel arguments and the Live CD just did what was right, to wit: if there is a removable media device labelled "casper-rw" and formatted appropriately, use it (or at least ask) and if there isn't, don't? See either of these 2 guides
  191.  
  192.         https://help.ubuntu.com/community/LiveCDCustomizationFromScratch
  193.  
  194.         https://help.ubuntu.com/community/LiveCDCustomization
  195.     Wouldn't it rock still further if the instructions provided were done up as a quick'n'dirty GUI (Knoppix-style) which allowed an end-user to make their persistent store without having to fudge around with the CLI at all?
  196.    Is there a way to use a (luks)encrypted usb stick?
  197.  
  198.    Every single disk write goes to the USB stick, which GNOME loves to do all the time. After following these directions, I booted the LiveCD using the "persistent" boot option. All I did was change the desktop background to a solid color and visit Slashdot's front page in Firefox. Then I powered down the system and looked at how much written data was saved on the USB stick. 75 MB! Most was gnome-related stuff under /var/lib. Ouch. And the USB stick got written to the whole time pretty much. Won't that wear out the USB stick much faster? Can't the changes be dumped in bulk only once in a while, when the user presses a button on some applet? And only that data that is in the user's home directory? This will keep the USB stick from wearing out. SLAX has got scripts to do this already that could perhaps be copied. Especially see the SLAX script called "configsave".
  199.    How can the USB stick be set up to have everything included? There's no reason for a 700 MB CD if the USB disk has a couple of GB's today. Would this be an entire ubuntu installation on the USB disk?. For this, one can use Ubuntu Live CD installation icon on the desktop.
  200.  
  201. Keep in mind that not everybody we want to convert to Ubuntu is a power user (administrator). I can pretty much guarantee that anything that looks like typing Scary Strings is going to turn people off, not on, no matter how "powerful" it is behind the scenes.
  202.  
  203. This feature (and the whole Ubuntu Live CD release) rocks, and I agree that it would rock even more if one could do it without CLI commands. It seems there is only a small number of places where the persistence can be stored (USB key and loopback file). The ideal solution would therefore seem to be an option at startup to create persistence in the one or few places where it is possible (including the hard drive), and the default option would look for persistence file and allow a choice if more than one is found (I wonder how is that dealt with currently?). This is option is absolutely ideal for people stuck with corporate computers, that want to start moving towards Linux, but are afraid to mess with their partitions just yet.
  204.  
  205. Suggestion: Actually very little CLI commands are needed, as nearly all of it can be done using the Gnome Partition Editor which is in the Administration menu. However it does not have an option for setting the disk label. In the 'Device' menu there's a 'Set Disk Label' item, however that's not it. Smile :) This wiki page should probably be redone using the Gnome Partition Editor tool, and loads of screen shots.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement