5

What directories on my Ubuntu computer aren't actually on my hard drive? I am making a personal backup software, and some of the directories are not "real" Which directories aren't actually on my hard drive?

Thanks

6
  • 1
    The only directory you really need to backup is the /home/your-username folder. Merry Christmas! Dec 25 '16 at 21:27
  • what about installed softwares? Dec 25 '16 at 22:02
  • 1
    Installed software can reside many different places, the most common being: /bin/, /usr/bin/, /sbin/, /usr/sbin/, and /opt/. Dec 25 '16 at 22:29
  • what are the other directories that contain data that is on the hard drive? the current directories i have are /home, /var, /lib, /usr, /bin, /sbin, and /opt this seem ok or are there more? Dec 25 '16 at 22:52
  • 4
4

To list all mounted file systems and their mount point directories that are virtual i.e. not backed by a physical disk storage, you can parse the output of the mount command.

For simplicity, I'm only filtering out all mounts corresponding to devices starting with /dev/sd or /dev/mmcblk, which should cover most hard disk partitions and removable media. This is not perfect, because you might possibly have devices that show up differently which would then not get filtered out, but as you later still see what was mounted in the output, I prefer false positive results here over false negatives. If you notice you need to add something, simply add it to the regular expression pattern of the first grep command, inside the (...) brackets and separated from the other filtered line beginnings with a | pipe.

mount | grep -vE '^(/dev/sd|/dev/mmcblk)' | grep -oE '\S+ on \S+' | sort -k3 | column -t

This will result in a list of mounts, like that one on my example machine:

$ mount | grep -vE '^(/dev/sd|/dev/mmcblk)' | grep -oE '\S+ on \S+' | sort -k3 | column -t
udev           on  /dev
hugetlbfs      on  /dev/hugepages
mqueue         on  /dev/mqueue
devpts         on  /dev/pts
tmpfs          on  /dev/shm
proc           on  /proc
binfmt_misc    on  /proc/sys/fs/binfmt_misc
systemd-1      on  /proc/sys/fs/binfmt_misc
tmpfs          on  /run
cgmfs          on  /run/cgmanager/fs
hugetlbfs-kvm  on  /run/hugepages/kvm
tmpfs          on  /run/lock
tmpfs          on  /run/user/1000
gvfsd-fuse     on  /run/user/1000/gvfs
sysfs          on  /sys
efivarfs       on  /sys/firmware/efi/efivars
tmpfs          on  /sys/fs/cgroup
cgroup         on  /sys/fs/cgroup/blkio
cgroup         on  /sys/fs/cgroup/cpu,cpuacct
cgroup         on  /sys/fs/cgroup/cpuset
cgroup         on  /sys/fs/cgroup/devices
cgroup         on  /sys/fs/cgroup/freezer
cgroup         on  /sys/fs/cgroup/hugetlb
cgroup         on  /sys/fs/cgroup/memory
cgroup         on  /sys/fs/cgroup/net_cls,net_prio
cgroup         on  /sys/fs/cgroup/perf_event
cgroup         on  /sys/fs/cgroup/pids
cgroup         on  /sys/fs/cgroup/systemd
fusectl        on  /sys/fs/fuse/connections
pstore         on  /sys/fs/pstore
debugfs        on  /sys/kernel/debug
securityfs     on  /sys/kernel/security
none           on  /tmp

This listing should show all paths on the right where you have a virtual file system mounted and the corresponding type of file system on the left. As mentioned above, due to filtering /dev/sd* only, there might be some false positive results in the list.

So from that list we can conclude that /dev, /proc, /run, /sys and /tmp are purely virtual. Note that while the first four directories are virtual on all Ubuntu installations, /tmp is normally stored on he hard disk unless you manually make it a tmpfs like I did. It should never be included into a backup anyway though.

If you want a way to reduce that list of paths and filter out all those which are only subdirectories of already mentioned paths (like e.g. /dev/pts can be omitted because /dev is already listed), look at Having a list of paths, how can I filter out subdirectories of previously mentioned paths?

3
  • /dev/sd* is no longer used in 16.04 for things like NVMe drives. /dev/nvme* is used instead. Dec 26 '16 at 0:18
  • @ChaiT.Rex I don't know, how would such an NVMe drive be represented then? For now I added a filter for /dev/mmcblk and instructions how to add more filters.
    – Byte Commander
    Dec 26 '16 at 0:26
  • For example, /dev/nvme0n1p1 Dec 26 '16 at 0:27
1

This really depends on how you are going to restore your system. If you will rebuild then you only need the configuration/data files for your services (eg: /etc, /opt, /var, /home)

If you are after a full system restore, then it you could omit /proc, /boot & /dev. Then you can install the minimum OS from your boot media and then restore your system via your backup.

https://serverfault.com/questions/74696/linux-what-directories-should-i-exclude-when-backing-up-a-server

Not the answer you're looking for? Browse other questions tagged or ask your own question.