smbclient & dd

you know I am told to get an image of the whole ubuntu system on my server shared folder.
If you have used dd before to get an image of the occupied space on the system please lemme know bout your command.
(I preferably want dd to only get an image of the occupied file system not the free space)

Well, here comes the next part. You know, though I can view my server shared folder graphically, I cannot do it using shell command. The server has the following path:

smb://username@safe/mysharedfolder

(username and mysharedfolder have the same name)

I tried different commands for smbclient to connect to the server but it failed. Any helps would be appreciable.

These GUIs can be misleading since the actual underlying filesystem isn't using URL's.

To actually mount a CIFS file share(CIFS = samba shares / windows shares / etc) with mount:

# /mnt/share, or wherever you mount it, should already exist and
# be an empty folder.
mount -t cifs //safe/mysharedfolder -o username=user,password="password" /path/to/mountfolder

---------- Post updated at 12:22 PM ---------- Previous update was at 12:16 PM ----------

dd isn't psychic. dd won't know and cannot know what space is occupied, that's handled at the filesystem level. You need to use filesystem-specific tools to handle that, and how that's done depends on the filesystem type.

Three options:

1) Do it manually. Save your boot sector and /etc/fstab so you know what kind of partitions belong where, then create tarballs of the contents of every partition. By restoring the boot sector, 'w'-ing it inside 'fdisk', re-creating empty partitions and un-taring their contents in them, you ought to create a bootable system.

2) Cheat, forcing an ordinary dd dump to compress better. Boot a livecd and mount partitions, then 'dd if=/dev/zero of=/mnt/partition/bigfile bs=1048576 ; rm /mnt/partition/bigfile' to overwrite all unused space with zeroes. When you make your dd dump, it should now compress very well when piped through gzip because all empty space will contain zeroes.

3) Use partiton-specific tools. (dump can understand ext2/ext3)

I usually do option 1, myself, since it allows you to create a new system with different partition sizes on restore, though it's fiddly and a lot more work.

1 Like

[quote=corona688;302603611]
These GUIs can be misleading since the actual underlying filesystem isn't using URL's.

To actually mount a CIFS file share(CIFS = samba shares / windows shares / etc) with mount:

# /mnt/share, or wherever you mount it, should already exist and
# be an empty folder.
------- Post updated at 12:22 PM ---------- Previous update was at 12:16 PM ----------

dd isn't psychic.  dd won't know and cannot know what space is occupied, that's handled at the filesystem level.  You need to use filesystem-specific tools to handle that, and how that's done depends on the filesystem type.

Three options:

1) Do it manually.  Save your boot sector and /etc/fstab so you know what kind of partitions belong where, then create tarballs of the contents of every partition.  By restoring the boot sector, 'w'-ing it inside 'fdisk', re-creating empty partitions and un-taring their contents in them, you ought to create a bootable system.

2) Cheat, forcing an ordinary dd dump to compress better.  Boot a livecd and mount partitions, then 'dd if=/dev/zero of=/mnt/partition/bigfile bs=1048576 ; rm /mnt/partition/bigfile' to overwrite all unused space with zeroes.  When you make your dd dump, it should now compress very well when piped through gzip because all empty space will contain zeroes.

3) Use partiton-specific tools.  (dump can understand ext2/ext3)

I usually do option 1, myself, since it allows you to create a new system with different partition sizes on restore, though it's fiddly and a lot more work.

So, to the smb server in for example, /mnt/share, I shall first mkdir /mnt/share; and then
mount -t cifs //safe/mysharedfolder -o username=user,password="password" /mnt/share

right?

-about the first option of taking backup, could you clarify it for me with an example? I don't know about /etc/fstab n how to take my partition from there n tar them.

thanks

If those aren't familiar to you, don't try it, since I can't give you a step by step procedure for it -- how to do it depends on what your partitions are, etc, etc. All it boils down to is, there's very little "magic" about a Linux system. Put the right files in the right places with the right permissions and owners, and it really doesn't matter how they got there. There's distributions whose "installer" is just mkfs, tar, and grub-install. The bootloader of course, is a little magic, hence the need to back up the bootsector, where it lives...

dd on the other hand is stupidly simple. One command dumps the entire disk, warts and all.

Your mount options look correct. Keep in mind that 'password' is optional, if there isn't one, remove that option.

If it can't find //safe, try it's ip address, like //192.168.0.101/safe

You can't dd a running system, by the way. You'll have to do this from a livecd of some sort.

The following is the content of my /etc/fstab file:

# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
/dev/sda6       /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda7 during installation
UUID=ea0965c8-d66b-4f0e-bb20-ed629eb011fc none            swap    sw              0       0

so , here the only thing i need to backup is /dev/sda6.

so, i'l try to backup /dev/sda6 using:

tar cvpjf backup.tar.bz2 (here how can i say to backup /dev/sda6?)

You're not familiar with it. Don't try it.

You can't tar a device file, only a folder. You put a disk on a folder by mounting it.

mount -o ro /dev/whatever /path/to/folder

You'll need the boot sector too. Without that you lose the bootloader.

Well, OK then I need to mount /dev/sda6
mount -o ro /dev/sda6 /mnt/myDev

I don't understand this. how can i use the boot sector? and what do you mean that if the bootloader might get lost if i don use the boot sector?

This is made much more complicated by it being sda6. That's 2 beyond the limits of the DOS boot sector, which places it in an extended region that's not backed up when you back up the boot sector. So my instructions no longer apply.

That it's sda6 at all suggests there's 4 partitions before it(not 5, sda5 is special) whose contents are at best unknown here.

This is why you need to be familiar with it, to know the implications of what you're doing -- to know what will and won't work and why.

Don't make me regret trying to help you. Don't do it.

You suggest the best option is the best n telling me not to use it i can't, so, what's the point then? m wasting all my comments, bcoz it ended up with nothing!

I gave you several options, but you refused most of them, even though I warned you -- repeatedly -- that this way was the most difficult and troublesome and likely to end in disaster. You wasted your own time.

I tried your command, but it fails:

saman@saman-G41MT-ES2L:~$ sudo mount -t cifs //safe/tabatabaian_s -o username="myuser",password="mypass" /mnt/share
mount: wrong fs type, bad option, bad superblock on //safe/tabatabaian_s,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so

this is the location I can reach via graphics browser:smb://safe/tabatabaian_s/

---------- Post updated at 02:18 AM ---------- Previous update was at 02:13 AM ----------

whatever, that's my own business if it's the most difficult way or whatever, i can choose this option as long as it is mentioned in your post!

The command told you where to find better error messages. Did you run dmesg | tail yet? Did you get any interesting output from it?

I also told you to try the //IPaddress if //servername didn't work, did you try it?

I also told you smbfs://-style things and URL's in general make no sense at all in shell. Actual file paths don't work that way. I wasn't kidding. I use CIFS mounts all the time.